synthesis-test / app.py
theodotus's picture
Use answers id
1b53686
raw
history blame
2.5 kB
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"]
if (current_question_index != 0):
question_state["responses"].append(answer)
# 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"])
return response_text
# 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)
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 = {"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)
with gr.Column():
result = gr.Textbox(label="Test result", interactive=False)
resultImage = gr.Image(label="Image", 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, resultImage],
)
blocks.launch()