louiecerv commited on
Commit
b5740aa
·
1 Parent(s): b385ac2
Files changed (1) hide show
  1. app.py +36 -15
app.py CHANGED
@@ -91,6 +91,27 @@ def multimodal_prompt(pdf_path, text_prompt, file_type="PDF"):
91
  except Exception as e:
92
  return f"An error occurred: {e}"
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  # --- Main Page ---
95
  st.title("📚❓Problem Solving Tutor")
96
  about = """
@@ -108,21 +129,21 @@ with st.spinner("Loading the problem..."):
108
  # --- Display the image ---
109
  st.image(filepath, caption="Problem Image", use_container_width=True)
110
 
111
- # Remove the ```json and ``` and extra spaces.
112
- try:
113
- json_string = response.replace('```json', '').replace('```', '').strip()
114
-
115
- # Parse the JSON string into a Python list.
116
- problems_list = json.loads(json_string)
117
-
118
- # Iterate over the list and print each item using st.write().
119
- for item in problems_list:
120
- st.write(item)
121
-
122
- except json.JSONDecodeError:
123
- st.write("Error: Invalid JSON format in the response.")
124
- except Exception as e:
125
- st.write(f"An unexpected error occurred: {e}")
126
 
127
 
128
  st.markdown("Visit our Hugging Face Space!")
 
91
  except Exception as e:
92
  return f"An error occurred: {e}"
93
 
94
+ def get_equation(response):
95
+ # Remove the ```json and ``` and extra spaces.
96
+ try:
97
+ json_string = response.replace('```json', '').replace('```', '').strip()
98
+
99
+ # Parse the JSON string into a Python list.
100
+ problems_list = json.loads(json_string)
101
+
102
+ # return the first item found
103
+ return problems_list[0]
104
+
105
+ except json.JSONDecodeError:
106
+ st.error("Invalid JSON format in the response.")
107
+ return None
108
+ except Exception as e:
109
+ st.error(f"An unexpected error occurred: {e}")
110
+ return None
111
+
112
+ if "problem_step" not in st.session_state:
113
+ st.session_state.problem_step = 0
114
+
115
  # --- Main Page ---
116
  st.title("📚❓Problem Solving Tutor")
117
  about = """
 
129
  # --- Display the image ---
130
  st.image(filepath, caption="Problem Image", use_container_width=True)
131
 
132
+ equation = get_equation(response)
133
+ st.write(f"**Equation:** {equation}")
134
+
135
+ problem_step = st.session_state.problem_step
136
+ if problem_step == 0:
137
+ #Show instructions to submit the answer
138
+ st.write("Please write down your answer in a piece of paper. Take a picture of the paper and submit it in the next step.")
139
+ st.write("Click the button below to proceed.")
140
+ image = st.camera_input("Take a picture of your answer.")
141
+
142
+ if image is not None:
143
+ # process the answer
144
+ st.write("Processing your answer...")
145
+ else:
146
+ st.write("Please take a picture of your answer.")
147
 
148
 
149
  st.markdown("Visit our Hugging Face Space!")