Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -617,11 +617,17 @@ def create_quiz_interface():
|
|
| 617 |
variant="primary",
|
| 618 |
size="lg"
|
| 619 |
)
|
| 620 |
-
|
| 621 |
# Results Section in Assessment Tab
|
| 622 |
with gr.Column(visible=False) as results_group:
|
| 623 |
-
result_message = gr.Markdown(
|
| 624 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 625 |
gr.Markdown("---") # Separator
|
| 626 |
with gr.Row(equal_height=True):
|
| 627 |
reset_btn = gr.Button(
|
|
@@ -635,7 +641,8 @@ def create_quiz_interface():
|
|
| 635 |
variant="primary",
|
| 636 |
size="lg",
|
| 637 |
visible=False
|
| 638 |
-
)
|
|
|
|
| 639 |
|
| 640 |
# Certification Tab
|
| 641 |
with gr.Tab(id=3, label="🎓 Step 3: Get Certified"):
|
|
@@ -749,7 +756,7 @@ def create_quiz_interface():
|
|
| 749 |
return navigate(1, current_idx, questions, answers, current_answer)
|
| 750 |
|
| 751 |
def on_submit(questions, answers, current_idx, current_answer):
|
| 752 |
-
"""Handle quiz submission with proper Markdown rendering"""
|
| 753 |
final_answers = list(answers)
|
| 754 |
if 0 <= current_idx < len(final_answers):
|
| 755 |
final_answers[current_idx] = current_answer
|
|
@@ -763,54 +770,56 @@ def create_quiz_interface():
|
|
| 763 |
gr.update(visible=True),
|
| 764 |
gr.update(visible=True),
|
| 765 |
gr.update(visible=False),
|
| 766 |
-
gr.update(visible=False),
|
| 767 |
gr.update(visible=False)
|
| 768 |
]
|
| 769 |
|
| 770 |
score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
|
| 771 |
|
| 772 |
-
# Create feedback content using
|
| 773 |
feedback_content = f"""# Assessment Results
|
| 774 |
|
| 775 |
-
Score: {score:.1f}
|
| 776 |
|
| 777 |
"""
|
| 778 |
|
| 779 |
for i, (q, f) in enumerate(zip(questions, feedback)):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 780 |
feedback_content += f"""### Question {i+1}
|
| 781 |
{q.question}
|
| 782 |
|
| 783 |
-
{
|
| 784 |
-
{'' if f.is_correct else f'Correct answer
|
| 785 |
|
| 786 |
"""
|
| 787 |
|
| 788 |
-
# Add summary box
|
| 789 |
if passed:
|
| 790 |
feedback_content += f"""
|
| 791 |
---
|
| 792 |
-
|
| 793 |
You passed with a score of {score:.1f}%!
|
| 794 |
"""
|
| 795 |
else:
|
| 796 |
feedback_content += f"""
|
| 797 |
---
|
| 798 |
-
|
| 799 |
You scored {score:.1f}%. You need 80% or higher to pass.
|
| 800 |
Please try again.
|
| 801 |
"""
|
| 802 |
|
| 803 |
return [
|
| 804 |
feedback_content, # feedback_box
|
| 805 |
-
gr.update(visible=True),
|
| 806 |
-
score,
|
| 807 |
-
"
|
| 808 |
-
gr.update(visible=False),
|
| 809 |
-
gr.update(visible=not passed),
|
| 810 |
-
gr.update(visible=passed),
|
| 811 |
-
gr.update(
|
| 812 |
-
|
| 813 |
-
]
|
| 814 |
|
| 815 |
# Event Handlers
|
| 816 |
generate_btn.click(
|
|
|
|
| 617 |
variant="primary",
|
| 618 |
size="lg"
|
| 619 |
)
|
| 620 |
+
|
| 621 |
# Results Section in Assessment Tab
|
| 622 |
with gr.Column(visible=False) as results_group:
|
| 623 |
+
result_message = gr.Markdown(
|
| 624 |
+
label="Result",
|
| 625 |
+
show_label=True
|
| 626 |
+
)
|
| 627 |
+
feedback_box = gr.Markdown(
|
| 628 |
+
label="Detailed Feedback",
|
| 629 |
+
show_label=True
|
| 630 |
+
)
|
| 631 |
gr.Markdown("---") # Separator
|
| 632 |
with gr.Row(equal_height=True):
|
| 633 |
reset_btn = gr.Button(
|
|
|
|
| 641 |
variant="primary",
|
| 642 |
size="lg",
|
| 643 |
visible=False
|
| 644 |
+
)
|
| 645 |
+
|
| 646 |
|
| 647 |
# Certification Tab
|
| 648 |
with gr.Tab(id=3, label="🎓 Step 3: Get Certified"):
|
|
|
|
| 756 |
return navigate(1, current_idx, questions, answers, current_answer)
|
| 757 |
|
| 758 |
def on_submit(questions, answers, current_idx, current_answer):
|
| 759 |
+
"""Handle quiz submission with proper Markdown rendering and emojis"""
|
| 760 |
final_answers = list(answers)
|
| 761 |
if 0 <= current_idx < len(final_answers):
|
| 762 |
final_answers[current_idx] = current_answer
|
|
|
|
| 770 |
gr.update(visible=True),
|
| 771 |
gr.update(visible=True),
|
| 772 |
gr.update(visible=False),
|
|
|
|
| 773 |
gr.update(visible=False)
|
| 774 |
]
|
| 775 |
|
| 776 |
score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
|
| 777 |
|
| 778 |
+
# Create feedback content using proper Markdown with emojis
|
| 779 |
feedback_content = f"""# Assessment Results
|
| 780 |
|
| 781 |
+
**Score: {score:.1f}%**
|
| 782 |
|
| 783 |
"""
|
| 784 |
|
| 785 |
for i, (q, f) in enumerate(zip(questions, feedback)):
|
| 786 |
+
icon = "✅" if f.is_correct else "❌"
|
| 787 |
+
color = "green" if f.is_correct else "red"
|
| 788 |
+
|
| 789 |
+
# Using markdown syntax with color formatting
|
| 790 |
feedback_content += f"""### Question {i+1}
|
| 791 |
{q.question}
|
| 792 |
|
| 793 |
+
{icon} **Your answer:** {f.selected or 'No answer'}
|
| 794 |
+
{'' if f.is_correct else f'**Correct answer:** {f.correct_answer}'}
|
| 795 |
|
| 796 |
"""
|
| 797 |
|
| 798 |
+
# Add summary box
|
| 799 |
if passed:
|
| 800 |
feedback_content += f"""
|
| 801 |
---
|
| 802 |
+
## 🎉 Congratulations!
|
| 803 |
You passed with a score of {score:.1f}%!
|
| 804 |
"""
|
| 805 |
else:
|
| 806 |
feedback_content += f"""
|
| 807 |
---
|
| 808 |
+
## Need Improvement
|
| 809 |
You scored {score:.1f}%. You need 80% or higher to pass.
|
| 810 |
Please try again.
|
| 811 |
"""
|
| 812 |
|
| 813 |
return [
|
| 814 |
feedback_content, # feedback_box
|
| 815 |
+
gr.update(visible=True), # results_group
|
| 816 |
+
score, # score_display
|
| 817 |
+
f"Score: {score:.1f}%", # result_message
|
| 818 |
+
gr.update(visible=False), # question_box
|
| 819 |
+
gr.update(visible=not passed), # reset_btn
|
| 820 |
+
gr.update(visible=passed), # view_cert_btn
|
| 821 |
+
gr.update(selected=2) # tabs
|
| 822 |
+
]
|
|
|
|
| 823 |
|
| 824 |
# Event Handlers
|
| 825 |
generate_btn.click(
|