Sina Media Lab
commited on
Commit
Β·
e722c2a
1
Parent(s):
5f170a6
Updates
Browse files
app.py
CHANGED
@@ -25,6 +25,8 @@ if 'selected_answer' not in st.session_state:
|
|
25 |
st.session_state.selected_answer = None
|
26 |
if 'answered' not in st.session_state:
|
27 |
st.session_state.answered = False
|
|
|
|
|
28 |
|
29 |
def reset_pdf_cache():
|
30 |
st.session_state.pdf_data = None
|
@@ -133,6 +135,7 @@ if selected_module != st.session_state.current_module:
|
|
133 |
st.session_state.module_correct_count[selected_module] = 0
|
134 |
st.session_state.selected_answer = None
|
135 |
st.session_state.answered = False
|
|
|
136 |
|
137 |
# Load the current module's question
|
138 |
current_question = st.session_state.questions[st.session_state.current_index]
|
@@ -175,47 +178,52 @@ with st.form(key=f'question_form_{st.session_state.current_index}'):
|
|
175 |
|
176 |
# Handle button state and answer submission
|
177 |
if submit_button:
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
st.session_state.
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
new_question = generate_new_question(selected_module, modules[selected_module])
|
196 |
st.session_state.questions.append(new_question)
|
197 |
st.session_state.current_index = len(st.session_state.questions) - 1
|
198 |
st.session_state.answered = False
|
199 |
-
|
200 |
-
#
|
201 |
-
if current_question.get('answered', False):
|
202 |
-
for option in current_question['options']:
|
203 |
-
if option == current_question['correct_answer']:
|
204 |
-
st.markdown(f"<span style='color:green;'>{option} β
</span>", unsafe_allow_html=True)
|
205 |
-
elif option == current_question['selected']:
|
206 |
-
st.markdown(f"<span style='color:red;'>{option} β</span>", unsafe_allow_html=True)
|
207 |
-
else:
|
208 |
-
st.markdown(f"{option}")
|
209 |
-
|
210 |
-
# Show explanation and step-by-step solution with improved visuals
|
211 |
-
st.write(f"**Explanation:** {current_question['explanation']}")
|
212 |
-
st.markdown("""
|
213 |
-
<div style='border: 2px solid #4CAF50; padding: 10px; margin-top: 20px; background-color: #f9f9f9;'>
|
214 |
-
<h4 style='color: #4CAF50;'>Step-by-Step Solution:</h4>
|
215 |
-
<ol>
|
216 |
-
""", unsafe_allow_html=True)
|
217 |
-
|
218 |
-
for step in current_question['step_by_step_solution']:
|
219 |
-
st.markdown(f"<li style='margin-bottom: 10px;'>{step}</li>", unsafe_allow_html=True)
|
220 |
-
|
221 |
-
st.markdown("</ol></div>", unsafe_allow_html=True)
|
|
|
25 |
st.session_state.selected_answer = None
|
26 |
if 'answered' not in st.session_state:
|
27 |
st.session_state.answered = False
|
28 |
+
if 'submit_click_count' not in st.session_state:
|
29 |
+
st.session_state.submit_click_count = 0
|
30 |
|
31 |
def reset_pdf_cache():
|
32 |
st.session_state.pdf_data = None
|
|
|
135 |
st.session_state.module_correct_count[selected_module] = 0
|
136 |
st.session_state.selected_answer = None
|
137 |
st.session_state.answered = False
|
138 |
+
st.session_state.submit_click_count = 0 # Reset the submit click count
|
139 |
|
140 |
# Load the current module's question
|
141 |
current_question = st.session_state.questions[st.session_state.current_index]
|
|
|
178 |
|
179 |
# Handle button state and answer submission
|
180 |
if submit_button:
|
181 |
+
st.session_state.submit_click_count += 1
|
182 |
+
|
183 |
+
if st.session_state.submit_click_count == 1:
|
184 |
+
# First click: show solution
|
185 |
+
if not current_question['answered']:
|
186 |
+
if selected_answer is not None:
|
187 |
+
# Process the answer
|
188 |
+
current_question['selected'] = selected_answer
|
189 |
+
current_question['answered'] = True
|
190 |
+
st.session_state.module_question_count[selected_module] += 1
|
191 |
+
|
192 |
+
if selected_answer == current_question['correct_answer']:
|
193 |
+
st.session_state.correct_count += 1
|
194 |
+
st.session_state.module_correct_count[selected_module] += 1
|
195 |
+
|
196 |
+
# Set answered to true to disable options
|
197 |
+
st.session_state.questions[st.session_state.current_index]['answered'] = True
|
198 |
+
st.session_state.selected_answer = selected_answer
|
199 |
+
|
200 |
+
# Show correct/incorrect feedback after submission
|
201 |
+
for option in current_question['options']:
|
202 |
+
if option == current_question['correct_answer']:
|
203 |
+
st.markdown(f"<span style='color:green;'>{option} β
</span>", unsafe_allow_html=True)
|
204 |
+
elif option == current_question['selected']:
|
205 |
+
st.markdown(f"<span style='color:red;'>{option} β</span>", unsafe_allow_html=True)
|
206 |
+
else:
|
207 |
+
st.markdown(f"{option}")
|
208 |
+
|
209 |
+
# Show explanation and step-by-step solution with improved visuals
|
210 |
+
st.write(f"**Explanation:** {current_question['explanation']}")
|
211 |
+
st.markdown("""
|
212 |
+
<div style='border: 2px solid #4CAF50; padding: 10px; margin-top: 20px; background-color: #f9f9f9;'>
|
213 |
+
<h4 style='color: #4CAF50;'>Step-by-Step Solution:</h4>
|
214 |
+
<ol>
|
215 |
+
""", unsafe_allow_html=True)
|
216 |
+
|
217 |
+
for step in current_question['step_by_step_solution']:
|
218 |
+
st.markdown(f"<li style='margin-bottom: 10px;'>{step}</li>", unsafe_allow_html=True)
|
219 |
+
|
220 |
+
st.markdown("</ol></div>", unsafe_allow_html=True)
|
221 |
+
|
222 |
+
elif st.session_state.submit_click_count == 2:
|
223 |
+
# Second click: generate a new question
|
224 |
new_question = generate_new_question(selected_module, modules[selected_module])
|
225 |
st.session_state.questions.append(new_question)
|
226 |
st.session_state.current_index = len(st.session_state.questions) - 1
|
227 |
st.session_state.answered = False
|
228 |
+
st.session_state.submit_click_count = 0 # Reset the click count
|
229 |
+
st.experimental_rerun() # Rerun to load the new question
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|