Spaces:
fantos
/
Sleeping

arxivgpt kim commited on
Commit
8dd2edf
·
verified ·
1 Parent(s): 6ff1c27

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -39
app.py CHANGED
@@ -1,58 +1,57 @@
1
  import gradio as gr
2
 
3
- # 예시 데이터
4
  questions = [
5
  "1. 당신의 좋아하는 색은 무엇인가요?",
6
  "2. 주말에 가장 하고 싶은 활동은?",
7
- "3. 선호하는 여행지 유형은?",
8
- "4. 좋아하는 음식은 무엇인가요?",
9
- "5. 관심 있는 취미는 무엇인가요?",
10
- "6. 선호하는 영화 장르는?"
11
  ]
12
 
13
- choices = [
14
  ["빨강", "파랑", "초록"],
15
  ["산책", "독서", "영화 감상"],
16
- ["산", "바다", "도시"],
17
  ["한식", "중식", "양식"],
18
- ["운동", "음악 감상", "그림 그리기"],
19
- ["액션", "로맨스", "공포"]
 
20
  ]
21
 
22
  scores = [
23
  [1, 2, 3],
24
- [3, 2, 1],
25
- [2, 3, 1],
26
- [1, 3, 2],
27
- [2, 1, 3],
28
- [3, 1, 2]
29
  ]
30
 
31
  def calculate_score(answers):
32
- total_score = sum(scores[i][choices[i].index(ans)] for i, ans in enumerate(answers))
33
- return f"총점: {total_score}"
 
 
34
 
35
- with gr.Blocks() as app:
36
- pages = []
37
- answers = gr.State([])
 
 
 
 
 
 
 
 
38
 
39
- for i, question in enumerate(questions):
40
- with gr.Page() as page:
41
- gr.Markdown(question)
42
- answer = gr.Radio(choices=choices[i])
43
- if i < len(questions) - 1:
44
- gr.Button("다음").click(
45
- lambda a, ans=answer: ans.get(),
46
- inputs=[],
47
- outputs=answers,
48
- next_page=page.next_page
49
- )
50
- else:
51
- gr.Button("제출").click(
52
- calculate_score,
53
- inputs=[answers],
54
- outputs=gr.Textbox()
55
- )
56
- pages.append(page)
57
-
58
- app.launch()
 
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, 4],
25
+ [3, 4, 5],
26
+ [4, 5, 6],
27
+ [5, 6, 7, 8],
28
+ [6, 7, 8]
29
  ]
30
 
31
  def calculate_score(answers):
32
+ total_score = 0
33
+ for i, ans in enumerate(answers):
34
+ total_score += scores[i][options[i].index(ans)]
35
+ return total_score
36
 
37
+ with gr.Blocks() as demo:
38
+ with gr.Tab("퀴즈 1"):
39
+ answer1 = gr.Radio(choices=options[0], label=questions[0])
40
+ answer2 = gr.Radio(choices=options[1], label=questions[1])
41
+ with gr.Tab("퀴즈 2"):
42
+ answer3 = gr.Radio(choices=options[2], label=questions[2])
43
+ answer4 = gr.Radio(choices=options[3], label=questions[3])
44
+ with gr.Tab("퀴즈 3"):
45
+ answer5 = gr.Radio(choices=options[4], label=questions[4])
46
+ answer6 = gr.Radio(choices=options[5], label=questions[5])
47
+ submit_btn = gr.Button("제출")
48
 
49
+ result = gr.Textbox(label="총점")
50
+
51
+ submit_btn.click(
52
+ fn=calculate_score,
53
+ inputs=[answer1, answer2, answer3, answer4, answer5, answer6],
54
+ outputs=result
55
+ )
56
+
57
+ demo.launch()