File size: 1,942 Bytes
a99257b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from question_generator import generate_microbiology_question

current_question = None

def generate_question():
    global current_question
    current_question = generate_microbiology_question()
    return (
        current_question['question'],
        current_question['options']['A'],
        current_question['options']['B'],
        current_question['options']['C'],
        current_question['options']['D'],
        current_question['options']['E'],
    )

def check_answer(choice):
    if current_question is None:
        return "Please generate a question first."
    
    correct = current_question['correct_answer']
    if choice == correct:
        result = "Correct!"
    else:
        result = f"Incorrect. The correct answer is {correct}."
    
    return f"{result}\n\nExplanation: {current_question['explanation']}\n\nMedical Reasoning: {current_question['medical_reasoning']}"

with gr.Blocks() as demo:
    gr.Markdown("# Microbiology NBME Question Generator")
    
    with gr.Row():
        generate_btn = gr.Button("Generate Question")
    
    with gr.Row():
        question_text = gr.Textbox(label="Question", lines=4)
    
    with gr.Row():
        option_a = gr.Button("A")
        option_b = gr.Button("B")
        option_c = gr.Button("C")
        option_d = gr.Button("D")
        option_e = gr.Button("E")
    
    with gr.Row():
        result = gr.Textbox(label="Result", lines=10)
    
    generate_btn.click(
        generate_question,
        outputs=[question_text, option_a, option_b, option_c, option_d, option_e]
    )
    
    option_a.click(lambda: check_answer("A"), outputs=result)
    option_b.click(lambda: check_answer("B"), outputs=result)
    option_c.click(lambda: check_answer("C"), outputs=result)
    option_d.click(lambda: check_answer("D"), outputs=result)
    option_e.click(lambda: check_answer("E"), outputs=result)

if __name__ == "__main__":
    demo.launch()