Sina Media Lab
commited on
Commit
Β·
4b333fb
1
Parent(s):
0f8da64
Updates
Browse files
app.py
CHANGED
@@ -178,54 +178,57 @@ with st.form(key=f'question_form_{st.session_state.current_index}'):
|
|
178 |
|
179 |
# Handle button state and answer submission
|
180 |
if submit_button:
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
st.session_state.
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
st.session_state.
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
|
|
|
|
|
|
|
178 |
|
179 |
# Handle button state and answer submission
|
180 |
if submit_button:
|
181 |
+
if selected_answer is None:
|
182 |
+
st.warning("Please select an option before submitting.")
|
183 |
+
else:
|
184 |
+
st.session_state.submit_click_count += 1
|
185 |
+
|
186 |
+
if st.session_state.submit_click_count == 1:
|
187 |
+
# First click: show solution
|
188 |
+
if not current_question['answered']:
|
189 |
+
if selected_answer is not None:
|
190 |
+
# Process the answer
|
191 |
+
current_question['selected'] = selected_answer
|
192 |
+
current_question['answered'] = True
|
193 |
+
st.session_state.module_question_count[selected_module] += 1
|
194 |
+
|
195 |
+
if selected_answer == current_question['correct_answer']:
|
196 |
+
st.session_state.correct_count += 1
|
197 |
+
st.session_state.module_correct_count[selected_module] += 1
|
198 |
+
|
199 |
+
# Set answered to true to disable options
|
200 |
+
st.session_state.questions[st.session_state.current_index]['answered'] = True
|
201 |
+
st.session_state.selected_answer = selected_answer
|
202 |
+
|
203 |
+
# Show correct/incorrect feedback after submission
|
204 |
+
for option in current_question['options']:
|
205 |
+
if option == current_question['correct_answer']:
|
206 |
+
st.markdown(f"<span style='color:green;'>{option} β
</span>", unsafe_allow_html=True)
|
207 |
+
elif option == current_question['selected']:
|
208 |
+
st.markdown(f"<span style='color:red;'>{option} β</span>", unsafe_allow_html=True)
|
209 |
+
else:
|
210 |
+
st.markdown(f"{option}")
|
211 |
+
|
212 |
+
# Show explanation and step-by-step solution with improved visuals
|
213 |
+
st.write(f"**Explanation:** {current_question['explanation']}")
|
214 |
+
st.markdown("""
|
215 |
+
<div style='border: 2px solid #4CAF50; padding: 10px; margin-top: 20px; background-color: #f9f9f9;'>
|
216 |
+
<h4 style='color: #4CAF50;'>Step-by-Step Solution:</h4>
|
217 |
+
<ol>
|
218 |
+
""", unsafe_allow_html=True)
|
219 |
+
|
220 |
+
for step in current_question['step_by_step_solution']:
|
221 |
+
st.markdown(f"<li style='margin-bottom: 10px;'>{step}</li>", unsafe_allow_html=True)
|
222 |
+
|
223 |
+
st.markdown("</ol></div>", unsafe_allow_html=True)
|
224 |
+
|
225 |
+
elif st.session_state.submit_click_count == 2:
|
226 |
+
# Second click: generate a new question
|
227 |
+
new_question = generate_new_question(selected_module, modules[selected_module])
|
228 |
+
st.session_state.questions.append(new_question)
|
229 |
+
st.session_state.current_index = len(st.session_state.questions) - 1
|
230 |
+
st.session_state.answered = False
|
231 |
+
st.session_state.submit_click_count = 0 # Reset the click count
|
232 |
+
st.session_state.selected_answer = None # Reset the selected answer
|
233 |
+
# Force a re-render by modifying a state variable
|
234 |
+
st.session_state['last_updated'] = str(uuid.uuid4())
|