Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -923,54 +923,48 @@ def create_quiz_interface():
|
|
| 923 |
if 0 <= current_idx < len(final_answers):
|
| 924 |
final_answers[current_idx] = current_answer
|
| 925 |
|
|
|
|
| 926 |
if not all(a is not None for a in final_answers[:len(questions)]):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 927 |
return [
|
| 928 |
-
|
| 929 |
-
gr.update(visible=True),
|
| 930 |
-
0,
|
| 931 |
-
"",
|
| 932 |
-
gr.update(visible=True),
|
| 933 |
-
gr.update(visible=True),
|
| 934 |
-
gr.update(visible=False),
|
| 935 |
-
gr.update(
|
| 936 |
]
|
| 937 |
-
|
| 938 |
-
score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
|
| 939 |
-
|
| 940 |
-
# Create feedback content using proper Markdown with emojis
|
| 941 |
-
feedback_content = f"""# Assessment Results
|
| 942 |
-
|
| 943 |
-
**Score: {score:.1f}%**
|
| 944 |
|
| 945 |
-
|
|
|
|
|
|
|
| 946 |
|
| 947 |
for i, (q, f) in enumerate(zip(questions, feedback)):
|
| 948 |
icon = "✅" if f.is_correct else "❌"
|
| 949 |
color = "green" if f.is_correct else "red"
|
| 950 |
-
|
| 951 |
-
# Using markdown syntax with color formatting
|
| 952 |
feedback_content += f"""### Question {i+1}
|
| 953 |
-
|
| 954 |
-
|
| 955 |
-
|
| 956 |
-
{'' if f.is_correct else f'**Correct answer:** {f.correct_answer}'}
|
| 957 |
-
|
| 958 |
-
"""
|
| 959 |
|
| 960 |
-
# Add summary box
|
| 961 |
if passed:
|
| 962 |
-
feedback_content += f"""
|
| 963 |
-
---
|
| 964 |
-
## 🎉 Congratulations!
|
| 965 |
-
You passed with a score of {score:.1f}%!
|
| 966 |
-
"""
|
| 967 |
else:
|
| 968 |
-
feedback_content += f"""
|
| 969 |
-
---
|
| 970 |
-
## Need Improvement
|
| 971 |
-
You scored {score:.1f}%. You need 80% or higher to pass.
|
| 972 |
-
Please try again.
|
| 973 |
-
"""
|
| 974 |
|
| 975 |
return [
|
| 976 |
feedback_content, # feedback_box
|
|
|
|
| 923 |
if 0 <= current_idx < len(final_answers):
|
| 924 |
final_answers[current_idx] = current_answer
|
| 925 |
|
| 926 |
+
# Check for unanswered questions
|
| 927 |
if not all(a is not None for a in final_answers[:len(questions)]):
|
| 928 |
+
# Find unanswered question numbers
|
| 929 |
+
unanswered = [i+1 for i, a in enumerate(final_answers[:len(questions)]) if a is None]
|
| 930 |
+
warning_content = f"""
|
| 931 |
+
<div style="background-color: #fff3cd; padding: 20px; border-radius: 8px; border: 1px solid #ffeeba; margin: 10px 0;">
|
| 932 |
+
<div style="display: flex; align-items: center; margin-bottom: 10px;">
|
| 933 |
+
<span style="font-size: 24px; margin-right: 10px;">⚠️</span>
|
| 934 |
+
<h3 style="color: #856404; margin: 0;">Please Complete All Questions</h3>
|
| 935 |
+
</div>
|
| 936 |
+
<p style="color: #856404; margin: 10px 0;">The following questions are unanswered:</p>
|
| 937 |
+
<p style="color: #856404; font-weight: bold; margin: 5px 0;">Question(s) {', '.join(map(str, unanswered))}</p>
|
| 938 |
+
<p style="color: #856404; margin: 10px 0;">Please answer all questions before submitting.</p>
|
| 939 |
+
</div>
|
| 940 |
+
"""
|
| 941 |
return [
|
| 942 |
+
warning_content, # feedback_box
|
| 943 |
+
gr.update(visible=True), # results_group
|
| 944 |
+
0, # score
|
| 945 |
+
"⚠️ Incomplete Submission", # result_message
|
| 946 |
+
gr.update(visible=True), # question_box
|
| 947 |
+
gr.update(visible=True), # reset_btn
|
| 948 |
+
gr.update(visible=False), # view_cert_btn
|
| 949 |
+
gr.update(selected=2) # tabs
|
| 950 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 951 |
|
| 952 |
+
# Rest of the original function remains the same...
|
| 953 |
+
score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
|
| 954 |
+
feedback_content = f"""# Assessment Results\n\n**Score: {score:.1f}%**\n\n"""
|
| 955 |
|
| 956 |
for i, (q, f) in enumerate(zip(questions, feedback)):
|
| 957 |
icon = "✅" if f.is_correct else "❌"
|
| 958 |
color = "green" if f.is_correct else "red"
|
|
|
|
|
|
|
| 959 |
feedback_content += f"""### Question {i+1}
|
| 960 |
+
{q.question}\n
|
| 961 |
+
{icon} **Your answer:** {f.selected or 'No answer'}
|
| 962 |
+
{'' if f.is_correct else f'**Correct answer:** {f.correct_answer}'}\n\n"""
|
|
|
|
|
|
|
|
|
|
| 963 |
|
|
|
|
| 964 |
if passed:
|
| 965 |
+
feedback_content += f"""\n---\n## 🎉 Congratulations!\nYou passed with a score of {score:.1f}%!"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 966 |
else:
|
| 967 |
+
feedback_content += f"""\n---\n## Need Improvement\nYou scored {score:.1f}%. You need 80% or higher to pass.\nPlease try again."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 968 |
|
| 969 |
return [
|
| 970 |
feedback_content, # feedback_box
|