vladyslav
commited on
Commit
·
c37b8d9
1
Parent(s):
fbaf544
Refactored returns in functions. Fixed displaying components when not all fields are filled
Browse files
app.py
CHANGED
@@ -19,13 +19,13 @@ current_question_index = 0
|
|
19 |
answers_log = [] # Log for saving answers
|
20 |
|
21 |
|
22 |
-
def load_questions(model, book):
|
23 |
global questions_data, current_question_index
|
24 |
current_question_index = 0
|
25 |
answers_log.clear()
|
26 |
|
27 |
-
if not model or not book:
|
28 |
-
return "Будь ласка,
|
29 |
|
30 |
model_path = MODELS_PATH[model]
|
31 |
book_filename = BOOKS[book]
|
@@ -67,8 +67,14 @@ def get_next_question(selected_answer):
|
|
67 |
else:
|
68 |
# All questions are completed — ask for feedback
|
69 |
question_text = "Дякуємо за участь у тесті! Залиште, будь ласка, свій відгук і оцініть тест."
|
70 |
-
return
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
|
74 |
def summarize_results(student_name, class_name, model, book, feedback, rating):
|
@@ -93,7 +99,12 @@ def summarize_results(student_name, class_name, model, book, feedback, rating):
|
|
93 |
f"## Оцінка за 12-бальною шкалою: {grade_12:.2f}\n\n"
|
94 |
)
|
95 |
|
96 |
-
return
|
|
|
|
|
|
|
|
|
|
|
97 |
|
98 |
|
99 |
with gr.Blocks() as demo:
|
@@ -107,7 +118,7 @@ with gr.Blocks() as demo:
|
|
107 |
|
108 |
load_button = gr.Button("Завантажити питання")
|
109 |
question_output = gr.Markdown(label="Питання")
|
110 |
-
answer_radio = gr.Radio([], label="Варіанти відповіді", interactive=True)
|
111 |
next_button = gr.Button("Наступне питання", visible=False)
|
112 |
|
113 |
feedback_input = gr.Textbox(label="Ваш відгук про тест", visible=False)
|
@@ -116,9 +127,16 @@ with gr.Blocks() as demo:
|
|
116 |
|
117 |
|
118 |
def update_question(model, book):
|
119 |
-
question, answers = load_questions(model, book)
|
120 |
-
|
121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
|
123 |
|
124 |
load_button.click(
|
|
|
19 |
answers_log = [] # Log for saving answers
|
20 |
|
21 |
|
22 |
+
def load_questions(model, book, student_name, class_name):
|
23 |
global questions_data, current_question_index
|
24 |
current_question_index = 0
|
25 |
answers_log.clear()
|
26 |
|
27 |
+
if not model or not book or not student_name or not class_name:
|
28 |
+
return "# Будь ласка, заповніть усі поля!", []
|
29 |
|
30 |
model_path = MODELS_PATH[model]
|
31 |
book_filename = BOOKS[book]
|
|
|
67 |
else:
|
68 |
# All questions are completed — ask for feedback
|
69 |
question_text = "Дякуємо за участь у тесті! Залиште, будь ласка, свій відгук і оцініть тест."
|
70 |
+
return (
|
71 |
+
question_text, # question_radio
|
72 |
+
gr.update(visible=False), # answer_radio
|
73 |
+
gr.update(visible=False), # next_button
|
74 |
+
gr.update(visible=True), # feedback_input
|
75 |
+
gr.update(visible=True), # rating_slider
|
76 |
+
gr.update(visible=True) # submit_feedback_button
|
77 |
+
)
|
78 |
|
79 |
|
80 |
def summarize_results(student_name, class_name, model, book, feedback, rating):
|
|
|
99 |
f"## Оцінка за 12-бальною шкалою: {grade_12:.2f}\n\n"
|
100 |
)
|
101 |
|
102 |
+
return (
|
103 |
+
summary, # question_output
|
104 |
+
gr.update(visible=False, value=""), # feedback_input
|
105 |
+
gr.update(visible=False, value=0), # rating_slider
|
106 |
+
gr.update(visible=False) # submit_feedback_button
|
107 |
+
)
|
108 |
|
109 |
|
110 |
with gr.Blocks() as demo:
|
|
|
118 |
|
119 |
load_button = gr.Button("Завантажити питання")
|
120 |
question_output = gr.Markdown(label="Питання")
|
121 |
+
answer_radio = gr.Radio([], label="Варіанти відповіді", interactive=True, visible=False)
|
122 |
next_button = gr.Button("Наступне питання", visible=False)
|
123 |
|
124 |
feedback_input = gr.Textbox(label="Ваш відгук про тест", visible=False)
|
|
|
127 |
|
128 |
|
129 |
def update_question(model, book):
|
130 |
+
question, answers = load_questions(model, book, student_name_input, class_name_input)
|
131 |
+
is_field_filled = len(answers) > 0
|
132 |
+
return (
|
133 |
+
question, # question_output
|
134 |
+
gr.update(choices=answers, interactive=True, visible=is_field_filled), # answer_radio
|
135 |
+
gr.update(visible=is_field_filled), # next_button
|
136 |
+
gr.update(visible=False), # feedback_input
|
137 |
+
gr.update(visible=False), # rating_slider
|
138 |
+
gr.update(visible=False) # submit_feedback_button
|
139 |
+
)
|
140 |
|
141 |
|
142 |
load_button.click(
|