Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -675,67 +675,6 @@ def create_quiz_interface():
|
|
675 |
gr.update(visible=False) # view_cert_btn visibility
|
676 |
]
|
677 |
|
678 |
-
def on_submit(questions, answers, current_idx, current_answer):
|
679 |
-
final_answers = list(answers)
|
680 |
-
if 0 <= current_idx < len(final_answers):
|
681 |
-
final_answers[current_idx] = current_answer
|
682 |
-
|
683 |
-
if not all(a is not None for a in final_answers[:len(questions)]):
|
684 |
-
return [
|
685 |
-
"⚠️ Please answer all questions before submitting.",
|
686 |
-
gr.update(visible=True),
|
687 |
-
0,
|
688 |
-
"",
|
689 |
-
gr.update(visible=True),
|
690 |
-
gr.update(selected=1),
|
691 |
-
gr.update(visible=False) # view_cert_btn visibility
|
692 |
-
]
|
693 |
-
|
694 |
-
score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
|
695 |
-
|
696 |
-
feedback_html = "# Assessment Results\n\n"
|
697 |
-
for i, (q, f) in enumerate(zip(questions, feedback)):
|
698 |
-
color = "green" if f.is_correct else "red"
|
699 |
-
symbol = "✅" if f.is_correct else "❌"
|
700 |
-
feedback_html += f"""### Question {i+1}
|
701 |
-
{q.question}
|
702 |
-
|
703 |
-
<div style="color: {color}; padding: 10px; margin: 5px 0; border-left: 3px solid {color};">
|
704 |
-
{symbol} Your answer: {f.selected or "No answer"}
|
705 |
-
{'' if f.is_correct else f'<br>Correct answer: {f.correct_answer}'}
|
706 |
-
</div>
|
707 |
-
"""
|
708 |
-
|
709 |
-
result_msg = "🎉 Passed!" if passed else "Please try again"
|
710 |
-
|
711 |
-
# Add a message about viewing certificate if passed
|
712 |
-
if passed:
|
713 |
-
feedback_html += f"""
|
714 |
-
<div style="background-color: #e6ffe6; padding: 20px; margin-top: 20px; border-radius: 10px;">
|
715 |
-
<h3 style="color: #008000;">🎉 Congratulations!</h3>
|
716 |
-
<p>You passed with a score of {score:.1f}%</p>
|
717 |
-
<p>Click the "View Certificate" button below to see your certificate.</p>
|
718 |
-
</div>
|
719 |
-
"""
|
720 |
-
else:
|
721 |
-
feedback_html += f"""
|
722 |
-
<div style="background-color: #ffe6e6; padding: 20px; margin-top: 20px; border-radius: 10px;">
|
723 |
-
<h3 style="color: #cc0000;">Please Try Again</h3>
|
724 |
-
<p>Your score: {score:.1f}%</p>
|
725 |
-
<p>You need 80% or higher to pass and receive a certificate.</p>
|
726 |
-
</div>
|
727 |
-
"""
|
728 |
-
|
729 |
-
return [
|
730 |
-
feedback_html,
|
731 |
-
gr.update(visible=True),
|
732 |
-
score,
|
733 |
-
result_msg,
|
734 |
-
gr.update(visible=not passed),
|
735 |
-
gr.update(selected=1),
|
736 |
-
gr.update(visible=passed) # Show view certificate button only if passed
|
737 |
-
]
|
738 |
-
|
739 |
def goto_take_assessment():
|
740 |
"""Navigate to Take Assessment tab"""
|
741 |
return gr.update(selected=1)
|
|
|
675 |
gr.update(visible=False) # view_cert_btn visibility
|
676 |
]
|
677 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
678 |
def goto_take_assessment():
|
679 |
"""Navigate to Take Assessment tab"""
|
680 |
return gr.update(selected=1)
|