cryogenic22 commited on
Commit
3690501
Β·
verified Β·
1 Parent(s): 4629838

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -51
app.py CHANGED
@@ -197,30 +197,7 @@ with tab1:
197
  except Exception as e:
198
  st.error(f"Error: {str(e)}")
199
 
200
- # Course Content Display
201
- if st.session_state.learning_path:
202
- learning_path = st.session_state.learning_path
203
-
204
- # Module Navigation Bar
205
- st.markdown('<div class="module-navigator">', unsafe_allow_html=True)
206
- col1, col2 = st.columns([3, 1])
207
- with col1:
208
- module_titles = [f"Module {i+1}: {module.title}" for i, module in enumerate(learning_path.modules)]
209
- selected_module = st.selectbox(
210
- "Navigate to Module",
211
- module_titles,
212
- index=st.session_state.current_module
213
- )
214
- st.session_state.current_module = module_titles.index(selected_module)
215
-
216
- with col2:
217
- if len(learning_path.modules) > 0:
218
- progress = (st.session_state.current_module / len(learning_path.modules)) * 100
219
- st.progress(progress/100)
220
- st.write(f"Progress: {progress:.0f}%")
221
- st.markdown('</div>', unsafe_allow_html=True)
222
-
223
- if not st.session_state.quiz_mode:
224
  # Module Content Display
225
  current_module = learning_path.modules[st.session_state.current_module]
226
 
@@ -230,17 +207,25 @@ with tab1:
230
  st.markdown(current_module.content)
231
 
232
  # Quiz Button
233
- if current_module.quiz_questions:
234
- if st.button("πŸ“ Take Module Quiz", key=f"start_quiz_{st.session_state.current_module}"):
235
- st.session_state.quiz_mode = True
236
- st.session_state.current_question = 0
237
- st.session_state.quiz_score = 0
238
- st.rerun()
 
 
239
  st.markdown('</div>', unsafe_allow_html=True)
240
 
241
  else:
242
  # Quiz Mode
243
  current_module = learning_path.modules[st.session_state.current_module]
 
 
 
 
 
 
244
  questions = current_module.quiz_questions
245
 
246
  st.markdown('<div class="quiz-card">', unsafe_allow_html=True)
@@ -258,35 +243,41 @@ with tab1:
258
  st.markdown(f"**{question['question']}**")
259
 
260
  # Display options
261
- answer = st.radio("Select your answer:",
262
- question['options'],
263
- key=f"quiz_{st.session_state.current_module}_{st.session_state.current_question}")
264
-
265
- col1, col2 = st.columns([1, 3])
266
- with col1:
267
- if st.button("Submit Answer"):
268
- if answer == question['correct_answer']:
 
269
  st.success("βœ… Correct!")
270
  st.session_state.quiz_score += 1
271
  else:
272
  st.error("❌ Incorrect")
273
- st.markdown(f"The correct answer is: **{question['correct_answer']}**")
274
 
275
- st.markdown(f"**Explanation:** {question['explanation']}")
276
- st.session_state.current_question += 1
277
- st.rerun()
 
 
 
 
278
 
279
- with col2:
280
- st.write(f"Current Score: {st.session_state.quiz_score}/{total_questions}")
281
 
282
  else:
283
  # Quiz Complete
284
  score_percentage = (st.session_state.quiz_score / len(questions)) * 100
285
  st.markdown(f"### πŸŽ‰ Quiz Complete!")
286
- st.markdown(f"Final Score: **{score_percentage:.1f}%**")
287
 
288
  # Award badge based on score
289
  if score_percentage >= 90:
 
290
  st.markdown("### πŸ† Expert Achievement Unlocked!")
291
  elif score_percentage >= 75:
292
  st.markdown("### 🌟 Advanced Learner Badge!")
@@ -295,23 +286,20 @@ with tab1:
295
 
296
  col1, col2 = st.columns(2)
297
  with col1:
298
- if st.button("Review Module"):
299
  st.session_state.quiz_mode = False
300
  mark_module_complete(st.session_state.current_module)
301
  st.rerun()
302
  with col2:
303
  if st.session_state.current_module < len(learning_path.modules) - 1:
304
- if st.button("Next Module"):
305
  st.session_state.current_module += 1
306
  st.session_state.quiz_mode = False
307
  mark_module_complete(st.session_state.current_module - 1)
308
  st.rerun()
309
 
310
  st.markdown('</div>', unsafe_allow_html=True)
311
-
312
- with tab2:
313
- st.markdown("### πŸ“š My Learning Journey")
314
-
315
  # In Progress Courses
316
  st.markdown("#### πŸš€ In Progress")
317
  if st.session_state.courses['in_progress']:
 
197
  except Exception as e:
198
  st.error(f"Error: {str(e)}")
199
 
200
+ if not st.session_state.quiz_mode:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
  # Module Content Display
202
  current_module = learning_path.modules[st.session_state.current_module]
203
 
 
207
  st.markdown(current_module.content)
208
 
209
  # Quiz Button
210
+ if hasattr(current_module, 'quiz_questions') and current_module.quiz_questions:
211
+ quiz_col1, quiz_col2, quiz_col3 = st.columns([1,2,1])
212
+ with quiz_col2:
213
+ if st.button("πŸ“ Start Module Quiz", type="primary"):
214
+ st.session_state.quiz_mode = True
215
+ st.session_state.current_question = 0
216
+ st.session_state.quiz_score = 0
217
+ st.rerun()
218
  st.markdown('</div>', unsafe_allow_html=True)
219
 
220
  else:
221
  # Quiz Mode
222
  current_module = learning_path.modules[st.session_state.current_module]
223
+
224
+ if not hasattr(current_module, 'quiz_questions') or not current_module.quiz_questions:
225
+ st.warning("No quiz available for this module.")
226
+ st.session_state.quiz_mode = False
227
+ st.rerun()
228
+
229
  questions = current_module.quiz_questions
230
 
231
  st.markdown('<div class="quiz-card">', unsafe_allow_html=True)
 
243
  st.markdown(f"**{question['question']}**")
244
 
245
  # Display options
246
+ if 'options' in question and question['options']:
247
+ answer = st.radio(
248
+ "Select your answer:",
249
+ question['options'],
250
+ key=f"quiz_{st.session_state.current_module}_{st.session_state.current_question}"
251
+ )
252
+
253
+ if st.button("Submit Answer", type="primary"):
254
+ if answer == question.get('correct_answer'):
255
  st.success("βœ… Correct!")
256
  st.session_state.quiz_score += 1
257
  else:
258
  st.error("❌ Incorrect")
259
+ st.markdown(f"The correct answer is: **{question.get('correct_answer')}**")
260
 
261
+ if 'explanation' in question:
262
+ st.info(f"**Explanation:** {question['explanation']}")
263
+
264
+ # Add continue button after showing result
265
+ if st.button("Continue to Next Question ➑️"):
266
+ st.session_state.current_question += 1
267
+ st.rerun()
268
 
269
+ # Show current score
270
+ st.markdown(f"**Current Score:** {st.session_state.quiz_score}/{total_questions}")
271
 
272
  else:
273
  # Quiz Complete
274
  score_percentage = (st.session_state.quiz_score / len(questions)) * 100
275
  st.markdown(f"### πŸŽ‰ Quiz Complete!")
276
+ st.markdown(f"### Final Score: {score_percentage:.1f}%")
277
 
278
  # Award badge based on score
279
  if score_percentage >= 90:
280
+ st.balloons()
281
  st.markdown("### πŸ† Expert Achievement Unlocked!")
282
  elif score_percentage >= 75:
283
  st.markdown("### 🌟 Advanced Learner Badge!")
 
286
 
287
  col1, col2 = st.columns(2)
288
  with col1:
289
+ if st.button("πŸ“š Review Module", type="secondary"):
290
  st.session_state.quiz_mode = False
291
  mark_module_complete(st.session_state.current_module)
292
  st.rerun()
293
  with col2:
294
  if st.session_state.current_module < len(learning_path.modules) - 1:
295
+ if st.button("Next Module ➑️", type="primary"):
296
  st.session_state.current_module += 1
297
  st.session_state.quiz_mode = False
298
  mark_module_complete(st.session_state.current_module - 1)
299
  st.rerun()
300
 
301
  st.markdown('</div>', unsafe_allow_html=True)
302
+
 
 
 
303
  # In Progress Courses
304
  st.markdown("#### πŸš€ In Progress")
305
  if st.session_state.courses['in_progress']: