Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -636,40 +636,47 @@ def create_quiz_interface():
|
|
636 |
|
637 |
# Helper Functions
|
638 |
def on_generate_questions(text, num_questions):
|
|
|
639 |
success, questions = quiz_app.generate_questions(text, num_questions)
|
640 |
if not success:
|
641 |
return [
|
642 |
-
"",
|
643 |
-
gr.update(choices=[], visible=False),
|
644 |
-
"",
|
645 |
-
gr.update(visible=False),
|
646 |
-
[],
|
647 |
-
0,
|
648 |
-
[None] * 5,
|
649 |
-
gr.
|
650 |
-
gr.update(visible=False)
|
|
|
651 |
]
|
652 |
|
|
|
653 |
initial_answers = [None] * len(questions)
|
654 |
question = questions[0]
|
|
|
|
|
|
|
|
|
655 |
|
656 |
return [
|
657 |
-
|
658 |
gr.update(
|
659 |
choices=question.options,
|
660 |
value=None,
|
661 |
visible=True,
|
662 |
label="Select your answer for Question 1:"
|
663 |
-
),
|
664 |
-
f"Question 1 of {len(questions)}",
|
665 |
-
gr.update(visible=True),
|
666 |
-
questions,
|
667 |
-
0,
|
668 |
-
initial_answers,
|
669 |
-
gr.
|
670 |
-
gr.update(visible=False)
|
|
|
671 |
]
|
672 |
-
|
673 |
def navigate(direction, current_idx, questions, answers, current_answer):
|
674 |
"""Handle navigation between questions"""
|
675 |
if not questions:
|
|
|
636 |
|
637 |
# Helper Functions
|
638 |
def on_generate_questions(text, num_questions):
|
639 |
+
"""Generate quiz questions and setup initial state"""
|
640 |
success, questions = quiz_app.generate_questions(text, num_questions)
|
641 |
if not success:
|
642 |
return [
|
643 |
+
"", # question_display
|
644 |
+
gr.update(choices=[], visible=False), # current_options
|
645 |
+
"", # question_counter
|
646 |
+
gr.update(visible=False), # question_box
|
647 |
+
[], # current_questions
|
648 |
+
0, # current_question_idx
|
649 |
+
[None] * 5, # answer_state
|
650 |
+
gr.Tabs(selected=2), # tabs
|
651 |
+
gr.update(visible=False), # results_group
|
652 |
+
gr.update(visible=False) # view_cert_btn - added this
|
653 |
]
|
654 |
|
655 |
+
# Setup initial state with first question
|
656 |
initial_answers = [None] * len(questions)
|
657 |
question = questions[0]
|
658 |
+
question_html = f"""## Question 1
|
659 |
+
{question.question}
|
660 |
+
|
661 |
+
Please select one answer:"""
|
662 |
|
663 |
return [
|
664 |
+
question_html, # question_display
|
665 |
gr.update(
|
666 |
choices=question.options,
|
667 |
value=None,
|
668 |
visible=True,
|
669 |
label="Select your answer for Question 1:"
|
670 |
+
), # current_options
|
671 |
+
f"Question 1 of {len(questions)}", # question_counter
|
672 |
+
gr.update(visible=True), # question_box
|
673 |
+
questions, # current_questions
|
674 |
+
0, # current_question_idx
|
675 |
+
initial_answers, # answer_state
|
676 |
+
gr.Tabs(selected=2), # tabs
|
677 |
+
gr.update(visible=False), # results_group
|
678 |
+
gr.update(visible=False) # view_cert_btn - added this
|
679 |
]
|
|
|
680 |
def navigate(direction, current_idx, questions, answers, current_answer):
|
681 |
"""Handle navigation between questions"""
|
682 |
if not questions:
|