Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -197,30 +197,7 @@ with tab1:
|
|
| 197 |
except Exception as e:
|
| 198 |
st.error(f"Error: {str(e)}")
|
| 199 |
|
| 200 |
-
|
| 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 |
-
|
| 235 |
-
|
| 236 |
-
st.
|
| 237 |
-
|
| 238 |
-
|
|
|
|
|
|
|
| 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 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
|
|
|
| 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
|
| 274 |
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
|
| 279 |
-
|
| 280 |
-
|
| 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:
|
| 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']:
|