Nathan Butters commited on
Commit
e91d43c
·
1 Parent(s): 89cc75f

Updated to temporary solution based on examples.

Browse files
Files changed (2) hide show
  1. app.py +24 -14
  2. tempDir/notice.md +1 -1
app.py CHANGED
@@ -34,8 +34,10 @@ with st.sidebar:
34
  logger.info(f"Model changed to {model_choice}.")
35
  systemPrompt = st.radio("Designate a control persona:",options=["Model","Tutor"])
36
  st.session_state.systemPrompt = systemPrompt
 
 
37
  st.subheader(f"This experience is currently running on {st.session_state.model}.")
38
- st.warning("The experience is currently nonfunctional as I attempt to figure out how to expose the image URL to the HF inference API via streamlit...")
39
  # Initialize chat history
40
  if "messages" not in st.session_state:
41
  st.session_state.messages = []
@@ -45,18 +47,26 @@ for message in st.session_state.messages:
45
  with st.chat_message(message["role"]):
46
  st.markdown(message["content"])
47
 
 
 
 
 
48
 
49
- enable = st.checkbox("Enable camera")
50
- picture = st.camera_input("Take a picture of your math work", disabled=not enable)
51
-
52
- if picture is not None:
53
- # Save the image to a temporary file
54
- temp_dir = tempfile.mkdtemp()
55
- temp_image_path = os.path.join(temp_dir, "picture.png")
56
- with open(temp_image_path, "wb") as f:
57
- f.write(picture.getbuffer())
58
- extIP = requests.get("https://ipv4.icanhazip.com").text + ":8501"
59
- img_url = f"http://{extIP}{temp_image_path}"
60
- guidedMM(st.session_state.systemPrompt, img_url)
61
  else:
62
- basicChat()
 
 
 
 
 
 
 
 
34
  logger.info(f"Model changed to {model_choice}.")
35
  systemPrompt = st.radio("Designate a control persona:",options=["Model","Tutor"])
36
  st.session_state.systemPrompt = systemPrompt
37
+ liveExperience = st.checkbox("Check for live experience, currently impoeverished.")
38
+
39
  st.subheader(f"This experience is currently running on {st.session_state.model}.")
40
+
41
  # Initialize chat history
42
  if "messages" not in st.session_state:
43
  st.session_state.messages = []
 
47
  with st.chat_message(message["role"]):
48
  st.markdown(message["content"])
49
 
50
+ if liveExperience:
51
+ st.warning("The experience is currently nonfunctional as I attempt to figure out how to expose the image URL to the HF inference API via streamlit...")
52
+ enable = st.checkbox("Enable camera")
53
+ picture = st.camera_input("Take a picture of your math work", disabled=not enable)
54
 
55
+ if picture is not None:
56
+ # Save the image to a temporary file
57
+ temp_dir = tempfile.mkdtemp()
58
+ temp_image_path = os.path.join(temp_dir, "picture.png")
59
+ with open(temp_image_path, "wb") as f:
60
+ f.write(picture.getbuffer())
61
+ extIP = requests.get("https://ipv4.icanhazip.com").text
62
+ img_url = f"https://{extIP}:8501{temp_image_path}"
63
+ guidedMM(st.session_state.systemPrompt, img_url)
 
 
 
64
  else:
65
+ st.info("Please select an example image to understand the basic potential of the app while I try to figure out how to serve images correctly to the completions API.")
66
+ example = st.selectbox("Select an example image", options=["Example 1", "Example 2"])
67
+ if example == "Example 1":
68
+ img_url = "https://huggingface.co/spaces/butterswords/MM_Math_Helper/resolve/main/tempDir/example1.png"
69
+ elif example == "Example 2":
70
+ img_url = "https://huggingface.co/spaces/butterswords/MM_Math_Helper/resolve/main/tempDir/example2.png"
71
+ st.image(img_url)
72
+ guidedMM(st.session_state.systemPrompt, img_url)
tempDir/notice.md CHANGED
@@ -1,3 +1,3 @@
1
  # Notice.
2
 
3
- This directory should remain empty. It's used to house temporary images for processing URLs because of the way the HF API works.
 
1
  # Notice.
2
 
3
+ This directory contains examples. It's a holdover from an attempt to house temporary images for processing URLs because of the way the HF API works (or doesn't) with streamlit images.