Spaces:
Running
Running
mah-diaa
commited on
Commit
Β·
c1b4062
1
Parent(s):
e69d5cf
Changed files
Browse files- app.py +13 -1
- handlers/quiz_handlers.py +29 -27
app.py
CHANGED
|
@@ -437,7 +437,19 @@ Upload a PDF or tell me what you want to learn to see extracted concepts here!
|
|
| 437 |
quick_resources_btn.click(quick_find_resources, None, [quick_output], api_name=False)
|
| 438 |
|
| 439 |
# Quiz modal interactions
|
| 440 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
app.load(load_quiz_to_modal, None, [
|
| 442 |
quiz_status, quiz_question_num, quiz_score_display, quiz_question_text,
|
| 443 |
quiz_options, quiz_submit_btn, quiz_feedback, quiz_explanation,
|
|
|
|
| 437 |
quick_resources_btn.click(quick_find_resources, None, [quick_output], api_name=False)
|
| 438 |
|
| 439 |
# Quiz modal interactions
|
| 440 |
+
# Clear quiz on page load/refresh (don't persist across refreshes)
|
| 441 |
+
def clear_quiz_on_load():
|
| 442 |
+
"""Clear quiz state when page loads/refreshes."""
|
| 443 |
+
from core.state import user_state
|
| 444 |
+
user_state["current_quiz"] = []
|
| 445 |
+
user_state["current_question_idx"] = 0
|
| 446 |
+
user_state["show_quiz_modal"] = False
|
| 447 |
+
return None
|
| 448 |
+
|
| 449 |
+
# Clear quiz first, then load (which will show "no quiz" message)
|
| 450 |
+
app.load(clear_quiz_on_load, None, [], api_name=False)
|
| 451 |
+
|
| 452 |
+
# Load quiz when app loads (will show "no quiz" since we just cleared it)
|
| 453 |
app.load(load_quiz_to_modal, None, [
|
| 454 |
quiz_status, quiz_question_num, quiz_score_display, quiz_question_text,
|
| 455 |
quiz_options, quiz_submit_btn, quiz_feedback, quiz_explanation,
|
handlers/quiz_handlers.py
CHANGED
|
@@ -48,33 +48,35 @@ def quick_generate_quiz():
|
|
| 48 |
|
| 49 |
def load_quiz_to_modal():
|
| 50 |
"""Load quiz from state into modal."""
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
)
|
|
|
|
|
|
|
| 78 |
|
| 79 |
|
| 80 |
def display_question(quiz_data, idx, score, _):
|
|
|
|
| 48 |
|
| 49 |
def load_quiz_to_modal():
|
| 50 |
"""Load quiz from state into modal."""
|
| 51 |
+
quiz = user_state.get("current_quiz")
|
| 52 |
+
# Check if we have a quiz to load
|
| 53 |
+
if not quiz or len(quiz) == 0:
|
| 54 |
+
print("π [QUIZ] No quiz available to load")
|
| 55 |
+
# Return 15 values to match outputs: quiz_status, quiz_question_num, quiz_score_display, quiz_question_text,
|
| 56 |
+
# quiz_options, quiz_submit_btn, quiz_feedback, quiz_explanation,
|
| 57 |
+
# quiz_prev_btn, quiz_next_btn, quiz_complete, quiz_restart_btn,
|
| 58 |
+
# current_question_idx, quiz_score_state, quiz_data_state
|
| 59 |
+
return (
|
| 60 |
+
gr.update(visible=True, value="π **No quiz available yet**"), # quiz_status
|
| 61 |
+
gr.update(visible=False), # quiz_question_num
|
| 62 |
+
gr.update(visible=False), # quiz_score_display
|
| 63 |
+
gr.update(visible=True, value="Generate a quiz first by telling me what you want to learn, then ask for a quiz!"), # quiz_question_text
|
| 64 |
+
gr.update(visible=False, choices=[]), # quiz_options
|
| 65 |
+
gr.update(visible=False), # quiz_submit_btn
|
| 66 |
+
gr.update(visible=False), # quiz_feedback
|
| 67 |
+
gr.update(visible=False), # quiz_explanation
|
| 68 |
+
gr.update(visible=False), # quiz_prev_btn
|
| 69 |
+
gr.update(visible=False), # quiz_next_btn
|
| 70 |
+
gr.update(visible=False), # quiz_complete
|
| 71 |
+
gr.update(visible=False), # quiz_restart_btn
|
| 72 |
+
gr.update(value=0), # current_question_idx
|
| 73 |
+
gr.update(value={"correct": 0, "total": 0}), # quiz_score_state
|
| 74 |
+
gr.update(value=[]) # quiz_data_state
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
print(f"π [QUIZ] Loading existing quiz with {len(quiz)} questions")
|
| 78 |
+
# Show first question
|
| 79 |
+
return display_question(quiz, 0, {"correct": 0, "total": 0}, quiz)
|
| 80 |
|
| 81 |
|
| 82 |
def display_question(quiz_data, idx, score, _):
|