vladyslav
commited on
Commit
·
f972eea
1
Parent(s):
fefd70e
Added comment and rating for test
Browse files
app.py
CHANGED
|
@@ -73,13 +73,18 @@ def get_next_question(selected_answer):
|
|
| 73 |
next_question = questions_data[current_question_index]
|
| 74 |
question_text = f"# Питання:\n## {next_question['question']}"
|
| 75 |
answers = [answer['answer'] for answer in next_question['answers']]
|
| 76 |
-
return question_text, gr.update(choices=answers, interactive=True), gr.update(visible=True)
|
| 77 |
else:
|
| 78 |
-
# All questions are completed —
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
|
| 85 |
with gr.Blocks() as demo:
|
|
@@ -94,21 +99,32 @@ with gr.Blocks() as demo:
|
|
| 94 |
answer_radio = gr.Radio([], label="Варіанти відповіді", interactive=True)
|
| 95 |
next_button = gr.Button("Наступне питання", visible=False)
|
| 96 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
def update_question(model, book):
|
| 98 |
question, answers = load_questions(model, book)
|
| 99 |
-
return question, gr.update(choices=answers, interactive=True), gr.update(visible=True)
|
| 100 |
|
| 101 |
load_button.click(
|
| 102 |
update_question,
|
| 103 |
inputs=[model_radio, book_radio],
|
| 104 |
-
outputs=[question_output, answer_radio, next_button]
|
| 105 |
)
|
| 106 |
|
| 107 |
next_button.click(
|
| 108 |
get_next_question,
|
| 109 |
inputs=[answer_radio],
|
| 110 |
-
outputs=[question_output, answer_radio, next_button]
|
| 111 |
)
|
| 112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
if __name__ == "__main__":
|
| 114 |
demo.launch()
|
|
|
|
| 73 |
next_question = questions_data[current_question_index]
|
| 74 |
question_text = f"# Питання:\n## {next_question['question']}"
|
| 75 |
answers = [answer['answer'] for answer in next_question['answers']]
|
| 76 |
+
return question_text, gr.update(choices=answers, interactive=True), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
| 77 |
else:
|
| 78 |
+
# All questions are completed — ask for feedback
|
| 79 |
+
question_text = "Дякуємо за участь у тесті! Залиште, будь ласка, свій відгук і оцініть тест."
|
| 80 |
+
return question_text, gr.update(visible=False), gr.update(visible=False), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def summarize_results(feedback, rating):
|
| 84 |
+
correct_answers_count = sum(1 for answer in answers_log if answer['isCorrect'])
|
| 85 |
+
total_questions = len(questions_data)
|
| 86 |
+
summary = f"# Усі питання пройдено.\n\n## Ви відповіли правильно на {correct_answers_count} з {total_questions} питань.\n\n### Ваш відгук: {feedback}\n### Ваша оцінка: {rating}/5"
|
| 87 |
+
return summary, gr.update(visible=False, value=""), gr.update(visible=False, value=0), gr.update(visible=False)
|
| 88 |
|
| 89 |
|
| 90 |
with gr.Blocks() as demo:
|
|
|
|
| 99 |
answer_radio = gr.Radio([], label="Варіанти відповіді", interactive=True)
|
| 100 |
next_button = gr.Button("Наступне питання", visible=False)
|
| 101 |
|
| 102 |
+
feedback_input = gr.Textbox(label="Ваш відгук про тест", visible=False)
|
| 103 |
+
rating_slider = gr.Slider(1, 5, step=1, label="Оцініть тест", visible=False)
|
| 104 |
+
submit_feedback_button = gr.Button("Завершити тест", visible=False)
|
| 105 |
+
|
| 106 |
def update_question(model, book):
|
| 107 |
question, answers = load_questions(model, book)
|
| 108 |
+
return question, gr.update(choices=answers, interactive=True, visible=True), gr.update(visible=True), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
| 109 |
|
| 110 |
load_button.click(
|
| 111 |
update_question,
|
| 112 |
inputs=[model_radio, book_radio],
|
| 113 |
+
outputs=[question_output, answer_radio, next_button, feedback_input, rating_slider, submit_feedback_button]
|
| 114 |
)
|
| 115 |
|
| 116 |
next_button.click(
|
| 117 |
get_next_question,
|
| 118 |
inputs=[answer_radio],
|
| 119 |
+
outputs=[question_output, answer_radio, next_button, feedback_input, rating_slider, submit_feedback_button]
|
| 120 |
)
|
| 121 |
|
| 122 |
+
submit_feedback_button.click(
|
| 123 |
+
summarize_results,
|
| 124 |
+
inputs=[feedback_input, rating_slider],
|
| 125 |
+
outputs=[question_output, feedback_input, rating_slider, submit_feedback_button]
|
| 126 |
+
)
|
| 127 |
+
|
| 128 |
+
|
| 129 |
if __name__ == "__main__":
|
| 130 |
demo.launch()
|