Rooni commited on
Commit
55be74a
·
1 Parent(s): e26881b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -23
app.py CHANGED
@@ -1,40 +1,40 @@
1
- # imports
2
  import gradio as gr
3
- import json
4
-
5
 
6
  # functions
7
- def check(v1, v2):
8
- if not v1 or not v2:
9
  raise gr.Error("Выберите все ответы!")
10
- return None
11
- v1 = "✖️"
12
- v2 = "✖️"
13
- if v1 == "А":
14
- v1 = "✔"
15
- if v2 == "Б":
16
- v2 = ""
17
 
18
- return f"""
19
- 1: {v1};
20
- 2: {v2};
21
- """
22
  # css
23
  css = """
24
  footer {visibility: hidden !important;}
25
  """
26
 
27
-
28
  # ui
29
- with gr.Blocks(css=css, theme='YTheme/TehnoX') as vui:
30
- with gr.Row():
31
- with gr.Column():
32
- v1 = gr.Radio(label="Вопрос 1", info="Выберите А", choices=["А", "Б", "В"])
33
- v2 = gr.Radio(label="Вопрос 2", info="Выберите Б", choices=["А", "Б", "В"])
 
 
 
 
34
  text_button = gr.Button("Проверить", variant='primary')
35
  with gr.Tab("Результаты"):
36
  text_output = gr.Markdown("")
37
- text_button.click(check, inputs=[v1, v2], outputs=[text_output])
 
 
 
 
38
 
39
  #end
40
  vui.queue(api_open=False).launch()
 
 
1
  import gradio as gr
 
 
2
 
3
  # functions
4
+ def check(answers, correct_answers):
5
+ if not all(answers):
6
  raise gr.Error("Выберите все ответы!")
7
+
8
+ results = []
9
+ for i, (answer, correct_answer) in enumerate(zip(answers, correct_answers), start=1):
10
+ result = "✔" if answer == correct_answer else "✖️"
11
+ results.append(f"{i}: {result}")
12
+
13
+ return "\n".join(results)
14
 
 
 
 
 
15
  # css
16
  css = """
17
  footer {visibility: hidden !important;}
18
  """
19
 
 
20
  # ui
21
+ with gr.Blocks(css=css) as vui:
22
+ question_blocks = []
23
+ correct_answers = ["А", "Б"] # Предполагаем, что это правильные ответы
24
+ for i, correct_answer in enumerate(correct_answers, start=1):
25
+ with gr.Row():
26
+ with gr.Column():
27
+ question = gr.Radio(label=f"Вопрос {i}", choices=["А", "Б", "В"])
28
+ question_blocks.append(question)
29
+
30
  text_button = gr.Button("Проверить", variant='primary')
31
  with gr.Tab("Результаты"):
32
  text_output = gr.Markdown("")
33
+
34
+ def on_click(*args):
35
+ return check(args, correct_answers)
36
+
37
+ text_button.click(on_click, inputs=question_blocks, outputs=[text_output], queue=False)
38
 
39
  #end
40
  vui.queue(api_open=False).launch()