Spaces:
Sleeping
Sleeping
save
Browse files
app.py
CHANGED
@@ -5,6 +5,7 @@ import json
|
|
5 |
from PIL import Image
|
6 |
import re
|
7 |
import json
|
|
|
8 |
|
9 |
# Define constants
|
10 |
TEXT_PROMPT = """Use the provided document. Read the list of quadratic equations.
|
@@ -137,11 +138,37 @@ 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 |
-
|
141 |
|
142 |
-
if
|
143 |
# process the answer
|
144 |
-
st.write("Processing your answer...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
else:
|
146 |
st.write("Please take a picture of your answer.")
|
147 |
|
|
|
5 |
from PIL import Image
|
6 |
import re
|
7 |
import json
|
8 |
+
import tempfile
|
9 |
|
10 |
# Define constants
|
11 |
TEXT_PROMPT = """Use the provided document. Read the list of quadratic equations.
|
|
|
138 |
#Show instructions to submit the answer
|
139 |
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.")
|
140 |
st.write("Click the button below to proceed.")
|
141 |
+
img_file_buffer = st.camera_input("Take a picture of your answer.")
|
142 |
|
143 |
+
if img_file_buffer is not None:
|
144 |
# process the answer
|
145 |
+
st.write("Processing your answer...")
|
146 |
+
|
147 |
+
# Save the image to a temporary file
|
148 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
|
149 |
+
temp_file.write(img_file_buffer.read())
|
150 |
+
image_path = temp_file.name
|
151 |
+
st.write("Image saved to:", image_path)
|
152 |
+
|
153 |
+
# create the text prompt
|
154 |
+
text_prompt = "Use the provided image. The image shoqs, a student's answer to the problem. Evaluate the answer and provide a correct solution. Provide feedback how can the student improve their answer."
|
155 |
+
|
156 |
+
if st.button("Ask Tutor for Feedback"):
|
157 |
+
if text_prompt:
|
158 |
+
with st.spinner("AI is thinking..."):
|
159 |
+
response = multimodal_prompt(image_path, text_prompt, file_type="image")
|
160 |
+
st.markdown(response)
|
161 |
+
|
162 |
+
if st.button("Next"):
|
163 |
+
# Evaluate the response
|
164 |
+
if "Correct" in response:
|
165 |
+
st.write("Correct! 🎉")
|
166 |
+
st.session_state.problem_step = 1
|
167 |
+
else:
|
168 |
+
st.write("Incorrect. 😞")
|
169 |
+
st.session_state.problem_step = 0
|
170 |
+
|
171 |
+
|
172 |
else:
|
173 |
st.write("Please take a picture of your answer.")
|
174 |
|