Rooni commited on
Commit
74b4b91
·
1 Parent(s): cd0e092

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -1,13 +1,9 @@
1
  import gradio as gr
2
 
3
- # Global variable to track if the check has been done
4
- check_done = False
5
-
6
  # functions
7
- def check(answers, correct_answers):
8
- global check_done
9
- if check_done:
10
- raise gr.Error("Вы уже проверили ответы!")
11
 
12
  if not all(answers):
13
  raise gr.Error("Выберите все ответы!")
@@ -17,7 +13,7 @@ def check(answers, correct_answers):
17
  result = "✔" if answer == correct_answer else "✖️"
18
  results.append(f"{i}: {result}")
19
 
20
- check_done = True # Set the flag to True after the check
21
  return "\n".join(results)
22
 
23
  # css
@@ -34,13 +30,17 @@ with gr.Blocks(css=css, theme='YTheme/TehnoX') as vui:
34
  with gr.Column():
35
  question = gr.Radio(label=f"Вопрос {i}", choices=["А", "Б", "В"])
36
  question_blocks.append(question)
37
-
38
  text_button = gr.Button("Проверить", variant='primary')
39
  with gr.Tab("Результаты"):
40
  text_output = gr.Markdown("")
41
 
 
 
 
42
  def on_click(*args):
43
- return check(args, correct_answers)
 
44
 
45
  text_button.click(on_click, inputs=question_blocks, outputs=[text_output], queue=False)
46
 
 
1
  import gradio as gr
2
 
 
 
 
3
  # functions
4
+ def check(answers, correct_answers, user_ip):
5
+ if user_ip in completed_ips:
6
+ raise gr.Error("Вы уже проверили свои ответы!")
 
7
 
8
  if not all(answers):
9
  raise gr.Error("Выберите все ответы!")
 
13
  result = "✔" if answer == correct_answer else "✖️"
14
  results.append(f"{i}: {result}")
15
 
16
+ completed_ips.add(user_ip) # Добавляем IP пользователя в список выполненных
17
  return "\n".join(results)
18
 
19
  # css
 
30
  with gr.Column():
31
  question = gr.Radio(label=f"Вопрос {i}", choices=["А", "Б", "В"])
32
  question_blocks.append(question)
33
+
34
  text_button = gr.Button("Проверить", variant='primary')
35
  with gr.Tab("Результаты"):
36
  text_output = gr.Markdown("")
37
 
38
+ # Список IP-адресов пользователей, которые уже сделали запрос
39
+ completed_ips = set()
40
+
41
  def on_click(*args):
42
+ user_ip = gr.get_ip_address() # Получаем IP пользователя
43
+ return check(args, correct_answers, user_ip)
44
 
45
  text_button.click(on_click, inputs=question_blocks, outputs=[text_output], queue=False)
46