Sina Media Lab
commited on
Commit
·
8cfa676
1
Parent(s):
a55be0a
Updates
Browse files
app.py
CHANGED
@@ -123,14 +123,6 @@ def generate_new_question(module_name, module):
|
|
123 |
st.warning(f"Question in module '{module_name}' does not have 4 options. Found {len(question_data['options'])}.")
|
124 |
return question_data
|
125 |
|
126 |
-
def navigate_question(direction):
|
127 |
-
if direction == "prev" and st.session_state.current_index > 0:
|
128 |
-
st.session_state.current_index -= 1
|
129 |
-
st.session_state.answered = True
|
130 |
-
elif direction == "next" and st.session_state.current_index < len(st.session_state.questions) - 1:
|
131 |
-
st.session_state.current_index += 1
|
132 |
-
st.session_state.answered = True
|
133 |
-
|
134 |
# Load all modules dynamically
|
135 |
modules = load_modules()
|
136 |
|
@@ -164,10 +156,10 @@ st.write(modules[selected_module]["description"])
|
|
164 |
col1, col2, col3 = st.columns([1, 1, 2])
|
165 |
with col1:
|
166 |
if st.button("⬅️ Prev", disabled=st.session_state.current_index == 0):
|
167 |
-
|
168 |
with col2:
|
169 |
if st.button("➡️ Next", disabled=st.session_state.current_index >= len(st.session_state.questions) - 1):
|
170 |
-
|
171 |
with col3:
|
172 |
if len(st.session_state.questions) > 0:
|
173 |
pdf = generate_pdf_report()
|
@@ -223,37 +215,15 @@ def display_question_with_styles(question_data):
|
|
223 |
</div>
|
224 |
""", unsafe_allow_html=True)
|
225 |
|
226 |
-
|
|
|
227 |
for option in question_data['options']:
|
228 |
-
option_class = ''
|
229 |
-
if option == question_data['correct_answer']:
|
230 |
-
option_class = 'correct'
|
231 |
-
elif option == question_data['selected']:
|
232 |
-
option_class = 'incorrect'
|
233 |
-
|
234 |
st.markdown(f"""
|
235 |
-
<div class="option
|
236 |
{option}
|
237 |
</div>
|
238 |
""", unsafe_allow_html=True)
|
239 |
|
240 |
-
st.markdown(f"""
|
241 |
-
<div class="explanation-box">
|
242 |
-
<strong>Explanation:</strong> {question_data['explanation']}
|
243 |
-
</div>
|
244 |
-
""", unsafe_allow_html=True)
|
245 |
-
|
246 |
-
st.markdown(f"""
|
247 |
-
<div class="step-box">
|
248 |
-
<strong>Step-by-Step Solution:</strong>
|
249 |
-
<ul>
|
250 |
-
""", unsafe_allow_html=True)
|
251 |
-
|
252 |
-
for step in question_data['step_by_step_solution']:
|
253 |
-
st.markdown(f"<li>{step}</li>", unsafe_allow_html=True)
|
254 |
-
|
255 |
-
st.markdown("</ul></div>", unsafe_allow_html=True)
|
256 |
-
|
257 |
# Display the current question with styles
|
258 |
display_question_with_styles(current_question)
|
259 |
|
@@ -270,32 +240,49 @@ with st.form(key=f'question_form_{st.session_state.current_index}'):
|
|
270 |
key=f"question_{st.session_state.current_index}_options"
|
271 |
)
|
272 |
|
273 |
-
submit_button = st.form_submit_button(label="Submit
|
|
|
274 |
|
275 |
# Handle button state and answer submission
|
276 |
-
if submit_button:
|
277 |
-
if not
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
st.
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
st.warning(f"Question in module '{module_name}' does not have 4 options. Found {len(question_data['options'])}.")
|
124 |
return question_data
|
125 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
# Load all modules dynamically
|
127 |
modules = load_modules()
|
128 |
|
|
|
156 |
col1, col2, col3 = st.columns([1, 1, 2])
|
157 |
with col1:
|
158 |
if st.button("⬅️ Prev", disabled=st.session_state.current_index == 0):
|
159 |
+
st.session_state.current_index -= 1
|
160 |
with col2:
|
161 |
if st.button("➡️ Next", disabled=st.session_state.current_index >= len(st.session_state.questions) - 1):
|
162 |
+
st.session_state.current_index += 1
|
163 |
with col3:
|
164 |
if len(st.session_state.questions) > 0:
|
165 |
pdf = generate_pdf_report()
|
|
|
215 |
</div>
|
216 |
""", unsafe_allow_html=True)
|
217 |
|
218 |
+
# Display options without correct/incorrect marking initially
|
219 |
+
if not question_data.get('answered', False):
|
220 |
for option in question_data['options']:
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
st.markdown(f"""
|
222 |
+
<div class="option">
|
223 |
{option}
|
224 |
</div>
|
225 |
""", unsafe_allow_html=True)
|
226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
# Display the current question with styles
|
228 |
display_question_with_styles(current_question)
|
229 |
|
|
|
240 |
key=f"question_{st.session_state.current_index}_options"
|
241 |
)
|
242 |
|
243 |
+
submit_button = st.form_submit_button(label="Submit")
|
244 |
+
generate_button = st.form_submit_button(label="Generate")
|
245 |
|
246 |
# Handle button state and answer submission
|
247 |
+
if submit_button and not current_question['answered']:
|
248 |
+
if selected_answer is not None:
|
249 |
+
# Process the answer
|
250 |
+
current_question['selected'] = selected_answer
|
251 |
+
current_question['answered'] = True
|
252 |
+
st.session_state.module_question_count[selected_module] += 1
|
253 |
+
|
254 |
+
if selected_answer == current_question['correct_answer']:
|
255 |
+
st.session_state.correct_count += 1
|
256 |
+
st.session_state.module_correct_count[selected_module] += 1
|
257 |
+
|
258 |
+
# Set answered to true to disable options
|
259 |
+
st.session_state.questions[st.session_state.current_index]['answered'] = True
|
260 |
+
st.session_state.selected_answer = selected_answer
|
261 |
+
|
262 |
+
# Show correct/incorrect feedback after submission
|
263 |
+
display_question_with_styles(current_question)
|
264 |
+
|
265 |
+
# Display the explanation and step-by-step solution only after the question is answered
|
266 |
+
st.markdown(f"""
|
267 |
+
<div class="explanation-box">
|
268 |
+
<strong>Explanation:</strong> {current_question['explanation']}
|
269 |
+
</div>
|
270 |
+
""", unsafe_allow_html=True)
|
271 |
+
|
272 |
+
st.markdown(f"""
|
273 |
+
<div class="step-box">
|
274 |
+
<strong>Step-by-Step Solution:</strong>
|
275 |
+
<ul>
|
276 |
+
""", unsafe_allow_html=True)
|
277 |
+
|
278 |
+
for step in current_question['step_by_step_solution']:
|
279 |
+
st.markdown(f"<li>{step}</li>", unsafe_allow_html=True)
|
280 |
+
|
281 |
+
st.markdown("</ul></div>", unsafe_allow_html=True)
|
282 |
+
|
283 |
+
if generate_button:
|
284 |
+
new_question = generate_new_question(selected_module, modules[selected_module])
|
285 |
+
st.session_state.questions.append(new_question)
|
286 |
+
st.session_state.current_index = len(st.session_state.questions) - 1
|
287 |
+
st.session_state.answered = False
|
288 |
+
st.experimental_rerun() # Rerun to load the new question
|