Spaces:
Runtime error
Runtime error
File size: 6,589 Bytes
7841f4b c159f38 7841f4b f750fb3 7841f4b 011d04c 7841f4b c159f38 7841f4b c159f38 7841f4b 011d04c a950117 7841f4b c159f38 78a9928 c159f38 78a9928 dedb6f7 7841f4b e3fc795 7841f4b 78a9928 e3fc795 011d04c e3fc795 871b739 e3fc795 871b739 e3fc795 dedb6f7 c159f38 e3fc795 fd1c999 011d04c beaa562 c159f38 011d04c c159f38 9b5aafc dedb6f7 c159f38 dedb6f7 c159f38 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | import gradio as gr
import json
import os
import random
# -------------------------
# Quiz data
# -------------------------
quiz_questions = [
{
"question": "In our study, we applied a magnetic encapsulation technique. What primary physical phenomenon does this technique aim to suppress?",
"options": ["Taylor-Couette Instability", "Kelvin-Helmholtz Instability", "Rayleigh–Plateau Instability (RPI)", "Marangoni Effect"],
"answer": "Rayleigh–Plateau Instability (RPI)",
"hint": "Think about the instability that makes a stream of falling water break into droplets.",
"explanation": "✅ Correct! The Rayleigh–Plateau Instability causes liquid jets to break into droplets. Magnetic encapsulation stabilizes the flow, preventing this breakup."
},
{
"question": "According to the study's stability analysis, what condition must the magnetic Bond number (Bom) satisfy to keep the liquid-liquid interface stable?",
"options": ["Bom ≈ 0", "Bom < 1", "Bom = 1", "Bom > 1"],
"answer": "Bom > 1",
"hint": "Stability is achieved when stabilizing magnetic forces overcome destabilizing surface tension forces.",
"explanation": "✅ Correct! The interface remains stable when magnetic forces are stronger than surface tension, so Bom > 1."
},
{
"question": "The study shows that a stable flow can be switched to an unstable one using an external trigger. How is this achieved?",
"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"],
"answer": "By locally heating the ferrofluid with light irradiation",
"hint": "The instability occurs when the stabilizing magnetic force is weakened. Think about a property of the ferrofluid that can be externally altered.",
"explanation": "✅ Correct! Local heating of the ferrofluid reduces its magnetic susceptibility, weakening the stabilizing magnetic force and triggering instability."
},
{
"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?",
"options": ["τ(k) must be negative", "τ(k) must be positive", "τ(k) must be a complex number", "τ(k) must be equal to zero"],
"answer": "τ(k) must be negative",
"hint": "Consider whether a small ripple on the interface should grow or shrink for the jet to remain stable.",
"explanation": "✅ Correct! A negative growth rate means any small perturbation decays over time, keeping the interface stable."
},
{
"question": "What is a significant advantage of the magnetic confinement method over conventional techniques like flow focusing, especially at very low flow rates?",
"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"],
"answer": "It completely eliminates the dripping failure mode at static or near-static conditions",
"hint": "Think about what happens to a dripping tap when the flow is extremely slow.",
"explanation": "✅ Correct! Magnetic confinement stabilizes the liquid-liquid interface even at near-static conditions, preventing the usual dripping failure seen in conventional flow focusing."
}
]
# -------------------------
# Visitor counter
# -------------------------
COUNTER_FILE = "/tmp/counters.json" # Works both locally and in Hugging Face
def load_counters():
if os.path.exists(COUNTER_FILE):
with open(COUNTER_FILE, "r") as f:
try:
return json.load(f)
except json.JSONDecodeError:
return {"visitors": 0}
else:
counters = {"visitors": 0}
with open(COUNTER_FILE, "w") as f:
json.dump(counters, f)
return counters
def save_counters(counters):
with open(COUNTER_FILE, "w") as f:
json.dump(counters, f)
# Increment visitor count on each new user session
session_id = str(random.randint(100000, 999999))
counters = load_counters()
# To ensure it increments once per user, simulate a new visitor each reload
if session_id not in counters:
counters["visitors"] += 1
counters[session_id] = True
save_counters(counters)
# -------------------------
# Score tracking
# -------------------------
score = [0]
def check_answer(question_index, selected_option):
question = quiz_questions[question_index]
if selected_option == question["answer"]:
score[0] += 1
feedback = f"✅ Correct!\n\n{question['explanation']}"
else:
feedback = f"❌ Incorrect.\n\n{question['explanation']}"
if question_index == len(quiz_questions) - 1:
feedback += f"\n\n🎯 Your total score: {score[0]}/{len(quiz_questions)}"
feedback += "\n\n📘 Reference: A. A. Dev, G. Bagheri, E. Bodenschatz, T. M. Hermans, and B. Doudin, “Suppression of Interfacial Instability of Immiscible Liquid-in-Liquid Flow Using Magnetic Forces.” *Adv. Sci.* (2025): e10327. https://doi.org/10.1002/advs.202510327"
return feedback
def show_hint(question_index):
return quiz_questions[question_index]["hint"]
# -------------------------
# Build interface
# -------------------------
def create_question_block(i, q):
with gr.Blocks() as block:
gr.Markdown(f"### Question {i+1}: {q['question']}")
options_dropdown = gr.Radio(q["options"], label="Select your answer")
output = gr.Markdown("")
gr.Markdown(f"👥 Visitors: {counters['visitors']}")
with gr.Row():
gr.Button("Submit Answer").click(fn=lambda x: check_answer(i, x), inputs=options_dropdown, outputs=output)
gr.Button("Show Hint").click(fn=lambda: show_hint(i), inputs=None, outputs=output)
return block
# -------------------------
# Quiz interface
# -------------------------
question_blocks = [create_question_block(i, q) for i, q in enumerate(quiz_questions)]
quiz_interface = gr.TabbedInterface(question_blocks, ["Q1", "Q2", "Q3", "Q4", "Q5"])
# Launch
quiz_interface.launch()
|