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
import gradio as gr
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# -------------------------
|
| 6 |
+
# Quiz Data
|
| 7 |
+
# -------------------------
|
| 8 |
+
quiz_questions = [
|
| 9 |
+
{
|
| 10 |
+
"question": "In our study, we applied a magnetic encapsulation technique. What primary physical phenomenon does this technique aim to suppress?",
|
| 11 |
+
"options": ["Taylor-Couette Instability", "Kelvin-Helmholtz Instability", "Rayleigh–Plateau Instability (RPI)", "Marangoni Effect"],
|
| 12 |
+
"answer": "Rayleigh–Plateau Instability (RPI)",
|
| 13 |
+
"hint": "Think about the instability that makes a stream of falling water break into droplets.",
|
| 14 |
+
"explanation": "✅ Correct! The Rayleigh–Plateau Instability causes liquid jets to break into droplets. Magnetic encapsulation stabilizes the flow, preventing this breakup."
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"question": "According to the study's stability analysis, what condition must the magnetic Bond number (Bom) satisfy to keep the liquid-liquid interface stable?",
|
| 18 |
+
"options": ["Bom ≈ 0", "Bom < 1", "Bom = 1", "Bom > 1"],
|
| 19 |
+
"answer": "Bom > 1",
|
| 20 |
+
"hint": "Stability is achieved when stabilizing magnetic forces overcome destabilizing surface tension forces.",
|
| 21 |
+
"explanation": "✅ Correct! The interface remains stable when magnetic forces are stronger than surface tension, so Bom > 1."
|
| 22 |
+
},
|
| 23 |
+
{
|
| 24 |
+
"question": "The study shows that a stable flow can be switched to an unstable one using an external trigger. How is this achieved?",
|
| 25 |
+
"options": ["By locally heating the ferrofluid with light irradiation", "By rapidly increasing the flow rate of the inner liquid", "By adding a surfactant to the inner glycerol liquid", "By turning off the external magnets completely"],
|
| 26 |
+
"answer": "By locally heating the ferrofluid with light irradiation",
|
| 27 |
+
"hint": "The instability occurs when the stabilizing magnetic force is weakened. Think about a property of the ferrofluid that can be externally altered.",
|
| 28 |
+
"explanation": "✅ Correct! Local heating of the ferrofluid reduces its magnetic susceptibility, weakening the stabilizing magnetic force and triggering instability."
|
| 29 |
+
},
|
| 30 |
+
{
|
| 31 |
+
"question": "For the liquid-liquid interface to remain stable, what must be true about the growth rate of perturbations, τ(k), for all perturbation wave numbers k?",
|
| 32 |
+
"options": ["τ(k) must be negative", "τ(k) must be positive", "τ(k) must be a complex number", "τ(k) must be equal to zero"],
|
| 33 |
+
"answer": "τ(k) must be negative",
|
| 34 |
+
"hint": "Consider whether a small ripple on the interface should grow or shrink for the jet to remain stable.",
|
| 35 |
+
"explanation": "✅ Correct! A negative growth rate means any small perturbation decays over time, keeping the interface stable."
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"question": "What is a significant advantage of the magnetic confinement method over conventional techniques like flow focusing, especially at very low flow rates?",
|
| 39 |
+
"options": ["It requires a continuous and high-velocity flow of the outer sheath liquid", "It can only function at extremely high Reynolds numbers", "It completely eliminates the dripping failure mode at static or near-static conditions", "It is only stable for a very short axial length"],
|
| 40 |
+
"answer": "It completely eliminates the dripping failure mode at static or near-static conditions",
|
| 41 |
+
"hint": "Think about what happens to a dripping tap when the flow is extremely slow.",
|
| 42 |
+
"explanation": "✅ Correct! Magnetic confinement stabilizes the liquid-liquid interface even at near-static conditions, preventing the usual dripping failure seen in conventional flow focusing."
|
| 43 |
+
}
|
| 44 |
+
]
|
| 45 |
+
|
| 46 |
+
# -------------------------
|
| 47 |
+
# Counters
|
| 48 |
+
# -------------------------
|
| 49 |
+
COUNTER_FILE = "counters.json"
|
| 50 |
+
|
| 51 |
+
def load_counters():
|
| 52 |
+
if os.path.exists(COUNTER_FILE):
|
| 53 |
+
with open(COUNTER_FILE, "r") as f:
|
| 54 |
+
return json.load(f)
|
| 55 |
+
else:
|
| 56 |
+
return {"visitors": 0, "completions": 0}
|
| 57 |
+
|
| 58 |
+
def save_counters(counters):
|
| 59 |
+
with open(COUNTER_FILE, "w") as f:
|
| 60 |
+
json.dump(counters, f)
|
| 61 |
+
|
| 62 |
+
# Increment visitor count on page load
|
| 63 |
+
counters = load_counters()
|
| 64 |
+
counters["visitors"] += 1
|
| 65 |
+
save_counters(counters)
|
| 66 |
+
|
| 67 |
+
# -------------------------
|
| 68 |
+
# Quiz Functions
|
| 69 |
+
# -------------------------
|
| 70 |
+
def submit_answer(selected, q_index, score):
|
| 71 |
+
"""Process answer and move to next question or show final score."""
|
| 72 |
+
if selected is None:
|
| 73 |
+
return "Please select an answer before submitting.", gr.update(choices=quiz_questions[q_index]["options"], value=None), "", score, q_index, counters["visitors"], counters["completions"]
|
| 74 |
+
|
| 75 |
+
question = quiz_questions[q_index]
|
| 76 |
+
explanation = ""
|
| 77 |
+
|
| 78 |
+
if selected == question["answer"]:
|
| 79 |
+
score += 1
|
| 80 |
+
explanation = f"✅ Correct!\n\n{question['explanation']}"
|
| 81 |
+
else:
|
| 82 |
+
explanation = f"❌ Incorrect.\n\n{question['explanation']}"
|
| 83 |
+
|
| 84 |
+
next_index = q_index + 1
|
| 85 |
+
counters = load_counters()
|
| 86 |
+
|
| 87 |
+
if next_index >= len(quiz_questions):
|
| 88 |
+
# Quiz completed → update completion counter
|
| 89 |
+
counters["completions"] += 1
|
| 90 |
+
save_counters(counters)
|
| 91 |
+
return (
|
| 92 |
+
"🎉 Quiz Completed!",
|
| 93 |
+
gr.update(choices=[], value=None),
|
| 94 |
+
explanation + f"\n\n**Your Score: {score}/{len(quiz_questions)}**",
|
| 95 |
+
score,
|
| 96 |
+
next_index,
|
| 97 |
+
counters["visitors"],
|
| 98 |
+
counters["completions"]
|
| 99 |
+
)
|
| 100 |
+
else:
|
| 101 |
+
next_question = quiz_questions[next_index]
|
| 102 |
+
return (
|
| 103 |
+
f"### Question {next_index+1}: {next_question['question']}",
|
| 104 |
+
gr.update(choices=next_question["options"], value=None),
|
| 105 |
+
explanation,
|
| 106 |
+
score,
|
| 107 |
+
next_index,
|
| 108 |
+
counters["visitors"],
|
| 109 |
+
counters["completions"]
|
| 110 |
+
)
|
| 111 |
+
|
| 112 |
+
def show_hint(q_index):
|
| 113 |
+
return f"💡 Hint: {quiz_questions[q_index]['hint']}"
|
| 114 |
+
|
| 115 |
+
# -------------------------
|
| 116 |
+
# Build Gradio Interface
|
| 117 |
+
# -------------------------
|
| 118 |
+
with gr.Blocks() as quiz_app:
|
| 119 |
+
gr.Markdown("# 🧪 Magnetic Flow Quiz")
|
| 120 |
+
|
| 121 |
+
# Counters
|
| 122 |
+
visitor_md = gr.Markdown(f"👥 Visitors: {counters['visitors']}")
|
| 123 |
+
completion_md = gr.Markdown(f"✅ Completions: {counters['completions']}")
|
| 124 |
+
|
| 125 |
+
# Quiz area
|
| 126 |
+
question_md = gr.Markdown(f"### Question 1: {quiz_questions[0]['question']}")
|
| 127 |
+
options_radio = gr.Radio(quiz_questions[0]["options"], label="Select your answer")
|
| 128 |
+
output_md = gr.Markdown("")
|
| 129 |
+
|
| 130 |
+
# Buttons
|
| 131 |
+
with gr.Row():
|
| 132 |
+
submit_btn = gr.Button("Submit Answer")
|
| 133 |
+
hint_btn = gr.Button("Show Hint")
|
| 134 |
+
|
| 135 |
+
# Hidden states to track progress
|
| 136 |
+
score_state = gr.State(0)
|
| 137 |
+
q_index_state = gr.State(0)
|
| 138 |
+
|
| 139 |
+
# Button interactions
|
| 140 |
+
submit_btn.click(
|
| 141 |
+
fn=submit_answer,
|
| 142 |
+
inputs=[options_radio, q_index_state, score_state],
|
| 143 |
+
outputs=[question_md, options_radio, output_md, score_state, q_index_state, visitor_md, completion_md]
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
hint_btn.click(
|
| 147 |
+
fn=show_hint,
|
| 148 |
+
inputs=q_index_state,
|
| 149 |
+
outputs=output_md
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
# Launch app
|
| 153 |
+
quiz_app.launch()
|
counters.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"visitors": 0,
|
| 3 |
+
"completions": 0
|
| 4 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio
|