Sina Media Lab commited on
Commit
4b333fb
Β·
1 Parent(s): 0f8da64
Files changed (1) hide show
  1. app.py +54 -51
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
- 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.session_state.selected_answer = None # Reset the selected answer
230
- # Force a re-render by modifying a state variable
231
- st.session_state['last_updated'] = str(uuid.uuid4())
 
 
 
 
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())