vladyslav commited on
Commit
c059dfd
·
1 Parent(s): 9f10b71

Printing questions and chosen answers after completing test

Browse files
Files changed (1) hide show
  1. app.py +37 -4
app.py CHANGED
@@ -18,6 +18,7 @@ if os.getenv("ENV_TYPE") == "dev":
18
  questions_data = []
19
  current_question_index = 0
20
  answers_log = [] # Log for saving answers
 
21
 
22
 
23
  def get_question():
@@ -54,7 +55,7 @@ def load_questions(model, book, student_name, class_name):
54
 
55
 
56
  def get_next_question(selected_answer):
57
- global current_question_index, answers_log
58
 
59
  if not selected_answer:
60
  question_text, answers = get_question()
@@ -69,6 +70,7 @@ def get_next_question(selected_answer):
69
  gr.update(visible=False), # question_correct
70
  gr.update(visible=False), # text_coverage
71
  gr.update(visible=False), # interesting_question
 
72
  )
73
 
74
  # Writing answer in log
@@ -93,10 +95,12 @@ def get_next_question(selected_answer):
93
  gr.update(visible=False), # question_correct
94
  gr.update(visible=False), # text_coverage
95
  gr.update(visible=False), # interesting_question
 
96
  )
97
  else:
98
  # All questions are completed — ask for feedback
99
- question_text = "# Дякуємо за участь у тесті! Залиште, будь ласка, свій відгук і оцініть тест."
 
100
  return (
101
  question_text, # question_radio
102
  gr.update(visible=False, value=None), # answer_radio
@@ -108,6 +112,7 @@ def get_next_question(selected_answer):
108
  gr.update(visible=True), # question_correct
109
  gr.update(visible=True), # text_coverage
110
  gr.update(visible=True), # interesting_question
 
111
  )
112
 
113
 
@@ -120,10 +125,10 @@ def summarize_results(student_name,
120
  question_correct,
121
  text_coverage,
122
  interesting_question):
123
- global questions_data, answers_log
124
  questions = []
125
 
126
- if not feedback or not question_correct or not text_coverage or not interesting_question or not rating:
127
  return (
128
  "# Залиште відгук про тест!", # question_output
129
  gr.update(visible=True), # feedback_input
@@ -133,6 +138,8 @@ def summarize_results(student_name,
133
  gr.update(visible=True), # text_coverage
134
  gr.update(visible=True), # interesting_question
135
  gr.update(visible=True), # rating_text
 
 
136
  )
137
 
138
  for question, answer in zip(questions_data, answers_log):
@@ -174,9 +181,26 @@ def summarize_results(student_name,
174
  gr.update(visible=False, value=""), # text_coverage
175
  gr.update(visible=False, value=""), # interesting_question
176
  gr.update(visible=False), # rating_text
 
 
177
  )
178
 
179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  with gr.Blocks() as demo:
181
  with gr.Column():
182
  gr.Markdown("# Оберіть модель та книгу, щоб завантажити питання")
@@ -191,6 +215,8 @@ with gr.Blocks() as demo:
191
  answer_radio = gr.Radio([], label="Варіанти відповіді", interactive=True, visible=False)
192
  next_button = gr.Button("Наступне питання", visible=False)
193
 
 
 
194
  question_correct_input = gr.Textbox(label="Чи коректно поставлено запитання і варіанти відповідей?",
195
  visible=False)
196
  text_coverage_input = gr.Textbox(label="Рівномірність покриття тексту", visible=False)
@@ -217,6 +243,8 @@ with gr.Blocks() as demo:
217
  gr.update(visible=False, value=""), # question_correct
218
  gr.update(visible=False, value=""), # text_coverage
219
  gr.update(visible=False, value=""), # interesting_question
 
 
220
  )
221
 
222
 
@@ -239,6 +267,8 @@ with gr.Blocks() as demo:
239
  question_correct_input,
240
  text_coverage_input,
241
  interesting_question_input,
 
 
242
  ]
243
  )
244
 
@@ -256,6 +286,7 @@ with gr.Blocks() as demo:
256
  question_correct_input,
257
  text_coverage_input,
258
  interesting_question_input,
 
259
  ]
260
  )
261
 
@@ -281,6 +312,8 @@ with gr.Blocks() as demo:
281
  text_coverage_input,
282
  interesting_question_input,
283
  rating_text,
 
 
284
  ]
285
  )
286
 
 
18
  questions_data = []
19
  current_question_index = 0
20
  answers_log = [] # Log for saving answers
21
+ feedback_questions = ""
22
 
23
 
24
  def get_question():
 
55
 
56
 
57
  def get_next_question(selected_answer):
58
+ global current_question_index, answers_log, feedback_questions
59
 
60
  if not selected_answer:
61
  question_text, answers = get_question()
 
70
  gr.update(visible=False), # question_correct
71
  gr.update(visible=False), # text_coverage
72
  gr.update(visible=False), # interesting_question
73
+ "", # feedback_questions_output
74
  )
75
 
76
  # Writing answer in log
 
95
  gr.update(visible=False), # question_correct
96
  gr.update(visible=False), # text_coverage
97
  gr.update(visible=False), # interesting_question
98
+ "", # feedback_questions_output
99
  )
100
  else:
101
  # All questions are completed — ask for feedback
102
+ question_text = "# Дякуємо за участь у тесті!\n# Передивіться тест та ваші відповіді\n# Залиште, будь ласка, свій відгук в кінці сторінки і оцініть тест.\n---"
103
+ feedback_questions = prepare_questions_for_feedback(questions_data, answers_log)
104
  return (
105
  question_text, # question_radio
106
  gr.update(visible=False, value=None), # answer_radio
 
112
  gr.update(visible=True), # question_correct
113
  gr.update(visible=True), # text_coverage
114
  gr.update(visible=True), # interesting_question
115
+ feedback_questions, # feedback_questions_output
116
  )
117
 
118
 
 
125
  question_correct,
126
  text_coverage,
127
  interesting_question):
128
+ global questions_data, answers_log, feedback_questions
129
  questions = []
130
 
131
+ if not feedback or not question_correct or not text_coverage or not interesting_question or rating is None:
132
  return (
133
  "# Залиште відгук про тест!", # question_output
134
  gr.update(visible=True), # feedback_input
 
138
  gr.update(visible=True), # text_coverage
139
  gr.update(visible=True), # interesting_question
140
  gr.update(visible=True), # rating_text
141
+ feedback_questions, # feedback_questions_output
142
+ gr.update(visible=True), # feedback_not_provided
143
  )
144
 
145
  for question, answer in zip(questions_data, answers_log):
 
181
  gr.update(visible=False, value=""), # text_coverage
182
  gr.update(visible=False, value=""), # interesting_question
183
  gr.update(visible=False), # rating_text
184
+ "", # feedback_questions_output
185
+ gr.update(visible=False), # feedback_not_provided
186
  )
187
 
188
 
189
+ def prepare_questions_for_feedback(questions, answer_log):
190
+ feedback = []
191
+
192
+ for i, question in enumerate(questions):
193
+ question_text = f"## Питання: {question['question']}."
194
+ answers_text = "\n".join(
195
+ [f"* {ans['answer']}" for ans in question['answers']]
196
+ )
197
+ user_answer = f"## Ваша відповідь:\n* {answer_log[i]['selected']}"
198
+
199
+ feedback.append(f"{question_text}\n## Відповіді:\n{answers_text}\n{user_answer}\n---")
200
+
201
+ return "\n".join(feedback)
202
+
203
+
204
  with gr.Blocks() as demo:
205
  with gr.Column():
206
  gr.Markdown("# Оберіть модель та книгу, щоб завантажити питання")
 
215
  answer_radio = gr.Radio([], label="Варіанти відповіді", interactive=True, visible=False)
216
  next_button = gr.Button("Наступне питання", visible=False)
217
 
218
+ feedback_questions_output = gr.Markdown(label="Пройдені питання")
219
+ feedback_not_provided = gr.Markdown("# Заповніть поля відгуку та залишіть оцінку!", visible=False)
220
  question_correct_input = gr.Textbox(label="Чи коректно поставлено запитання і варіанти відповідей?",
221
  visible=False)
222
  text_coverage_input = gr.Textbox(label="Рівномірність покриття тексту", visible=False)
 
243
  gr.update(visible=False, value=""), # question_correct
244
  gr.update(visible=False, value=""), # text_coverage
245
  gr.update(visible=False, value=""), # interesting_question
246
+ "", # feedback_questions_output
247
+ gr.update(visible=False), # feedback_not_provided
248
  )
249
 
250
 
 
267
  question_correct_input,
268
  text_coverage_input,
269
  interesting_question_input,
270
+ feedback_questions_output,
271
+ feedback_not_provided,
272
  ]
273
  )
274
 
 
286
  question_correct_input,
287
  text_coverage_input,
288
  interesting_question_input,
289
+ feedback_questions_output,
290
  ]
291
  )
292
 
 
312
  text_coverage_input,
313
  interesting_question_input,
314
  rating_text,
315
+ feedback_questions_output,
316
+ feedback_not_provided,
317
  ]
318
  )
319