Arvind-Science123 commited on
Commit
b1a7ca5
Β·
verified Β·
1 Parent(s): 507a6d5

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -15
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 encouragement + citation per mark
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 + paragraph + citation
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(f"πŸ‘₯ Visitors: {counters['visitors']}")
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)