Sina Media Lab
commited on
Commit
Β·
516f536
1
Parent(s):
ed05a56
Updates
Browse files
app.py
CHANGED
@@ -27,6 +27,8 @@ 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
|
@@ -136,6 +138,7 @@ if selected_module != st.session_state.current_module:
|
|
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]
|
@@ -165,76 +168,77 @@ with col3:
|
|
165 |
|
166 |
st.write(current_question["question"])
|
167 |
|
168 |
-
#
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
if
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
st.session_state.
|
203 |
-
st.session_state.
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
|
|
|
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 |
+
if 'show_next_button' not in st.session_state:
|
31 |
+
st.session_state.show_next_button = False
|
32 |
|
33 |
def reset_pdf_cache():
|
34 |
st.session_state.pdf_data = None
|
|
|
138 |
st.session_state.selected_answer = None
|
139 |
st.session_state.answered = False
|
140 |
st.session_state.submit_click_count = 0 # Reset the submit click count
|
141 |
+
st.session_state.show_next_button = False # Reset the next button visibility
|
142 |
|
143 |
# Load the current module's question
|
144 |
current_question = st.session_state.questions[st.session_state.current_index]
|
|
|
168 |
|
169 |
st.write(current_question["question"])
|
170 |
|
171 |
+
# Show Submit/Next button or Next button depending on the state
|
172 |
+
if not st.session_state.show_next_button:
|
173 |
+
# Create the form for the question
|
174 |
+
with st.form(key=f'question_form_{st.session_state.current_index}'):
|
175 |
+
selected_answer = st.radio(
|
176 |
+
"Choose an answer:",
|
177 |
+
options=current_question['options'],
|
178 |
+
index=current_question['options'].index(current_question['selected']) if current_question['answered'] else None,
|
179 |
+
key=f"question_{st.session_state.current_index}_options"
|
180 |
+
)
|
181 |
+
|
182 |
+
submit_button = st.form_submit_button(label="Submit/Next")
|
183 |
+
|
184 |
+
# Handle button state and answer submission
|
185 |
+
if submit_button:
|
186 |
+
if selected_answer is None:
|
187 |
+
st.warning("Please select an option before submitting.")
|
188 |
+
else:
|
189 |
+
st.session_state.submit_click_count += 1
|
190 |
+
|
191 |
+
if st.session_state.submit_click_count == 1:
|
192 |
+
# First click: show solution and replace Submit/Next with Next
|
193 |
+
if not current_question['answered']:
|
194 |
+
if selected_answer is not None:
|
195 |
+
# Process the answer
|
196 |
+
current_question['selected'] = selected_answer
|
197 |
+
current_question['answered'] = True
|
198 |
+
st.session_state.module_question_count[selected_module] += 1
|
199 |
+
|
200 |
+
if selected_answer == current_question['correct_answer']:
|
201 |
+
st.session_state.correct_count += 1
|
202 |
+
st.session_state.module_correct_count[selected_module] += 1
|
203 |
+
|
204 |
+
# Set answered to true to disable options
|
205 |
+
st.session_state.questions[st.session_state.current_index]['answered'] = True
|
206 |
+
st.session_state.selected_answer = selected_answer
|
207 |
+
|
208 |
+
# Show correct/incorrect feedback after submission
|
209 |
+
for option in current_question['options']:
|
210 |
+
if option == current_question['correct_answer']:
|
211 |
+
st.markdown(f"<span style='color:green;'>{option} β
</span>", unsafe_allow_html=True)
|
212 |
+
elif option == current_question['selected']:
|
213 |
+
st.markdown(f"<span style='color:red;'>{option} β</span>", unsafe_allow_html=True)
|
214 |
+
else:
|
215 |
+
st.markdown(f"{option}")
|
216 |
+
|
217 |
+
# Show explanation and step-by-step solution with improved visuals
|
218 |
+
st.write(f"**Explanation:** {current_question['explanation']}")
|
219 |
+
st.markdown("""
|
220 |
+
<div style='border: 2px solid #4CAF50; padding: 10px; margin-top: 20px; background-color: #f9f9f9;'>
|
221 |
+
<h4 style='color: #4CAF50;'>Step-by-Step Solution:</h4>
|
222 |
+
<ol>
|
223 |
+
""", unsafe_allow_html=True)
|
224 |
+
|
225 |
+
for step in current_question['step_by_step_solution']:
|
226 |
+
st.markdown(f"<li style='margin-bottom: 10px;'>{step}</li>", unsafe_allow_html=True)
|
227 |
+
|
228 |
+
st.markdown("</ol></div>", unsafe_allow_html=True)
|
229 |
+
|
230 |
+
# Replace Submit/Next with Next
|
231 |
+
st.session_state.show_next_button = True
|
232 |
+
else:
|
233 |
+
# Show the Next button
|
234 |
+
if st.button("Next"):
|
235 |
+
# Generate a new question
|
236 |
+
new_question = generate_new_question(selected_module, modules[selected_module])
|
237 |
+
st.session_state.questions.append(new_question)
|
238 |
+
st.session_state.current_index = len(st.session_state.questions) - 1
|
239 |
+
st.session_state.answered = False
|
240 |
+
st.session_state.submit_click_count = 0 # Reset the click count
|
241 |
+
st.session_state.selected_answer = None # Reset the selected answer
|
242 |
+
st.session_state.show_next_button = False # Hide the Next button
|
243 |
+
# Force a re-render by modifying a state variable
|
244 |
+
st.session_state['last_updated'] = str(uuid.uuid4())
|