File size: 1,982 Bytes
ca86a9f
8b3bb66
478a01e
aeb22f7
478a01e
 
aeb22f7
 
 
 
478a01e
 
 
aeb22f7
a14df07
ca86a9f
aeb22f7
 
 
 
 
 
 
 
 
b471485
 
aeb22f7
 
 
 
 
 
 
ca86a9f
 
70d951e
 
aeb22f7
 
 
 
 
 
 
 
2c06f05
aeb22f7
 
 
2c06f05
aeb22f7
 
2c06f05
aeb22f7
70d951e
aeb22f7
 
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
49
50
51
52
53
54
55
56
57
58
import gradio as gr
import json

# JSON с вопросами, правильными ответами и текстом при неправильном ответе
json_data = """
{
    "questions": [
        {"text": "Выберите А", "correct_answer": "А", "wrong_answer_text": "Неправильно. Правильный ответ: А"},
        {"text": "Выберите Б", "correct_answer": "Б", "wrong_answer_text": "Неправильно. Правильный ответ: Б"}
    ]
}
"""

# Загрузка данных из JSON
data = json.loads(json_data)

# functions
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
css = """
footer {visibility: hidden !important;}
"""

# ui
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)

#end
vui.launch()