|
import gradio as gr |
|
import json |
|
|
|
|
|
json_data = """ |
|
{ |
|
"questions": [ |
|
{"text": "Выберите А", "correct_answer": "А", "wrong_answer_text": "Неправильно. Правильный ответ: А"}, |
|
{"text": "Выберите Б", "correct_answer": "Б", "wrong_answer_text": "Неправильно. Правильный ответ: Б"} |
|
] |
|
} |
|
""" |
|
|
|
|
|
data = json.loads(json_data) |
|
|
|
|
|
def check(answers, questions_data): |
|
results = [] |
|
for i, (answer, question_data) in enumerate(zip(answers, questions_data), start=1): |
|
if answer == question_data['correct_answer']: |
|
result = f"## {i}: ✔" |
|
else: |
|
result = f"## {i}: ✖️ ({question_data['wrong_answer_text']})" |
|
results.append(result) |
|
if i < len(questions_data): |
|
results.append("___\n\n") |
|
|
|
return "\n".join(results) |
|
|
|
|
|
questions_data = data['questions'] |
|
|
|
|
|
css = """ |
|
footer {visibility: hidden !important;} |
|
""" |
|
|
|
|
|
with gr.Blocks(css=css, theme='YTheme/TehnoX') as vui: |
|
question_blocks = [] |
|
for i, question in enumerate(data['questions'], start=1): |
|
with gr.Row(): |
|
with gr.Column(): |
|
radio = gr.Radio(label=f"Вопрос {i}", choices=["А", "Б", "В"], info=question['text']) |
|
question_blocks.append(radio) |
|
|
|
text_button = gr.Button("Проверить", variant='primary') |
|
with gr.Tab("Результаты"): |
|
text_output = gr.Markdown("") |
|
|
|
def on_click(*args): |
|
return check(args, questions_data) |
|
|
|
text_button.click(on_click, inputs=question_blocks, outputs=[text_output], queue=False) |
|
|
|
|
|
vui.launch() |