Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,24 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# functions
|
4 |
-
def check(answers
|
5 |
-
if not all(answers):
|
6 |
-
raise gr.Error("Выберите все ответы!")
|
7 |
-
|
8 |
results = []
|
9 |
-
for i, (answer,
|
|
|
10 |
result = "✔" if answer == correct_answer else "✖️"
|
11 |
results.append(f"{i}: {result}")
|
12 |
|
@@ -18,23 +30,19 @@ footer {visibility: hidden !important;}
|
|
18 |
"""
|
19 |
|
20 |
# ui
|
21 |
-
with gr.Blocks(css=css
|
22 |
question_blocks = []
|
23 |
-
|
24 |
-
for i, correct_answer in enumerate(correct_answers, start=1):
|
25 |
with gr.Row():
|
26 |
with gr.Column():
|
27 |
-
|
28 |
-
question_blocks.append(
|
29 |
|
30 |
text_button = gr.Button("Проверить", variant='primary')
|
31 |
with gr.Tab("Результаты"):
|
32 |
text_output = gr.Markdown("")
|
33 |
|
34 |
-
|
35 |
-
return check(args, correct_answers)
|
36 |
-
|
37 |
-
text_button.click(on_click, inputs=question_blocks, outputs=[text_output], queue=False)
|
38 |
|
39 |
#end
|
40 |
vui.queue(api_open=False).launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import json
|
3 |
+
|
4 |
+
# JSON с вопросами и правильными ответами
|
5 |
+
json_data = """
|
6 |
+
{
|
7 |
+
"questions": [
|
8 |
+
{"text": "Выберите А", "correct_answer": "А"},
|
9 |
+
{"text": "Выберите Б", "correct_answer": "Б"}
|
10 |
+
]
|
11 |
+
}
|
12 |
+
"""
|
13 |
+
|
14 |
+
# Загрузка данных из JSON
|
15 |
+
data = json.loads(json_data)
|
16 |
|
17 |
# functions
|
18 |
+
def check(answers):
|
|
|
|
|
|
|
19 |
results = []
|
20 |
+
for i, (answer, question) in enumerate(zip(answers, data['questions']), start=1):
|
21 |
+
correct_answer = question['correct_answer']
|
22 |
result = "✔" if answer == correct_answer else "✖️"
|
23 |
results.append(f"{i}: {result}")
|
24 |
|
|
|
30 |
"""
|
31 |
|
32 |
# ui
|
33 |
+
with gr.Blocks(css=css) as vui:
|
34 |
question_blocks = []
|
35 |
+
for i, question in enumerate(data['questions'], start=1):
|
|
|
36 |
with gr.Row():
|
37 |
with gr.Column():
|
38 |
+
radio = gr.Radio(label=f"Вопрос {i}", choices=["А", "Б", "В"], info=question['text'])
|
39 |
+
question_blocks.append(radio)
|
40 |
|
41 |
text_button = gr.Button("Проверить", variant='primary')
|
42 |
with gr.Tab("Результаты"):
|
43 |
text_output = gr.Markdown("")
|
44 |
|
45 |
+
text_button.click(check, inputs=question_blocks, outputs=[text_output])
|
|
|
|
|
|
|
46 |
|
47 |
#end
|
48 |
vui.queue(api_open=False).launch()
|