arxivgpt kim commited on
Commit
216c3df
Β·
verified Β·
1 Parent(s): 5473873

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -35
app.py CHANGED
@@ -1,55 +1,61 @@
1
  import gradio as gr
2
 
3
- # μ˜ˆμ‹œ 문제, 선택지, 점수 μ •μ˜
4
  questions = [
5
  "1. λ‹Ήμ‹ μ˜ μ’‹μ•„ν•˜λŠ” 색은 λ¬΄μ—‡μΈκ°€μš”?",
6
  "2. 주말에 κ°€μž₯ ν•˜κ³  싢은 ν™œλ™μ€?",
7
- "3. μ’‹μ•„ν•˜λŠ” μŒμ‹μ€ λ¬΄μ—‡μΈκ°€μš”?",
8
- "4. κ°€μž₯ μ’‹μ•„ν•˜λŠ” κ³„μ ˆμ€?",
9
- "5. 읽고 싢은 μ±…μ˜ μž₯λ₯΄λŠ”?",
10
- "6. μ—¬ν–‰ κ°€κ³  싢은 곳은?"
11
  ]
12
 
13
  options = [
14
  ["λΉ¨κ°•", "νŒŒλž‘", "녹색"],
15
- ["μ‚°μ±…", "λ…μ„œ", "μ˜ν™” 감상"],
 
16
  ["ν•œμ‹", "쀑식", "양식"],
17
- ["λ΄„", "여름", "가을", "겨울"],
18
- ["μ†Œμ„€", "μžκΈ°κ³„λ°œ", "역사"],
19
- ["μ‚°", "λ°”λ‹€", "λ„μ‹œ"]
20
  ]
21
 
22
  scores = [
23
  [1, 2, 3],
24
- [3, 2, 1],
25
  [2, 3, 1],
26
- [4, 3, 2, 1],
27
- [3, 2, 1],
28
- [2, 3, 1]
 
29
  ]
30
 
31
  # 점수 계산 ν•¨μˆ˜
32
  def calculate_score(answers):
33
  total_score = sum([scores[i][options[i].index(ans)] for i, ans in enumerate(answers)])
34
- return f"총점: {total_score}"
35
-
36
- # νŽ˜μ΄μ§€λ‹Ή 문제 수
37
- questions_per_page = 2
38
- total_pages = len(questions) // questions_per_page
39
-
40
- def create_page(page_num):
41
- page_questions = questions[page_num*questions_per_page:(page_num+1)*questions_per_page]
42
- page_options = options[page_num*questions_per_page:(page_num+1)*questions_per_page]
43
- inputs = [gr.Radio(label=ques, choices=opts) for ques, opts in zip(page_questions, page_options)]
44
- if page_num == total_pages - 1: # λ§ˆμ§€λ§‰ νŽ˜μ΄μ§€μ—μ„œλŠ” κ²°κ³Όλ₯Ό 좜λ ₯
45
- return gr.Interface(fn=calculate_score, inputs=inputs, outputs="text")
46
- else: # λ‹€λ₯Έ νŽ˜μ΄μ§€μ—μ„œλŠ” λ‹€μŒ νŽ˜μ΄μ§€ 링크 제곡
47
- return gr.Interface(fn=lambda *args: None, inputs=inputs, outputs=None)
48
-
49
- # 각 νŽ˜μ΄μ§€μ— λŒ€ν•œ μΈν„°νŽ˜μ΄μŠ€ 생성 및 μ‹€ν–‰
50
- pages = [create_page(i) for i in range(total_pages)]
51
- for page in pages:
52
- page.launch()
53
-
54
-
55
-
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
+ # 문제, 선택지, 점수 μ„€μ •
4
  questions = [
5
  "1. λ‹Ήμ‹ μ˜ μ’‹μ•„ν•˜λŠ” 색은 λ¬΄μ—‡μΈκ°€μš”?",
6
  "2. 주말에 κ°€μž₯ ν•˜κ³  싢은 ν™œλ™μ€?",
7
+ "3. μ„ ν˜Έν•˜λŠ” 여행지 μœ ν˜•μ€?",
8
+ "4. μ’‹μ•„ν•˜λŠ” μŒμ‹μ€ λ¬΄μ—‡μΈκ°€μš”?",
9
+ "5. μ·¨λ―Έ μƒν™œλ‘œ 더 μ„ ν˜Έν•˜λŠ” 것은?",
10
+ "6. 읽기 μ’‹μ•„ν•˜λŠ” μ±…μ˜ μž₯λ₯΄λŠ”?"
11
  ]
12
 
13
  options = [
14
  ["λΉ¨κ°•", "νŒŒλž‘", "녹색"],
15
+ ["μ‚°μ±…", "λ…μ„œ", "μ˜ν™” κ΄€λžŒ"],
16
+ ["μ‚°", "λ°”λ‹€", "λ„μ‹œ"],
17
  ["ν•œμ‹", "쀑식", "양식"],
18
+ ["μš΄λ™", "μš”λ¦¬", "κ·Έλ¦Ό 그리기"],
19
+ ["μ†Œμ„€", "κ³Όν•™", "역사"]
 
20
  ]
21
 
22
  scores = [
23
  [1, 2, 3],
 
24
  [2, 3, 1],
25
+ [3, 1, 2],
26
+ [1, 3, 2],
27
+ [2, 1, 3],
28
+ [3, 2, 1]
29
  ]
30
 
31
  # 점수 계산 ν•¨μˆ˜
32
  def calculate_score(answers):
33
  total_score = sum([scores[i][options[i].index(ans)] for i, ans in enumerate(answers)])
34
+ return f"총 μ μˆ˜λŠ” {total_score}μ μž…λ‹ˆλ‹€."
35
+
36
+ # μΈν„°νŽ˜μ΄μŠ€ 생성
37
+ def create_interface(question_idx):
38
+ with gr.Blocks() as demo:
39
+ with gr.Row():
40
+ gr.Markdown(questions[question_idx])
41
+ answer1 = gr.Radio(options[question_idx], label="선택")
42
+
43
+ with gr.Row():
44
+ gr.Markdown(questions[question_idx + 1])
45
+ answer2 = gr.Radio(options[question_idx + 1], label="선택")
46
+
47
+ if question_idx + 2 < len(questions):
48
+ btn_next = gr.Button("λ‹€μŒ")
49
+ btn_next.click(create_interface, inputs=[], outputs=[], _js="()=>{window.location.hash='page" + str((question_idx//2)+2) + "';}")
50
+
51
+ if question_idx + 2 >= len(questions):
52
+ btn_submit = gr.Button("제좜")
53
+ result = gr.Textbox(label="μ΅œμ’… κ²°κ³Ό")
54
+ btn_submit.click(calculate_score, inputs=[answer1, answer2], outputs=result)
55
+
56
+ return demo
57
+
58
+ # 각 νŽ˜μ΄μ§€λ³„λ‘œ μΈν„°νŽ˜μ΄μŠ€ 생성 및 λΌμš°νŒ…
59
+ for i in range(0, len(questions), 2):
60
+ demo = create_interface(i)
61
+ demo.launch(share=True, server_name="0.0.0.0", server_port=7860 + (i//2))