Sina Media Lab commited on
Commit
e722c2a
Β·
1 Parent(s): 5f170a6
Files changed (1) hide show
  1. app.py +48 -40
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
- if not current_question['answered']:
179
- if selected_answer is not None:
180
- # Process the answer
181
- current_question['selected'] = selected_answer
182
- current_question['answered'] = True
183
- st.session_state.module_question_count[selected_module] += 1
184
-
185
- if selected_answer == current_question['correct_answer']:
186
- st.session_state.correct_count += 1
187
- st.session_state.module_correct_count[selected_module] += 1
188
-
189
- # Set answered to true to disable options
190
- st.session_state.questions[st.session_state.current_index]['answered'] = True
191
- st.session_state.selected_answer = selected_answer
192
-
193
- else:
194
- # If already answered, move to the next question
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- # Show correct/incorrect feedback after submission
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