Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -62,11 +62,6 @@ def save_counters(counters):
|
|
| 62 |
with open(COUNTER_FILE, "w") as f:
|
| 63 |
json.dump(counters, f)
|
| 64 |
|
| 65 |
-
# Increment visitor count
|
| 66 |
-
counters = load_counters()
|
| 67 |
-
counters["visitors"] += 1
|
| 68 |
-
save_counters(counters)
|
| 69 |
-
|
| 70 |
# -------------------------
|
| 71 |
# Score tracking
|
| 72 |
# -------------------------
|
|
@@ -85,21 +80,15 @@ def check_answer(question_index, selected_option):
|
|
| 85 |
else:
|
| 86 |
feedback = f"β Incorrect.\n\n{question['explanation']}"
|
| 87 |
|
| 88 |
-
# If last question, show total score with
|
| 89 |
if question_index == len(quiz_questions) - 1:
|
| 90 |
total = score[0]
|
| 91 |
feedback += f"\n\nπ― Your total score: {total}/{len(quiz_questions)}\n\n"
|
| 92 |
|
| 93 |
-
# Positive encouragement for each mark
|
| 94 |
encouragements = ["Well done!", "Great job!", "Awesome!", "Excellent!", "Perfect score! π"]
|
| 95 |
for i in range(total):
|
| 96 |
feedback += f"π Mark {i+1}: {encouragements[i]}\n\n"
|
| 97 |
-
feedback += (
|
| 98 |
-
'See "A. A. Dev, G. Bagheri, E. Bodenschatz, T. M. Hermans, '
|
| 99 |
-
'and B. Doudin, β Suppressing Interfacial Instability of Immiscible '
|
| 100 |
-
'Liquid-in-Liquid Flow Using Magnetic Forces.β Adv. Sci. (2025): e10327. '
|
| 101 |
-
'https://doi.org/10.1002/advs.202510327" for detailed study.\n\n'
|
| 102 |
-
)
|
| 103 |
|
| 104 |
return feedback
|
| 105 |
|
|
@@ -114,8 +103,17 @@ def create_question_block(i, q):
|
|
| 114 |
gr.Markdown(f"### Question {i+1}: {q['question']}")
|
| 115 |
options_dropdown = gr.Radio(q["options"], label="Select your answer")
|
| 116 |
output = gr.Markdown("")
|
| 117 |
-
gr.Markdown(
|
| 118 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
with gr.Row():
|
| 120 |
gr.Button("Submit Answer").click(fn=lambda x: check_answer(i, x), inputs=options_dropdown, outputs=output)
|
| 121 |
gr.Button("Show Hint").click(fn=lambda: show_hint(i), inputs=None, outputs=output)
|
|
|
|
| 62 |
with open(COUNTER_FILE, "w") as f:
|
| 63 |
json.dump(counters, f)
|
| 64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
# -------------------------
|
| 66 |
# Score tracking
|
| 67 |
# -------------------------
|
|
|
|
| 80 |
else:
|
| 81 |
feedback = f"β Incorrect.\n\n{question['explanation']}"
|
| 82 |
|
| 83 |
+
# If last question, show total score with positive encouragement
|
| 84 |
if question_index == len(quiz_questions) - 1:
|
| 85 |
total = score[0]
|
| 86 |
feedback += f"\n\nπ― Your total score: {total}/{len(quiz_questions)}\n\n"
|
| 87 |
|
| 88 |
+
# Positive encouragement for each mark
|
| 89 |
encouragements = ["Well done!", "Great job!", "Awesome!", "Excellent!", "Perfect score! π"]
|
| 90 |
for i in range(total):
|
| 91 |
feedback += f"π Mark {i+1}: {encouragements[i]}\n\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
return feedback
|
| 94 |
|
|
|
|
| 103 |
gr.Markdown(f"### Question {i+1}: {q['question']}")
|
| 104 |
options_dropdown = gr.Radio(q["options"], label="Select your answer")
|
| 105 |
output = gr.Markdown("")
|
| 106 |
+
visitor_md = gr.Markdown("π₯ Visitors: 0")
|
| 107 |
+
|
| 108 |
+
# Increment visitor on page load
|
| 109 |
+
def increment_visitor():
|
| 110 |
+
counters = load_counters()
|
| 111 |
+
counters["visitors"] += 1
|
| 112 |
+
save_counters(counters)
|
| 113 |
+
return f"π₯ Visitors: {counters['visitors']}"
|
| 114 |
+
|
| 115 |
+
visitor_md.load(fn=increment_visitor, inputs=None, outputs=visitor_md)
|
| 116 |
+
|
| 117 |
with gr.Row():
|
| 118 |
gr.Button("Submit Answer").click(fn=lambda x: check_answer(i, x), inputs=options_dropdown, outputs=output)
|
| 119 |
gr.Button("Show Hint").click(fn=lambda: show_hint(i), inputs=None, outputs=output)
|