Spaces:
Sleeping
Sleeping
DIrty draft
Browse files
app.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
title = "Психологічний тест"
|
| 7 |
+
description = "Визначте хто ви з синтезу"
|
| 8 |
+
info = "Пройдіть тест до кінця"
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
# Define your list of questions and answers
|
| 13 |
+
questions = ["Question 1", "Question 2", "Question 3"]
|
| 14 |
+
answers = ["Answer 1", "Answer 2", "Answer 3"]
|
| 15 |
+
|
| 16 |
+
def question_interface(question_state, answer):
|
| 17 |
+
question_state["value"] += 1
|
| 18 |
+
current_question_index = question_state["value"]
|
| 19 |
+
|
| 20 |
+
# Check if all questions have been answered
|
| 21 |
+
if current_question_index == len(questions):
|
| 22 |
+
# Show all responses
|
| 23 |
+
response_text = "\n".join(f"Question: {q}\nAnswer: {a}\n" for q, a in zip(questions, question_state["responses"]))
|
| 24 |
+
return response_text
|
| 25 |
+
|
| 26 |
+
# Display the current question
|
| 27 |
+
question = questions[current_question_index]
|
| 28 |
+
|
| 29 |
+
# Create an input component for the answer
|
| 30 |
+
radio = gr.Radio.update(choices = ["1","2","3"])
|
| 31 |
+
|
| 32 |
+
return question_state, question, radio, "Click 'Answer' to submit"
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
with gr.Blocks() as blocks:
|
| 40 |
+
question_state = gr.State(value = {"value":0, "responses":[]})
|
| 41 |
+
gr.Markdown("<h1 style='text-align: center; margin-bottom: 1rem'>"
|
| 42 |
+
+ title
|
| 43 |
+
+ "</h1>")
|
| 44 |
+
gr.Markdown(description)
|
| 45 |
+
with gr.Row():
|
| 46 |
+
with gr.Column():
|
| 47 |
+
textbox = gr.Textbox(
|
| 48 |
+
label="Question",
|
| 49 |
+
value=questions[question_state.value["value"]],
|
| 50 |
+
interactive=False,
|
| 51 |
+
)
|
| 52 |
+
radio = gr.Radio(
|
| 53 |
+
label="Answer options",
|
| 54 |
+
choices=answers,
|
| 55 |
+
#value=default_lang,
|
| 56 |
+
type="index",
|
| 57 |
+
interactive=True,
|
| 58 |
+
)
|
| 59 |
+
with gr.Row():
|
| 60 |
+
submit = gr.Button("Submit", variant="primary", interactive=True)
|
| 61 |
+
result = gr.Textbox(label="Test result", interactive=False)
|
| 62 |
+
gr.Markdown(info)
|
| 63 |
+
# gr.Markdown("<center>"
|
| 64 |
+
# +f'<img src={badge} alt="visitors badge"/>'
|
| 65 |
+
# +"</center>")
|
| 66 |
+
|
| 67 |
+
# actions
|
| 68 |
+
submit.click(
|
| 69 |
+
question_interface,
|
| 70 |
+
[question_state, radio],
|
| 71 |
+
[question_state, textbox, radio, result],
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
blocks.launch()
|