Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -751,6 +751,7 @@ def create_quiz_interface():
|
|
| 751 |
return gr.Tabs(selected=2)
|
| 752 |
|
| 753 |
def on_submit(questions, answers, current_idx, current_answer):
|
|
|
|
| 754 |
final_answers = list(answers)
|
| 755 |
if 0 <= current_idx < len(final_answers):
|
| 756 |
final_answers[current_idx] = current_answer
|
|
@@ -762,47 +763,65 @@ def create_quiz_interface():
|
|
| 762 |
0,
|
| 763 |
"",
|
| 764 |
gr.update(visible=True),
|
| 765 |
-
gr.
|
|
|
|
|
|
|
| 766 |
gr.update(visible=False)
|
| 767 |
]
|
| 768 |
|
| 769 |
score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
|
| 770 |
|
| 771 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 772 |
for i, (q, f) in enumerate(zip(questions, feedback)):
|
| 773 |
color = "green" if f.is_correct else "red"
|
| 774 |
symbol = "✅" if f.is_correct else "❌"
|
| 775 |
|
| 776 |
-
feedback_html += f"""
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 782 |
|
| 783 |
-
|
| 784 |
-
if
|
| 785 |
-
feedback_html += f"""
|
| 786 |
-
|
| 787 |
-
|
| 788 |
-
|
| 789 |
-
|
|
|
|
| 790 |
else:
|
| 791 |
-
feedback_html += f"""
|
| 792 |
-
|
| 793 |
-
|
| 794 |
-
|
| 795 |
-
|
|
|
|
|
|
|
|
|
|
| 796 |
|
| 797 |
return [
|
| 798 |
-
feedback_html,
|
| 799 |
-
gr.update(visible=True),
|
| 800 |
-
score,
|
| 801 |
-
|
| 802 |
-
gr.update(visible=False),
|
| 803 |
-
gr.
|
| 804 |
-
gr.update(visible=passed)
|
|
|
|
|
|
|
| 805 |
]
|
|
|
|
| 806 |
# Event handlers
|
| 807 |
|
| 808 |
generate_btn.click(fn=on_generate_questions, inputs=[text_input, num_questions], outputs=[question_display, current_options, question_counter, question_box, current_questions, current_question_idx, answer_state, tabs, results_group, view_cert_btn]).then(fn=lambda: gr.Tabs(selected=2), outputs=tabs)
|
|
|
|
| 751 |
return gr.Tabs(selected=2)
|
| 752 |
|
| 753 |
def on_submit(questions, answers, current_idx, current_answer):
|
| 754 |
+
"""Handle quiz submission with updated styling and logic"""
|
| 755 |
final_answers = list(answers)
|
| 756 |
if 0 <= current_idx < len(final_answers):
|
| 757 |
final_answers[current_idx] = current_answer
|
|
|
|
| 763 |
0,
|
| 764 |
"",
|
| 765 |
gr.update(visible=True),
|
| 766 |
+
gr.update(visible=True),
|
| 767 |
+
gr.update(visible=False),
|
| 768 |
+
gr.update(visible=False),
|
| 769 |
gr.update(visible=False)
|
| 770 |
]
|
| 771 |
|
| 772 |
score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
|
| 773 |
|
| 774 |
+
# Updated feedback HTML with proper font styling
|
| 775 |
+
feedback_html = """
|
| 776 |
+
<div style="font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;">
|
| 777 |
+
<h1 style="font-size: 24px; font-weight: 600; margin-bottom: 20px;">Assessment Results</h1>
|
| 778 |
+
"""
|
| 779 |
+
|
| 780 |
for i, (q, f) in enumerate(zip(questions, feedback)):
|
| 781 |
color = "green" if f.is_correct else "red"
|
| 782 |
symbol = "✅" if f.is_correct else "❌"
|
| 783 |
|
| 784 |
+
feedback_html += f"""
|
| 785 |
+
<div style="margin-bottom: 24px;">
|
| 786 |
+
<h3 style="font-size: 18px; font-weight: 500; margin-bottom: 12px;">Question {i+1}</h3>
|
| 787 |
+
<p style="font-size: 16px; margin-bottom: 12px;">{q.question}</p>
|
| 788 |
+
<div style="color: {color}; padding: 12px; margin: 8px 0; border-left: 3px solid {color}; background-color: {'#f8fff8' if f.is_correct else '#fff8f8'}; font-size: 15px;">
|
| 789 |
+
{symbol} Your answer: {f.selected or "No answer"}
|
| 790 |
+
{'' if f.is_correct else f'<br><span style="font-weight: 500;">Correct answer:</span> {f.correct_answer}'}
|
| 791 |
+
</div>
|
| 792 |
+
</div>
|
| 793 |
+
"""
|
| 794 |
|
| 795 |
+
# Add summary box with score
|
| 796 |
+
if passed:
|
| 797 |
+
feedback_html += f"""
|
| 798 |
+
<div style="background-color: #e6ffe6; padding: 20px; margin: 20px 0; border-radius: 10px; border: 1px solid #ccffcc;">
|
| 799 |
+
<h3 style="color: #008000; margin: 0 0 12px 0; font-size: 20px;">🎉 Congratulations!</h3>
|
| 800 |
+
<p style="margin: 0; font-size: 16px;">You passed with a score of {score:.1f}%</p>
|
| 801 |
+
</div>
|
| 802 |
+
"""
|
| 803 |
else:
|
| 804 |
+
feedback_html += f"""
|
| 805 |
+
<div style="background-color: #ffe6e6; padding: 20px; margin: 20px 0; border-radius: 10px; border: 1px solid #ffcccc;">
|
| 806 |
+
<h3 style="color: #cc0000; margin: 0 0 12px 0; font-size: 20px;">Please Try Again</h3>
|
| 807 |
+
<p style="margin: 0; font-size: 16px;">Your score: {score:.1f}% (80% required to pass)</p>
|
| 808 |
+
</div>
|
| 809 |
+
"""
|
| 810 |
+
|
| 811 |
+
feedback_html += "</div>"
|
| 812 |
|
| 813 |
return [
|
| 814 |
+
feedback_html, # feedback_box
|
| 815 |
+
gr.update(visible=True), # results_group
|
| 816 |
+
score, # score_display
|
| 817 |
+
"🎉 Passed!" if passed else "Please try again", # result_message
|
| 818 |
+
gr.update(visible=False), # question_box
|
| 819 |
+
gr.update(visible=True), # reset_btn
|
| 820 |
+
gr.update(visible=passed), # view_cert_btn
|
| 821 |
+
gr.update(visible=not passed), # back_to_assessment
|
| 822 |
+
gr.update(visible=False) # profile_tab
|
| 823 |
]
|
| 824 |
+
|
| 825 |
# Event handlers
|
| 826 |
|
| 827 |
generate_btn.click(fn=on_generate_questions, inputs=[text_input, num_questions], outputs=[question_display, current_options, question_counter, question_box, current_questions, current_question_idx, answer_state, tabs, results_group, view_cert_btn]).then(fn=lambda: gr.Tabs(selected=2), outputs=tabs)
|