File size: 2,190 Bytes
d941304
 
2526b2b
d941304
 
 
 
 
 
 
 
 
 
2526b2b
 
d941304
 
 
 
 
 
2526b2b
d941304
 
 
 
 
2526b2b
d941304
 
2526b2b
d941304
 
 
 
 
 
 
 
 
07a7baf
d941304
 
 
 
 
 
 
 
07a7baf
d941304
 
 
 
07a7baf
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
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):
    question_state["value"] += 1
    current_question_index = question_state["value"]

    # Check if all questions have been answered
    if current_question_index == len(test):
        # Show all responses
        response_text = "\n".join(f"Question: {q}\nAnswer: {a}\n" for q, a in zip(questions, question_state["responses"]))
        return response_text

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

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

    return question_state, question, radio, "Click 'Answer' to submit"






with gr.Blocks() as blocks:
    question_state = gr.State(value = {"value":-1, "responses":[]})
    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="Question",
                value="Натисніть Submit для того щоб розпочати тест",
                interactive=False,
            )
            radio = gr.Radio(
                label="Answer options",
                choices=[],
                #value=default_lang,
                type="index",
                interactive=True,
            )
            with gr.Row():
                submit = gr.Button("Submit", variant="primary", interactive=True)
        result = gr.Textbox(label="Test result", interactive=False)
    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],
    )


blocks.launch()