Spaces:
Running
Running
capradeepgujaran
commited on
Commit
•
cc8f00f
1
Parent(s):
190e57a
Update app.py
Browse files
app.py
CHANGED
@@ -750,14 +750,14 @@ def create_quiz_interface():
|
|
750 |
return gr.Tabs(selected=2)
|
751 |
|
752 |
def on_submit(questions, answers, current_idx, current_answer):
|
753 |
-
"""Handle quiz submission with proper
|
754 |
final_answers = list(answers)
|
755 |
if 0 <= current_idx < len(final_answers):
|
756 |
final_answers[current_idx] = current_answer
|
757 |
|
758 |
if not all(a is not None for a in final_answers[:len(questions)]):
|
759 |
return [
|
760 |
-
|
761 |
gr.update(visible=True),
|
762 |
0,
|
763 |
"",
|
@@ -770,10 +770,10 @@ def create_quiz_interface():
|
|
770 |
|
771 |
score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
|
772 |
|
773 |
-
# Create feedback content using
|
774 |
feedback_content = f"""# Assessment Results
|
775 |
|
776 |
-
|
777 |
|
778 |
"""
|
779 |
|
@@ -781,36 +781,37 @@ def create_quiz_interface():
|
|
781 |
feedback_content += f"""### Question {i+1}
|
782 |
{q.question}
|
783 |
|
784 |
-
{'
|
785 |
-
{'
|
786 |
|
787 |
"""
|
788 |
|
789 |
-
# Add summary box
|
790 |
if passed:
|
791 |
-
feedback_content += """
|
792 |
---
|
793 |
-
|
794 |
-
You passed
|
795 |
"""
|
796 |
else:
|
797 |
-
feedback_content += """
|
798 |
---
|
799 |
-
|
800 |
-
You need 80% or higher to pass.
|
|
|
801 |
"""
|
802 |
|
803 |
return [
|
804 |
-
|
805 |
-
gr.update(visible=True),
|
806 |
-
score,
|
807 |
"🎉 Passed!" if passed else "Please try again", # result_message
|
808 |
-
gr.update(visible=False),
|
809 |
-
gr.update(visible=not passed),
|
810 |
-
gr.update(visible=passed),
|
811 |
-
gr.update(visible=True),
|
812 |
-
gr.update(visible=False)
|
813 |
-
]
|
814 |
# Event Handlers
|
815 |
generate_btn.click(
|
816 |
fn=on_generate_questions,
|
|
|
750 |
return gr.Tabs(selected=2)
|
751 |
|
752 |
def on_submit(questions, answers, current_idx, current_answer):
|
753 |
+
"""Handle quiz submission with proper Markdown rendering"""
|
754 |
final_answers = list(answers)
|
755 |
if 0 <= current_idx < len(final_answers):
|
756 |
final_answers[current_idx] = current_answer
|
757 |
|
758 |
if not all(a is not None for a in final_answers[:len(questions)]):
|
759 |
return [
|
760 |
+
"⚠️ Please answer all questions before submitting.",
|
761 |
gr.update(visible=True),
|
762 |
0,
|
763 |
"",
|
|
|
770 |
|
771 |
score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
|
772 |
|
773 |
+
# Create feedback content using pure Markdown
|
774 |
feedback_content = f"""# Assessment Results
|
775 |
|
776 |
+
Score: {score:.1f}%
|
777 |
|
778 |
"""
|
779 |
|
|
|
781 |
feedback_content += f"""### Question {i+1}
|
782 |
{q.question}
|
783 |
|
784 |
+
{':white_check_mark:' if f.is_correct else ':x:'} Your answer: {f.selected or 'No answer'}
|
785 |
+
{'' if f.is_correct else f'Correct answer: {f.correct_answer}'}
|
786 |
|
787 |
"""
|
788 |
|
789 |
+
# Add summary box using pure Markdown
|
790 |
if passed:
|
791 |
+
feedback_content += f"""
|
792 |
---
|
793 |
+
# 🎉 Congratulations!
|
794 |
+
You passed with a score of {score:.1f}%!
|
795 |
"""
|
796 |
else:
|
797 |
+
feedback_content += f"""
|
798 |
---
|
799 |
+
# Need to improve
|
800 |
+
You scored {score:.1f}%. You need 80% or higher to pass.
|
801 |
+
Please try again.
|
802 |
"""
|
803 |
|
804 |
return [
|
805 |
+
feedback_content, # feedback_box
|
806 |
+
gr.update(visible=True), # results_group
|
807 |
+
score, # score_display
|
808 |
"🎉 Passed!" if passed else "Please try again", # result_message
|
809 |
+
gr.update(visible=False), # question_box
|
810 |
+
gr.update(visible=not passed), # reset_btn
|
811 |
+
gr.update(visible=passed), # view_cert_btn
|
812 |
+
gr.update(visible=True), # back_to_assessment
|
813 |
+
gr.update(visible=False) # profile_tab
|
814 |
+
]
|
815 |
# Event Handlers
|
816 |
generate_btn.click(
|
817 |
fn=on_generate_questions,
|