Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,25 @@
|
|
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 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
def check_answer(choice):
|
19 |
if current_question is None:
|
@@ -46,9 +52,12 @@ with gr.Blocks() as demo:
|
|
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)
|
|
|
1 |
import gradio as gr
|
2 |
from question_generator import generate_microbiology_question
|
3 |
+
import logging
|
4 |
|
5 |
current_question = None
|
6 |
|
7 |
def generate_question():
|
8 |
global current_question
|
9 |
+
try:
|
10 |
+
current_question = generate_microbiology_question()
|
11 |
+
return (
|
12 |
+
current_question['question'],
|
13 |
+
current_question['options']['A'],
|
14 |
+
current_question['options']['B'],
|
15 |
+
current_question['options']['C'],
|
16 |
+
current_question['options']['D'],
|
17 |
+
current_question['options']['E'],
|
18 |
+
"" # Clear any previous error messages
|
19 |
+
)
|
20 |
+
except Exception as e:
|
21 |
+
logging.error(f"Error generating question: {e}")
|
22 |
+
return ("Error generating question. Please try again.", "", "", "", "", "", str(e))
|
23 |
|
24 |
def check_answer(choice):
|
25 |
if current_question is None:
|
|
|
52 |
with gr.Row():
|
53 |
result = gr.Textbox(label="Result", lines=10)
|
54 |
|
55 |
+
with gr.Row():
|
56 |
+
error_message = gr.Textbox(label="Error", lines=2)
|
57 |
+
|
58 |
generate_btn.click(
|
59 |
generate_question,
|
60 |
+
outputs=[question_text, option_a, option_b, option_c, option_d, option_e, error_message]
|
61 |
)
|
62 |
|
63 |
option_a.click(lambda: check_answer("A"), outputs=result)
|