Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -728,7 +728,7 @@ def create_quiz_interface():
|
|
| 728 |
def view_certificate():
|
| 729 |
"""Navigate to certificate tab"""
|
| 730 |
return gr.Tabs(selected=2)
|
| 731 |
-
|
| 732 |
def on_submit(questions, answers, current_idx, current_answer):
|
| 733 |
final_answers = list(answers)
|
| 734 |
if 0 <= current_idx < len(final_answers):
|
|
@@ -741,7 +741,7 @@ def create_quiz_interface():
|
|
| 741 |
0,
|
| 742 |
"",
|
| 743 |
gr.update(visible=True),
|
| 744 |
-
gr.
|
| 745 |
gr.update(visible=False) # view_cert_btn visibility
|
| 746 |
]
|
| 747 |
|
|
@@ -752,31 +752,31 @@ def create_quiz_interface():
|
|
| 752 |
color = "green" if f.is_correct else "red"
|
| 753 |
symbol = "✅" if f.is_correct else "❌"
|
| 754 |
feedback_html += f"""### Question {i+1}
|
| 755 |
-
{q.question}
|
| 756 |
-
|
| 757 |
-
<div style="color: {color}; padding: 10px; margin: 5px 0; border-left: 3px solid {color};">
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
</div>
|
| 761 |
-
"""
|
| 762 |
|
| 763 |
result_msg = "🎉 Passed!" if passed else "Please try again"
|
| 764 |
if not passed:
|
| 765 |
feedback_html += f"""
|
| 766 |
-
<div style="background-color: #ffe6e6; padding: 20px; margin-top: 20px; border-radius: 10px;">
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
</div>
|
| 771 |
-
"""
|
| 772 |
|
| 773 |
return [
|
| 774 |
feedback_html,
|
| 775 |
gr.update(visible=True),
|
| 776 |
score,
|
| 777 |
result_msg,
|
| 778 |
-
gr.update(visible=
|
| 779 |
-
gr.
|
| 780 |
gr.update(visible=passed) # Show view certificate button only if passed
|
| 781 |
]
|
| 782 |
# Event handlers
|
|
@@ -790,7 +790,7 @@ def create_quiz_interface():
|
|
| 790 |
current_options.change(fn=update_answer_state, inputs=[current_options, current_question_idx, answer_state], outputs=answer_state)
|
| 791 |
|
| 792 |
submit_btn.click(fn=on_submit, inputs=[current_questions, answer_state, current_question_idx, current_options], outputs=[feedback_box, results_group, score_display, result_message, question_box, tabs, view_cert_btn])
|
| 793 |
-
|
| 794 |
reset_btn.click(fn=reset_quiz, 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])
|
| 795 |
|
| 796 |
view_cert_btn.click(fn=lambda: gr.Tabs(selected=3), outputs=tabs)
|
|
|
|
| 728 |
def view_certificate():
|
| 729 |
"""Navigate to certificate tab"""
|
| 730 |
return gr.Tabs(selected=2)
|
| 731 |
+
|
| 732 |
def on_submit(questions, answers, current_idx, current_answer):
|
| 733 |
final_answers = list(answers)
|
| 734 |
if 0 <= current_idx < len(final_answers):
|
|
|
|
| 741 |
0,
|
| 742 |
"",
|
| 743 |
gr.update(visible=True),
|
| 744 |
+
gr.Tabs(selected=2), # Stay on assessment tab
|
| 745 |
gr.update(visible=False) # view_cert_btn visibility
|
| 746 |
]
|
| 747 |
|
|
|
|
| 752 |
color = "green" if f.is_correct else "red"
|
| 753 |
symbol = "✅" if f.is_correct else "❌"
|
| 754 |
feedback_html += f"""### Question {i+1}
|
| 755 |
+
{q.question}
|
| 756 |
+
|
| 757 |
+
<div style="color: {color}; padding: 10px; margin: 5px 0; border-left: 3px solid {color};">
|
| 758 |
+
{symbol} Your answer: {f.selected or "No answer"}
|
| 759 |
+
{'' if f.is_correct else f'<br>Correct answer: {f.correct_answer}'}
|
| 760 |
+
</div>
|
| 761 |
+
"""
|
| 762 |
|
| 763 |
result_msg = "🎉 Passed!" if passed else "Please try again"
|
| 764 |
if not passed:
|
| 765 |
feedback_html += f"""
|
| 766 |
+
<div style="background-color: #ffe6e6; padding: 20px; margin-top: 20px; border-radius: 10px;">
|
| 767 |
+
<h3 style="color: #cc0000;">Please Try Again</h3>
|
| 768 |
+
<p>Your score: {score:.1f}%</p>
|
| 769 |
+
<p>You need 80% or higher to pass and receive a certificate.</p>
|
| 770 |
+
</div>
|
| 771 |
+
"""
|
| 772 |
|
| 773 |
return [
|
| 774 |
feedback_html,
|
| 775 |
gr.update(visible=True),
|
| 776 |
score,
|
| 777 |
result_msg,
|
| 778 |
+
gr.update(visible=False), # Hide question box
|
| 779 |
+
gr.Tabs(selected=2), # Stay on assessment tab
|
| 780 |
gr.update(visible=passed) # Show view certificate button only if passed
|
| 781 |
]
|
| 782 |
# Event handlers
|
|
|
|
| 790 |
current_options.change(fn=update_answer_state, inputs=[current_options, current_question_idx, answer_state], outputs=answer_state)
|
| 791 |
|
| 792 |
submit_btn.click(fn=on_submit, inputs=[current_questions, answer_state, current_question_idx, current_options], outputs=[feedback_box, results_group, score_display, result_message, question_box, tabs, view_cert_btn])
|
| 793 |
+
|
| 794 |
reset_btn.click(fn=reset_quiz, 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])
|
| 795 |
|
| 796 |
view_cert_btn.click(fn=lambda: gr.Tabs(selected=3), outputs=tabs)
|