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