Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -526,7 +526,7 @@ class QuizApp:
|
|
| 526 |
<p>You need 80% or higher to pass and receive a certificate.</p>
|
| 527 |
</div>
|
| 528 |
"""
|
| 529 |
-
|
| 530 |
def create_quiz_interface():
|
| 531 |
if not os.getenv("GROQ_API_KEY"):
|
| 532 |
raise EnvironmentError("Please set your GROQ_API_KEY environment variable")
|
|
@@ -595,15 +595,28 @@ def create_quiz_interface():
|
|
| 595 |
|
| 596 |
gr.Markdown("---") # Separator
|
| 597 |
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 603 |
|
| 604 |
# Results section
|
| 605 |
with gr.Group(visible=False) as results_group:
|
| 606 |
feedback_box = gr.Markdown("")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 607 |
|
| 608 |
# Certification Tab
|
| 609 |
with gr.Tab("🎓 Step 3: Get Certified"):
|
|
@@ -614,8 +627,7 @@ def create_quiz_interface():
|
|
| 614 |
value="Professional Assessment Certification"
|
| 615 |
)
|
| 616 |
certificate_display = gr.Image(label="Your Certificate")
|
| 617 |
-
|
| 618 |
-
# Helper Functions
|
| 619 |
def on_generate_questions(text, num_questions):
|
| 620 |
success, questions = quiz_app.generate_questions(text, num_questions)
|
| 621 |
if not success:
|
|
@@ -628,7 +640,8 @@ def create_quiz_interface():
|
|
| 628 |
0,
|
| 629 |
[None] * 5,
|
| 630 |
gr.update(selected=1),
|
| 631 |
-
gr.update(visible=False)
|
|
|
|
| 632 |
]
|
| 633 |
|
| 634 |
initial_answers = [None] * len(questions)
|
|
@@ -648,7 +661,8 @@ def create_quiz_interface():
|
|
| 648 |
0,
|
| 649 |
initial_answers,
|
| 650 |
gr.update(selected=1),
|
| 651 |
-
gr.update(visible=False)
|
|
|
|
| 652 |
]
|
| 653 |
|
| 654 |
def navigate(direction, current_idx, questions, answers, current_answer):
|
|
@@ -682,10 +696,10 @@ def create_quiz_interface():
|
|
| 682 |
),
|
| 683 |
f"Question {new_idx + 1} of {len(questions)}",
|
| 684 |
gr.update(visible=True)
|
| 685 |
-
]
|
| 686 |
|
| 687 |
def handle_prev(current_idx, questions, answers, current_answer):
|
| 688 |
-
|
| 689 |
|
| 690 |
def handle_next(current_idx, questions, answers, current_answer):
|
| 691 |
return navigate(1, current_idx, questions, answers, current_answer)
|
|
@@ -708,7 +722,8 @@ def create_quiz_interface():
|
|
| 708 |
0,
|
| 709 |
"",
|
| 710 |
gr.update(visible=True),
|
| 711 |
-
gr.update(selected=1)
|
|
|
|
| 712 |
]
|
| 713 |
|
| 714 |
score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
|
|
@@ -742,10 +757,19 @@ def create_quiz_interface():
|
|
| 742 |
score,
|
| 743 |
result_msg,
|
| 744 |
gr.update(visible=not passed),
|
| 745 |
-
gr.update(selected=
|
|
|
|
| 746 |
]
|
| 747 |
|
| 748 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 749 |
generate_btn.click(
|
| 750 |
fn=on_generate_questions,
|
| 751 |
inputs=[text_input, num_questions],
|
|
@@ -758,8 +782,12 @@ def create_quiz_interface():
|
|
| 758 |
current_question_idx,
|
| 759 |
answer_state,
|
| 760 |
tabs,
|
| 761 |
-
results_group
|
|
|
|
| 762 |
]
|
|
|
|
|
|
|
|
|
|
| 763 |
)
|
| 764 |
|
| 765 |
prev_btn.click(
|
|
@@ -818,10 +846,34 @@ def create_quiz_interface():
|
|
| 818 |
score_display,
|
| 819 |
result_message,
|
| 820 |
question_box,
|
| 821 |
-
tabs
|
|
|
|
| 822 |
]
|
| 823 |
)
|
| 824 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 825 |
score_display.change(
|
| 826 |
fn=quiz_app.certificate_generator.generate,
|
| 827 |
inputs=[score_display, name, course_name, company_logo, participant_photo],
|
|
|
|
| 526 |
<p>You need 80% or higher to pass and receive a certificate.</p>
|
| 527 |
</div>
|
| 528 |
"""
|
| 529 |
+
------------------
|
| 530 |
def create_quiz_interface():
|
| 531 |
if not os.getenv("GROQ_API_KEY"):
|
| 532 |
raise EnvironmentError("Please set your GROQ_API_KEY environment variable")
|
|
|
|
| 595 |
|
| 596 |
gr.Markdown("---") # Separator
|
| 597 |
|
| 598 |
+
with gr.Row():
|
| 599 |
+
submit_btn = gr.Button(
|
| 600 |
+
"Submit Assessment",
|
| 601 |
+
variant="primary",
|
| 602 |
+
size="lg"
|
| 603 |
+
)
|
| 604 |
+
reset_btn = gr.Button(
|
| 605 |
+
"Reset Quiz",
|
| 606 |
+
variant="secondary",
|
| 607 |
+
size="lg"
|
| 608 |
+
)
|
| 609 |
|
| 610 |
# Results section
|
| 611 |
with gr.Group(visible=False) as results_group:
|
| 612 |
feedback_box = gr.Markdown("")
|
| 613 |
+
with gr.Row():
|
| 614 |
+
view_cert_btn = gr.Button(
|
| 615 |
+
"View Certificate",
|
| 616 |
+
variant="primary",
|
| 617 |
+
size="lg",
|
| 618 |
+
visible=False
|
| 619 |
+
)
|
| 620 |
|
| 621 |
# Certification Tab
|
| 622 |
with gr.Tab("🎓 Step 3: Get Certified"):
|
|
|
|
| 627 |
value="Professional Assessment Certification"
|
| 628 |
)
|
| 629 |
certificate_display = gr.Image(label="Your Certificate")
|
| 630 |
+
# Helper Functions
|
|
|
|
| 631 |
def on_generate_questions(text, num_questions):
|
| 632 |
success, questions = quiz_app.generate_questions(text, num_questions)
|
| 633 |
if not success:
|
|
|
|
| 640 |
0,
|
| 641 |
[None] * 5,
|
| 642 |
gr.update(selected=1),
|
| 643 |
+
gr.update(visible=False),
|
| 644 |
+
gr.update(visible=False) # view_cert_btn visibility
|
| 645 |
]
|
| 646 |
|
| 647 |
initial_answers = [None] * len(questions)
|
|
|
|
| 661 |
0,
|
| 662 |
initial_answers,
|
| 663 |
gr.update(selected=1),
|
| 664 |
+
gr.update(visible=False),
|
| 665 |
+
gr.update(visible=False) # view_cert_btn visibility
|
| 666 |
]
|
| 667 |
|
| 668 |
def navigate(direction, current_idx, questions, answers, current_answer):
|
|
|
|
| 696 |
),
|
| 697 |
f"Question {new_idx + 1} of {len(questions)}",
|
| 698 |
gr.update(visible=True)
|
| 699 |
+
]
|
| 700 |
|
| 701 |
def handle_prev(current_idx, questions, answers, current_answer):
|
| 702 |
+
return navigate(-1, current_idx, questions, answers, current_answer)
|
| 703 |
|
| 704 |
def handle_next(current_idx, questions, answers, current_answer):
|
| 705 |
return navigate(1, current_idx, questions, answers, current_answer)
|
|
|
|
| 722 |
0,
|
| 723 |
"",
|
| 724 |
gr.update(visible=True),
|
| 725 |
+
gr.update(selected=1),
|
| 726 |
+
gr.update(visible=False) # view_cert_btn visibility
|
| 727 |
]
|
| 728 |
|
| 729 |
score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
|
|
|
|
| 757 |
score,
|
| 758 |
result_msg,
|
| 759 |
gr.update(visible=not passed),
|
| 760 |
+
gr.update(selected=1),
|
| 761 |
+
gr.update(visible=passed) # Show view certificate button only if passed
|
| 762 |
]
|
| 763 |
|
| 764 |
+
def reset_quiz(text, num_questions):
|
| 765 |
+
"""Handle quiz reset"""
|
| 766 |
+
return on_generate_questions(text, num_questions)
|
| 767 |
+
|
| 768 |
+
def view_certificate():
|
| 769 |
+
"""Navigate to certificate tab"""
|
| 770 |
+
return gr.update(selected=2)
|
| 771 |
+
|
| 772 |
+
# Event handlers
|
| 773 |
generate_btn.click(
|
| 774 |
fn=on_generate_questions,
|
| 775 |
inputs=[text_input, num_questions],
|
|
|
|
| 782 |
current_question_idx,
|
| 783 |
answer_state,
|
| 784 |
tabs,
|
| 785 |
+
results_group,
|
| 786 |
+
view_cert_btn
|
| 787 |
]
|
| 788 |
+
).then(
|
| 789 |
+
lambda: gr.update(selected=1), # Navigate to Take Assessment tab
|
| 790 |
+
outputs=tabs
|
| 791 |
)
|
| 792 |
|
| 793 |
prev_btn.click(
|
|
|
|
| 846 |
score_display,
|
| 847 |
result_message,
|
| 848 |
question_box,
|
| 849 |
+
tabs,
|
| 850 |
+
view_cert_btn
|
| 851 |
]
|
| 852 |
)
|
| 853 |
|
| 854 |
+
reset_btn.click(
|
| 855 |
+
fn=reset_quiz,
|
| 856 |
+
inputs=[text_input, num_questions],
|
| 857 |
+
outputs=[
|
| 858 |
+
question_display,
|
| 859 |
+
current_options,
|
| 860 |
+
question_counter,
|
| 861 |
+
question_box,
|
| 862 |
+
current_questions,
|
| 863 |
+
current_question_idx,
|
| 864 |
+
answer_state,
|
| 865 |
+
tabs,
|
| 866 |
+
results_group,
|
| 867 |
+
view_cert_btn
|
| 868 |
+
]
|
| 869 |
+
)
|
| 870 |
+
|
| 871 |
+
view_cert_btn.click(
|
| 872 |
+
fn=view_certificate,
|
| 873 |
+
outputs=tabs
|
| 874 |
+
)
|
| 875 |
+
|
| 876 |
+
# Certificate generation
|
| 877 |
score_display.change(
|
| 878 |
fn=quiz_app.certificate_generator.generate,
|
| 879 |
inputs=[score_display, name, course_name, company_logo, participant_photo],
|