File size: 3,069 Bytes
d941304
 
2526b2b
d941304
 
 
5900776
 
d941304
 
 
 
 
2526b2b
 
d941304
 
00271ad
 
 
 
10482e4
00271ad
dc1d24c
d941304
2526b2b
d941304
1b53686
7488be8
ebe4f0b
5900776
7488be8
 
0e96afe
d941304
 
2526b2b
d941304
 
95eec11
2fc8171
d941304
c37fa3d
 
 
 
d941304
 
 
 
 
 
 
0e96afe
d941304
 
 
 
 
 
 
5900776
 
d941304
 
 
5900776
07a7baf
d941304
1262b51
d941304
 
 
5900776
3a41fb9
5900776
1d32b36
d941304
 
 
 
 
 
 
 
 
3a41fb9
d941304
 
 
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import gradio as gr

from utils import Test



title = "Хто ти із Синтезу?"
description = "Визначте, на кого з легендарної команди Синтез при Свічках (СпС) Ви найбільше схожі"
info = "Пройдіть тест до кінця"



# Define your list of questions and answers
test = Test()


def question_interface(question_state, answer):
    if (question_state["value"] == -1):
        question_state["value"] += 1
    elif (answer is not None):
        question_state["value"] += 1
        question_state["responses"].append(answer)
    current_question_index = question_state["value"]

    # Check if all questions have been answered
    if current_question_index == len(test):
        # Show all responses
        answer_ids = test.convert_to_answer_ids(question_state["responses"])
        best_id = test.select_best(answer_ids)
        radio = gr.Radio.update(choices = [], value = None)
        name = f"Вітаємо, Ви {test.full_names[best_id]}!"
        title = test.titles[best_id]
        image_path = test.get_photos_path(best_id)
        return test.zero_state, name, radio, title, image_path

    # Display the current question
    question = test.get_question(current_question_index)

    # Create an input component for the answer
    answers = test.get_answers(current_question_index)
    radio = gr.Radio.update(choices = answers, value = None)

    image_description = test.get_description(current_question_index)
    image_path = test.get_image_path(current_question_index)

    return question_state, question, radio, image_description, image_path






with gr.Blocks() as blocks:
    question_state = gr.State(value = test.zero_state)
    gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>"
                + title
                + "</h1>")
    gr.Markdown(description)
    with gr.Row():
        with gr.Column():
            textbox = gr.Textbox(
                label="Запитання",
                value="Натисніть ВПЕРЕД для того щоб розпочати тест",
                interactive=False,
            )
            radio = gr.Radio(
                label="Варіанти відповіді",
                choices=[],
                #value=default_lang,
                #type="index",
                interactive=True,
            )
            with gr.Row():
                submit = gr.Button("ВПЕРЕД", variant="primary", interactive=True)
        with gr.Column():
            result = gr.Textbox(label="Як би відповів СпС?", interactive=False)
            resultImage = gr.Image("./emblem.png", label="Image", interactive=False, height=500)
    gr.Markdown(info)
    # gr.Markdown("<center>"
    #             +f'<img src={badge} alt="visitors badge"/>'
    #             +"</center>")

    # actions
    submit.click(
        question_interface,
        [question_state, radio],
        [question_state, textbox, radio, result, resultImage],
    )


blocks.launch()