vladyslav commited on
Commit
c9a4f7a
·
1 Parent(s): 7958dfb

Shuffling answers

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import json
2
  import os
 
3
 
4
  import gradio as gr
5
  from dotenv import load_dotenv
@@ -19,6 +20,15 @@ current_question_index = 0
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
@@ -38,10 +48,7 @@ def load_questions(model, book, student_name, class_name):
38
  questions_data = json.load(file)
39
 
40
  if questions_data:
41
- first_question = questions_data[current_question_index]
42
- question_text = f"# Питання:\n## {first_question['question']}"
43
- answers = [answer['answer'] for answer in first_question['answers']]
44
- return question_text, answers
45
  else:
46
  return "У файлі немає питань.", []
47
 
@@ -50,9 +57,7 @@ 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
@@ -72,9 +77,7 @@ def get_next_question(selected_answer):
72
  # Move to the next question
73
  current_question_index += 1
74
  if current_question_index < len(questions_data):
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
 
1
  import json
2
  import os
3
+ import random
4
 
5
  import gradio as gr
6
  from dotenv import load_dotenv
 
20
  answers_log = [] # Log for saving answers
21
 
22
 
23
+ def get_question():
24
+ global questions_data, current_question_index
25
+ question = questions_data[current_question_index]
26
+ question_text = f"# Питання:\n## {question['question']}"
27
+ answers = [answer['answer'] for answer in question['answers']]
28
+ random.shuffle(answers)
29
+ return question_text, answers
30
+
31
+
32
  def load_questions(model, book, student_name, class_name):
33
  global questions_data, current_question_index
34
  current_question_index = 0
 
48
  questions_data = json.load(file)
49
 
50
  if questions_data:
51
+ return get_question()
 
 
 
52
  else:
53
  return "У файлі немає питань.", []
54
 
 
57
  global current_question_index, answers_log
58
 
59
  if not selected_answer:
60
+ question_text, answers = get_question()
 
 
61
  return (
62
  question_text, # question_radio
63
  gr.update(choices=answers, value=None, interactive=True, visible=True), # answer_radio
 
77
  # Move to the next question
78
  current_question_index += 1
79
  if current_question_index < len(questions_data):
80
+ question_text, answers = get_question()
 
 
81
  return (
82
  question_text, # question_radio
83
  gr.update(choices=answers, value=None, interactive=True, visible=True), # answer_radio