File size: 1,346 Bytes
ca86a9f 478a01e ca86a9f 478a01e 55be74a 478a01e 55be74a d0b8c85 ca86a9f 70d951e ca86a9f 478a01e 55be74a 478a01e 55be74a 478a01e 70d951e ca86a9f d0b8c85 55be74a 478a01e 70d951e ca86a9f |
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 |
import gradio as gr
import json
# JSON с вопросами и правильными ответами
json_data = """
{
"questions": [
{"text": "Выберите А", "correct_answer": "А"},
{"text": "Выберите Б", "correct_answer": "Б"}
]
}
"""
# Загрузка данных из JSON
data = json.loads(json_data)
# functions
def check(answers):
results = []
for i, (answer, question) in enumerate(zip(answers, data['questions']), start=1):
correct_answer = question['correct_answer']
result = "✔" if answer == correct_answer else "✖️"
results.append(f"{i}: {result}")
return "\n".join(results)
# css
css = """
footer {visibility: hidden !important;}
"""
# ui
with gr.Blocks(css=css) 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("")
text_button.click(check, inputs=question_blocks, outputs=[text_output])
#end
vui.queue(api_open=False).launch() |