Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from question_generator import generate_microbiology_question
|
3 |
+
|
4 |
+
current_question = None
|
5 |
+
|
6 |
+
def generate_question():
|
7 |
+
global current_question
|
8 |
+
current_question = generate_microbiology_question()
|
9 |
+
return (
|
10 |
+
current_question['question'],
|
11 |
+
current_question['options']['A'],
|
12 |
+
current_question['options']['B'],
|
13 |
+
current_question['options']['C'],
|
14 |
+
current_question['options']['D'],
|
15 |
+
current_question['options']['E'],
|
16 |
+
)
|
17 |
+
|
18 |
+
def check_answer(choice):
|
19 |
+
if current_question is None:
|
20 |
+
return "Please generate a question first."
|
21 |
+
|
22 |
+
correct = current_question['correct_answer']
|
23 |
+
if choice == correct:
|
24 |
+
result = "Correct!"
|
25 |
+
else:
|
26 |
+
result = f"Incorrect. The correct answer is {correct}."
|
27 |
+
|
28 |
+
return f"{result}\n\nExplanation: {current_question['explanation']}\n\nMedical Reasoning: {current_question['medical_reasoning']}"
|
29 |
+
|
30 |
+
with gr.Blocks() as demo:
|
31 |
+
gr.Markdown("# Microbiology NBME Question Generator")
|
32 |
+
|
33 |
+
with gr.Row():
|
34 |
+
generate_btn = gr.Button("Generate Question")
|
35 |
+
|
36 |
+
with gr.Row():
|
37 |
+
question_text = gr.Textbox(label="Question", lines=4)
|
38 |
+
|
39 |
+
with gr.Row():
|
40 |
+
option_a = gr.Button("A")
|
41 |
+
option_b = gr.Button("B")
|
42 |
+
option_c = gr.Button("C")
|
43 |
+
option_d = gr.Button("D")
|
44 |
+
option_e = gr.Button("E")
|
45 |
+
|
46 |
+
with gr.Row():
|
47 |
+
result = gr.Textbox(label="Result", lines=10)
|
48 |
+
|
49 |
+
generate_btn.click(
|
50 |
+
generate_question,
|
51 |
+
outputs=[question_text, option_a, option_b, option_c, option_d, option_e]
|
52 |
+
)
|
53 |
+
|
54 |
+
option_a.click(lambda: check_answer("A"), outputs=result)
|
55 |
+
option_b.click(lambda: check_answer("B"), outputs=result)
|
56 |
+
option_c.click(lambda: check_answer("C"), outputs=result)
|
57 |
+
option_d.click(lambda: check_answer("D"), outputs=result)
|
58 |
+
option_e.click(lambda: check_answer("E"), outputs=result)
|
59 |
+
|
60 |
+
if __name__ == "__main__":
|
61 |
+
demo.launch()
|