Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| title = "Психологічний тест" | |
| description = "Визначте хто ви з синтезу" | |
| info = "Пройдіть тест до кінця" | |
| # Define your list of questions and answers | |
| questions = ["Question 1", "Question 2", "Question 3"] | |
| answers = ["Answer 1", "Answer 2", "Answer 3"] | |
| 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(questions): | |
| # 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 = questions[current_question_index] | |
| # Create an input component for the answer | |
| radio = gr.Radio.update(choices = ["1","2","3"]) | |
| return question_state, question, radio, "Click 'Answer' to submit" | |
| with gr.Blocks() as blocks: | |
| question_state = gr.State(value = {"value":0, "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=questions[question_state.value["value"]], | |
| interactive=False, | |
| ) | |
| radio = gr.Radio( | |
| label="Answer options", | |
| choices=answers, | |
| #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() |