vladyslav commited on
Commit
49dd514
·
1 Parent(s): e4f1674

Reseting answer and Showing message if answer is not selected

Browse files
Files changed (1) hide show
  1. app.py +24 -5
app.py CHANGED
@@ -49,6 +49,19 @@ def load_questions(model, book, student_name, class_name):
49
  def get_next_question(selected_answer):
50
  global current_question_index, answers_log
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  # Writing answer in log
53
  answers_log.append({
54
  "selected": selected_answer,
@@ -62,18 +75,24 @@ def get_next_question(selected_answer):
62
  next_question = questions_data[current_question_index]
63
  question_text = f"# Питання:\n## {next_question['question']}"
64
  answers = [answer['answer'] for answer in next_question['answers']]
65
- return question_text, gr.update(choices=answers, interactive=True), gr.update(visible=True), gr.update(
66
- visible=False), gr.update(visible=False), gr.update(visible=False)
 
 
 
 
 
 
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
 
@@ -135,7 +154,7 @@ with gr.Blocks() as demo:
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
 
 
49
  def get_next_question(selected_answer):
50
  global current_question_index, answers_log
51
 
52
+ if not selected_answer:
53
+ next_question = questions_data[current_question_index]
54
+ question_text = f"# Питання:\n## {next_question['question']}\n# Будь ласка, оберіть відповідь!"
55
+ answers = [answer['answer'] for answer in next_question['answers']]
56
+ return (
57
+ question_text, # question_radio
58
+ gr.update(choices=answers, value=None, interactive=True, visible=True), # answer_radio
59
+ gr.update(visible=True), # next_button
60
+ gr.update(visible=False), # feedback_input
61
+ gr.update(visible=False), # rating_slider
62
+ gr.update(visible=False), # submit_feedback_button
63
+ )
64
+
65
  # Writing answer in log
66
  answers_log.append({
67
  "selected": selected_answer,
 
75
  next_question = questions_data[current_question_index]
76
  question_text = f"# Питання:\n## {next_question['question']}"
77
  answers = [answer['answer'] for answer in next_question['answers']]
78
+ return (
79
+ question_text, # question_radio
80
+ gr.update(choices=answers, value=None, interactive=True, visible=True), # answer_radio
81
+ gr.update(visible=True), # next_button
82
+ gr.update(visible=False), # feedback_input
83
+ gr.update(visible=False), # rating_slider
84
+ gr.update(visible=False), # submit_feedback_button
85
+ )
86
  else:
87
  # All questions are completed — ask for feedback
88
  question_text = "# Дякуємо за участь у тесті! Залиште, будь ласка, свій відгук і оцініть тест."
89
  return (
90
  question_text, # question_radio
91
+ gr.update(visible=False, value=None), # answer_radio
92
  gr.update(visible=False), # next_button
93
  gr.update(visible=True), # feedback_input
94
  gr.update(visible=True), # rating_slider
95
+ gr.update(visible=True), # submit_feedback_button
96
  )
97
 
98
 
 
154
  gr.update(visible=is_field_filled), # next_button
155
  gr.update(visible=False), # feedback_input
156
  gr.update(visible=False), # rating_slider
157
+ gr.update(visible=False), # submit_feedback_button
158
  )
159
 
160