Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -862,15 +862,6 @@ def create_quiz_interface():
|
|
862 |
)
|
863 |
certificate_display = gr.Image(label="Your Certificate")
|
864 |
|
865 |
-
|
866 |
-
def clear_content():
|
867 |
-
quiz_app.clear_learning_content()
|
868 |
-
return gr.update(value="")
|
869 |
-
|
870 |
-
clear_btn.click(
|
871 |
-
fn=clear_content,
|
872 |
-
outputs=[text_input]
|
873 |
-
)
|
874 |
|
875 |
def show_certificate_tab():
|
876 |
return [
|
@@ -977,32 +968,37 @@ def create_quiz_interface():
|
|
977 |
if 0 <= current_idx < len(final_answers):
|
978 |
final_answers[current_idx] = current_answer
|
979 |
|
|
|
980 |
if not all(a is not None for a in final_answers[:len(questions)]):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
981 |
return [
|
982 |
-
|
983 |
-
gr.update(visible=True),
|
984 |
-
0,
|
985 |
-
"",
|
986 |
-
gr.update(visible=True),
|
987 |
-
gr.update(visible=
|
988 |
-
gr.update(visible=False),
|
989 |
-
gr.update(
|
990 |
]
|
991 |
|
|
|
992 |
score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
|
993 |
|
994 |
-
|
995 |
-
feedback_content = f"""# Assessment Results
|
996 |
-
|
997 |
-
**Score: {score:.1f}%**
|
998 |
-
|
999 |
-
"""
|
1000 |
|
1001 |
for i, (q, f) in enumerate(zip(questions, feedback)):
|
1002 |
icon = "✅" if f.is_correct else "❌"
|
1003 |
color = "green" if f.is_correct else "red"
|
1004 |
|
1005 |
-
# Using markdown syntax with color formatting
|
1006 |
feedback_content += f"""### Question {i+1}
|
1007 |
{q.question}
|
1008 |
|
@@ -1036,7 +1032,6 @@ def create_quiz_interface():
|
|
1036 |
gr.update(visible=passed), # view_cert_btn
|
1037 |
gr.update(selected=2) # tabs
|
1038 |
]
|
1039 |
-
|
1040 |
# Event Handlers
|
1041 |
generate_btn.click(
|
1042 |
fn=on_generate_questions,
|
|
|
862 |
)
|
863 |
certificate_display = gr.Image(label="Your Certificate")
|
864 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
865 |
|
866 |
def show_certificate_tab():
|
867 |
return [
|
|
|
968 |
if 0 <= current_idx < len(final_answers):
|
969 |
final_answers[current_idx] = current_answer
|
970 |
|
971 |
+
# Check if all questions are answered
|
972 |
if not all(a is not None for a in final_answers[:len(questions)]):
|
973 |
+
# Create list of unanswered question numbers
|
974 |
+
unanswered = [i+1 for i, a in enumerate(final_answers[:len(questions)]) if a is None]
|
975 |
+
message = f"""
|
976 |
+
<div style="background-color: #fff3cd; padding: 20px; border-radius: 10px; border-left: 5px solid #ffa000;">
|
977 |
+
<h3 style="color: #ff6b6b; margin: 0;">⚠️ Please Answer All Questions</h3>
|
978 |
+
<p style="margin: 10px 0;">Questions not answered: {', '.join(map(str, unanswered))}</p>
|
979 |
+
<p style="margin: 0;">Please complete all questions before submitting.</p>
|
980 |
+
</div>
|
981 |
+
"""
|
982 |
return [
|
983 |
+
message, # feedback_box content
|
984 |
+
gr.update(visible=True), # results_group visibility
|
985 |
+
0, # score
|
986 |
+
"⚠️ Please answer all questions", # result_message
|
987 |
+
gr.update(visible=True), # question_box visibility
|
988 |
+
gr.update(visible=False), # reset_btn visibility
|
989 |
+
gr.update(visible=False), # view_cert_btn visibility
|
990 |
+
gr.update(selected=2) # keep on same tab
|
991 |
]
|
992 |
|
993 |
+
# Rest of the submission logic remains the same
|
994 |
score, passed, feedback = quiz_app.calculate_score(final_answers[:len(questions)])
|
995 |
|
996 |
+
feedback_content = f"""# Assessment Results\n\n**Score: {score:.1f}%**\n\n"""
|
|
|
|
|
|
|
|
|
|
|
997 |
|
998 |
for i, (q, f) in enumerate(zip(questions, feedback)):
|
999 |
icon = "✅" if f.is_correct else "❌"
|
1000 |
color = "green" if f.is_correct else "red"
|
1001 |
|
|
|
1002 |
feedback_content += f"""### Question {i+1}
|
1003 |
{q.question}
|
1004 |
|
|
|
1032 |
gr.update(visible=passed), # view_cert_btn
|
1033 |
gr.update(selected=2) # tabs
|
1034 |
]
|
|
|
1035 |
# Event Handlers
|
1036 |
generate_btn.click(
|
1037 |
fn=on_generate_questions,
|