Spaces:
Running
Running
capradeepgujaran
commited on
Commit
•
ffcc3a1
1
Parent(s):
52e9564
Update app.py
Browse files
app.py
CHANGED
@@ -963,70 +963,77 @@ def create_quiz_interface():
|
|
963 |
return navigate(1, current_idx, questions, answers, current_answer)
|
964 |
|
965 |
def on_submit(questions, answers, current_idx, current_answer):
|
966 |
-
"""Handle quiz submission with proper
|
967 |
final_answers = list(answers)
|
968 |
if 0 <= current_idx < len(final_answers):
|
969 |
final_answers[current_idx] = current_answer
|
970 |
|
971 |
if not all(a is not None for a in final_answers[:len(questions)]):
|
|
|
972 |
unanswered = [i+1 for i, a in enumerate(final_answers[:len(questions)]) if a is None]
|
973 |
-
|
974 |
<div style="background-color: #fff3cd; padding: 20px; border-radius: 10px; border-left: 5px solid #ffa000;">
|
975 |
-
<h3 style="color: #ff6b6b; margin: 0;">⚠️ Please
|
976 |
-
<p style="margin: 10px 0;">Questions
|
977 |
-
<p style="margin: 0;">Please complete all questions before submitting.</p>
|
978 |
</div>
|
979 |
"""
|
980 |
return [
|
981 |
-
|
982 |
-
gr.update(visible=True),
|
983 |
-
0,
|
984 |
-
"
|
985 |
-
gr.update(visible=True),
|
986 |
-
gr.update(visible=
|
987 |
-
gr.update(visible=False),
|
988 |
-
gr.update(selected=2)
|
989 |
]
|
990 |
|
991 |
score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
|
992 |
|
993 |
-
# Create
|
994 |
-
feedback_content = ""
|
|
|
|
|
|
|
|
|
995 |
|
996 |
for i, (q, f) in enumerate(zip(questions, feedback)):
|
997 |
-
if
|
998 |
-
|
999 |
-
else:
|
1000 |
-
feedback_content += f"### Question {i+1}\n{q.question}\n\n"
|
1001 |
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
|
|
|
|
|
|
1007 |
|
1008 |
-
# Add
|
1009 |
if passed:
|
1010 |
feedback_content += f"""
|
|
|
1011 |
## 🎉 Congratulations!
|
1012 |
You passed with a score of {score:.1f}%!
|
1013 |
"""
|
1014 |
else:
|
1015 |
feedback_content += f"""
|
|
|
1016 |
## Need Improvement
|
1017 |
You scored {score:.1f}%. You need 80% or higher to pass.
|
1018 |
Please try again.
|
1019 |
"""
|
1020 |
|
1021 |
return [
|
1022 |
-
feedback_content,
|
1023 |
-
gr.update(visible=True),
|
1024 |
-
score,
|
1025 |
-
f"Score: {score:.1f}%",
|
1026 |
-
gr.update(visible=False),
|
1027 |
-
gr.update(visible=not passed),
|
1028 |
-
gr.update(visible=passed),
|
1029 |
-
gr.update(selected=2)
|
1030 |
]
|
1031 |
# Event Handlers
|
1032 |
generate_btn.click(
|
|
|
963 |
return navigate(1, current_idx, questions, answers, current_answer)
|
964 |
|
965 |
def on_submit(questions, answers, current_idx, current_answer):
|
966 |
+
"""Handle quiz submission with proper Markdown rendering and emojis"""
|
967 |
final_answers = list(answers)
|
968 |
if 0 <= current_idx < len(final_answers):
|
969 |
final_answers[current_idx] = current_answer
|
970 |
|
971 |
if not all(a is not None for a in final_answers[:len(questions)]):
|
972 |
+
# Create list of unanswered question numbers
|
973 |
unanswered = [i+1 for i, a in enumerate(final_answers[:len(questions)]) if a is None]
|
974 |
+
warning_content = f"""
|
975 |
<div style="background-color: #fff3cd; padding: 20px; border-radius: 10px; border-left: 5px solid #ffa000;">
|
976 |
+
<h3 style="color: #ff6b6b; margin: 0;">⚠️ Please Complete All Questions</h3>
|
977 |
+
<p style="margin: 10px 0;">Unanswered Questions: {', '.join(map(str, unanswered))}</p>
|
|
|
978 |
</div>
|
979 |
"""
|
980 |
return [
|
981 |
+
warning_content, # feedback_box
|
982 |
+
gr.update(visible=True), # results_group
|
983 |
+
0, # score
|
984 |
+
"", # result_message
|
985 |
+
gr.update(visible=True), # question_box
|
986 |
+
gr.update(visible=True), # reset_btn
|
987 |
+
gr.update(visible=False), # view_cert_btn
|
988 |
+
gr.update(selected=2) # tabs
|
989 |
]
|
990 |
|
991 |
score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
|
992 |
|
993 |
+
# Create feedback content using proper Markdown with emojis
|
994 |
+
feedback_content = f"""# Assessment Results
|
995 |
+
|
996 |
+
**Score: {score:.1f}%**
|
997 |
+
|
998 |
+
"""
|
999 |
|
1000 |
for i, (q, f) in enumerate(zip(questions, feedback)):
|
1001 |
+
icon = "✅" if f.is_correct else "❌"
|
1002 |
+
color = "green" if f.is_correct else "red"
|
|
|
|
|
1003 |
|
1004 |
+
# Using markdown syntax with color formatting
|
1005 |
+
feedback_content += f"""### Question {i+1}
|
1006 |
+
{q.question}
|
1007 |
+
|
1008 |
+
{icon} **Your answer:** {f.selected or 'No answer'}
|
1009 |
+
{'' if f.is_correct else f'**Correct answer:** {f.correct_answer}'}
|
1010 |
+
|
1011 |
+
"""
|
1012 |
|
1013 |
+
# Add summary box
|
1014 |
if passed:
|
1015 |
feedback_content += f"""
|
1016 |
+
---
|
1017 |
## 🎉 Congratulations!
|
1018 |
You passed with a score of {score:.1f}%!
|
1019 |
"""
|
1020 |
else:
|
1021 |
feedback_content += f"""
|
1022 |
+
---
|
1023 |
## Need Improvement
|
1024 |
You scored {score:.1f}%. You need 80% or higher to pass.
|
1025 |
Please try again.
|
1026 |
"""
|
1027 |
|
1028 |
return [
|
1029 |
+
feedback_content, # feedback_box
|
1030 |
+
gr.update(visible=True), # results_group
|
1031 |
+
score, # score_display
|
1032 |
+
f"Score: {score:.1f}%", # result_message
|
1033 |
+
gr.update(visible=False), # question_box
|
1034 |
+
gr.update(visible=not passed), # reset_btn
|
1035 |
+
gr.update(visible=passed), # view_cert_btn
|
1036 |
+
gr.update(selected=2) # tabs
|
1037 |
]
|
1038 |
# Event Handlers
|
1039 |
generate_btn.click(
|