Spaces:
Running
Running
Update modules/helpers_ui.py
Browse files- modules/helpers_ui.py +20 -21
modules/helpers_ui.py
CHANGED
@@ -36,27 +36,26 @@ def display_slide(index, module_name, slides):
|
|
36 |
st.audio(audio_bytes, format="audio/wav", autoplay=True)
|
37 |
|
38 |
# Quiz toggle
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
st.error(f"❌ Nope—correct answer is **{quiz['answer']}**.")
|
60 |
|
61 |
def slide_controls(module_name, slides):
|
62 |
# Get module-specific slide index
|
|
|
36 |
st.audio(audio_bytes, format="audio/wav", autoplay=True)
|
37 |
|
38 |
# Quiz toggle
|
39 |
+
# Only show quiz if not last slide
|
40 |
+
if index < len(slides) - 1:
|
41 |
+
quiz = md["slide_quizzes"].get(index, {"question": "Quiz not available.", "choices": [], "answer": ""})
|
42 |
+
quiz_visible_key = f"quiz_visible_{module_name}_{index}"
|
43 |
+
if quiz_visible_key not in st.session_state:
|
44 |
+
st.session_state[quiz_visible_key] = False
|
45 |
+
if st.button("📝 Take Slide Quiz", key=f"quiz_btn_{module_name}_{index}"):
|
46 |
+
st.session_state[quiz_visible_key] = not st.session_state[quiz_visible_key]
|
47 |
+
|
48 |
+
if st.session_state[quiz_visible_key]:
|
49 |
+
with st.expander(f"Quiz – Slide {index+1}", expanded=True):
|
50 |
+
form = st.form(key=f"quiz_form_{module_name}_{index}")
|
51 |
+
form.markdown(f"**Q:** {quiz['question']}")
|
52 |
+
selected = form.radio("Your answer:", quiz.get("choices", []), key=f"quiz_choice_{module_name}_{index}")
|
53 |
+
submitted = form.form_submit_button("Submit Answer")
|
54 |
+
if submitted:
|
55 |
+
if selected == quiz.get("answer"):
|
56 |
+
st.success("✅ Correct!")
|
57 |
+
else:
|
58 |
+
st.error(f"❌ Nope—correct answer is **{quiz.get('answer')}**.")
|
|
|
59 |
|
60 |
def slide_controls(module_name, slides):
|
61 |
# Get module-specific slide index
|