Spaces:
fantos
/
Sleeping

arxivgpt kim commited on
Commit
9b28bee
ยท
verified ยท
1 Parent(s): 7944e13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -26
app.py CHANGED
@@ -106,20 +106,32 @@ scores = [[1, 0],
106
  [3, 2, 1, 0]
107
  ]
108
 
109
- def calculate_score(*answers):
110
- total_score = sum([scores[i][options[i].index(answer)] for i, answer in enumerate(answers)])
 
 
 
 
 
 
 
 
 
 
 
111
  grade, definition = get_grade(total_score)
112
- # ์—ฌ๊ธฐ์„œ ๊ฒฐ๊ณผ๋ฅผ ๋ฐ˜ํ™˜ํ•˜๊ธฐ ์ „์— Zapier Webhook์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ „์†กํ•ฉ๋‹ˆ๋‹ค.
 
113
  webhook_url = "https://hooks.zapier.com/hooks/catch/14523965/3egrs04/"
114
  data = {
115
- "project_name": project_name.value,
116
- "contact_name": contact_name.value,
117
- "contact_email": contact_email.value,
118
- "contact_phone": contact_phone.value,
119
  "responses": answers # ์‚ฌ์šฉ์ž์˜ ์‘๋‹ต๋“ค
120
  }
121
  response = requests.post(webhook_url, json=data)
122
- # Zapier๋กœ๋ถ€ํ„ฐ์˜ ์‘๋‹ต ํ™•์ธ
123
  if response.status_code == 200:
124
  print("Data sent to Zapier successfully.")
125
  else:
@@ -127,6 +139,7 @@ def calculate_score(*answers):
127
  return total_score, grade, definition
128
 
129
 
 
130
  def get_grade(total_score):
131
  converted_score = (total_score)
132
 
@@ -149,7 +162,6 @@ css = """
149
  footer {
150
  visibility: hidden;
151
  }
152
-
153
  /* ๋ฒ„ํŠผ ์Šคํƒ€์ผ๋ง */
154
  button {
155
  background: linear-gradient(135deg, #007BFF, #004085);
@@ -163,54 +175,43 @@ button {
163
  cursor: pointer;
164
  transition: background 0.5s ease;
165
  }
166
-
167
  button:hover {
168
  background: linear-gradient(135deg, #0056b3, #002752);
169
  }
170
-
171
-
172
-
173
  /* ํƒญ ์ƒ‰๊น” ๋ณ€๊ฒฝ์„ ์œ„ํ•œ CSS */
174
  /* ํƒญ ๋ฒ„ํŠผ ์Šคํƒ€์ผ */
175
  .tab-container .tab {
176
  background-color: #f0f0f0; /* ์—ฐํ•œ ํšŒ์ƒ‰์œผ๋กœ ๋ฐฐ๊ฒฝ์ƒ‰ ๋ณ€๊ฒฝ */
177
  color: #333; /* ๊ธ€์ž์ƒ‰ ๋ณ€๊ฒฝ */
178
  }
179
-
180
  /* ์„ ํƒ๋œ ํƒญ ์Šคํƒ€์ผ */
181
  .tab-container .tab.selected {
182
  background-color: #d9d9d9; /* ์„ ํƒ๋œ ํƒญ์˜ ๋ฐฐ๊ฒฝ์ƒ‰์„ ๋” ์–ด๋‘์šด ํšŒ์ƒ‰์œผ๋กœ ๋ณ€๊ฒฝ */
183
  color: #000; /* ์„ ํƒ๋œ ํƒญ์˜ ๊ธ€์ž์ƒ‰์„ ๊ฒ€์ •์ƒ‰์œผ๋กœ ๋ณ€๊ฒฝ */
184
  border-bottom: 2px solid #007BFF; /* ์„ ํƒ๋œ ํƒญ์˜ ํ•˜๋‹จ ํ…Œ๋‘๋ฆฌ ์Šคํƒ€์ผ */
185
  }
186
-
187
  /* ํƒญ ์ปจํ…์ธ  ์˜์—ญ ์Šคํƒ€์ผ */
188
  .tab-content {
189
  border: 1px solid #dcdcdc; /* ํƒญ ์ปจํ…์ธ  ์˜์—ญ์˜ ํ…Œ๋‘๋ฆฌ ์ƒ‰์ƒ */
190
  background-color: #f9f9f9; /* ํƒญ ์ปจํ…์ธ  ์˜์—ญ์˜ ๋ฐฐ๊ฒฝ์ƒ‰ */
191
  }
192
-
193
  /* ์ž…๋ ฅ ํผ ๋ฐ ์ถœ๋ ฅ ํผ ์Šคํƒ€์ผ๋ง */
194
  .input, .output {
195
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); /* ์ž…์ฒด๊ฐ์„ ์ฃผ๋Š” ๊ทธ๋ฆผ์ž ์ถ”๊ฐ€ */
196
  border: 2px solid #17a2b8; /* ์ปฌ๋Ÿฌ ํ…Œ๋‘๋ฆฌ ์ ์šฉ */
197
  border-radius: 5px; /* ํ…Œ๋‘๋ฆฌ ๋‘ฅ๊ธ€๊ฒŒ */
198
  }
199
-
200
  .input:hover, .output:hover {
201
  box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2); /* ํ˜ธ๋ฒ„ ์‹œ ๋” ํฐ ๊ทธ๋ฆผ์ž ํšจ๊ณผ */
202
  }
203
-
204
  /* ํƒ€์ดํ‹€๊ณผ ์„ค๋ช…๊ธ€ ๊ฐ€์šด๋ฐ ์ •๋ ฌ ์ถ”๊ฐ€ */
205
  .markdown {
206
  text-align: center; /* ํ…์ŠคํŠธ๋ฅผ ๊ฐ€์šด๋ฐ ์ •๋ ฌ */
207
-
208
  }
209
  /* ๊ฒฐ๊ณผ ์ถœ๋ ฅ ์ปดํฌ๋„ŒํŠธ์˜ ๊ธ€์ž ํฌ๊ธฐ 3๋ฐฐ๋กœ ์กฐ์ • */
210
  .output {
211
  font-size: 300%; /* ๊ธฐ๋ณธ ๊ธ€์ž ํฌ๊ธฐ์˜ 2๋ฐฐ */
212
  }
213
-
214
  /* ํƒญ ํด๋ฆญ ์‹œ ๋ˆŒ๋ฆฐ ํƒญ์— ์ ์šฉ๋  ์Šคํƒ€์ผ */
215
  .tab_button.selected {
216
  background-color: #007BFF; /* ์„ ํƒ๋œ ํƒญ์˜ ๋ฐฐ๊ฒฝ์ƒ‰์„ ๋ณ€๊ฒฝ */
@@ -232,6 +233,8 @@ with gr.Blocks(css=css, title="์ฝ”๋ ˆ์ดํŒ… ์…€ํ”„ ์ง„๋‹จ ์„œ๋น„์Šค") as demo:
232
  contact_phone = gr.Textbox(label="์—ฐ๋ฝ์ฒ˜")
233
  contact_email = gr.Textbox(label="์ด๋ฉ”์ผ ์ฃผ์†Œ")
234
 
 
 
235
  with gr.Tab("1๋‹จ๊ณ„"):
236
  answer1 = gr.Radio(choices=options[0], label=questions[0])
237
  answer2 = gr.Radio(choices=options[1], label=questions[1])
@@ -272,19 +275,20 @@ with gr.Blocks(css=css, title="์ฝ”๋ ˆ์ดํŒ… ์…€ํ”„ ์ง„๋‹จ ์„œ๋น„์Šค") as demo:
272
  answer30 = gr.Radio(choices=options[29], label=questions[29])
273
  answer31 = gr.Radio(choices=options[30], label=questions[30])
274
  answer32 = gr.Radio(choices=options[31], label=questions[31])
275
-
 
276
 
277
  submit_btn = gr.Button("์…€ํ”„ ์ง„๋‹จ ์„œ๋น„์Šค ๊ฒฐ๊ณผ ๋ณด๊ธฐ")
278
  score_output = gr.Number(label="์ด์ (73์  ๋งŒ์ )")
279
  grade_output = gr.Text(label="๋“ฑ๊ธ‰")
280
  definition_output = gr.Textbox(label="๋“ฑ๊ธ‰ ์ •์˜: ์…€ํ”„์ง„๋‹จ ๊ฒฐ๊ณผ๋Š” ์ดค์†Œํ•œ์˜ ํ•ญ๋ชฉ์— ์‚ฌ์šฉ์ž์˜ ์ž„์˜์  ๋‹ต๋ณ€์— ๊ธฐ๋ฐ˜ํ•œ ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋ณธ ๊ฒฐ๊ณผ๋Š” ์ฝ”๋ ˆ์ดํŒ…์˜ ๊ณต์‹ ํ‰๊ฐ€ ๊ฒฐ๊ณผ๊ฐ€ ์•„๋‹˜์„ ์•Œ๋ ค๋“œ๋ฆฝ๋‹ˆ๋‹ค.")
281
 
 
 
282
  submit_btn.click(
283
- fn=calculate_score,
284
- inputs=[answer1, answer2, answer3, answer4, answer5, answer6, answer7, answer8, answer9, answer10, answer11, answer12, answer13, answer14, answer15, answer16, answer17, answer18, answer19, answer20, answer21, answer22, answer23, answer24, answer25, answer26, answer27, answer28, answer29, answer30, answer31, answer32],
285
  outputs=[score_output, grade_output, definition_output]
286
  )
287
 
288
- demo.launch()
289
-
290
-
 
106
  [3, 2, 1, 0]
107
  ]
108
 
109
+
110
+
111
+ def calculate_score(project_info, answers):
112
+ total_score = 0
113
+ for i, answer in enumerate(answers):
114
+ if answer is not None:
115
+ try:
116
+ answer_index = options[i].index(answer)
117
+ total_score += scores[i][answer_index]
118
+ except ValueError:
119
+ print(f"Invalid answer: {answer} for question {i+1}")
120
+ else:
121
+ print(f"No answer for question {i+1}, assigning score of 0.")
122
  grade, definition = get_grade(total_score)
123
+
124
+ # Zapier Webhook์œผ๋กœ ๋ฐ์ดํ„ฐ ์ „์†ก
125
  webhook_url = "https://hooks.zapier.com/hooks/catch/14523965/3egrs04/"
126
  data = {
127
+ "project_name": project_info[0],
128
+ "contact_name": project_info[1],
129
+ "contact_email": project_info[2],
130
+ "contact_phone": project_info[3],
131
  "responses": answers # ์‚ฌ์šฉ์ž์˜ ์‘๋‹ต๋“ค
132
  }
133
  response = requests.post(webhook_url, json=data)
134
+
135
  if response.status_code == 200:
136
  print("Data sent to Zapier successfully.")
137
  else:
 
139
  return total_score, grade, definition
140
 
141
 
142
+
143
  def get_grade(total_score):
144
  converted_score = (total_score)
145
 
 
162
  footer {
163
  visibility: hidden;
164
  }
 
165
  /* ๋ฒ„ํŠผ ์Šคํƒ€์ผ๋ง */
166
  button {
167
  background: linear-gradient(135deg, #007BFF, #004085);
 
175
  cursor: pointer;
176
  transition: background 0.5s ease;
177
  }
 
178
  button:hover {
179
  background: linear-gradient(135deg, #0056b3, #002752);
180
  }
 
 
 
181
  /* ํƒญ ์ƒ‰๊น” ๋ณ€๊ฒฝ์„ ์œ„ํ•œ CSS */
182
  /* ํƒญ ๋ฒ„ํŠผ ์Šคํƒ€์ผ */
183
  .tab-container .tab {
184
  background-color: #f0f0f0; /* ์—ฐํ•œ ํšŒ์ƒ‰์œผ๋กœ ๋ฐฐ๊ฒฝ์ƒ‰ ๋ณ€๊ฒฝ */
185
  color: #333; /* ๊ธ€์ž์ƒ‰ ๋ณ€๊ฒฝ */
186
  }
 
187
  /* ์„ ํƒ๋œ ํƒญ ์Šคํƒ€์ผ */
188
  .tab-container .tab.selected {
189
  background-color: #d9d9d9; /* ์„ ํƒ๋œ ํƒญ์˜ ๋ฐฐ๊ฒฝ์ƒ‰์„ ๋” ์–ด๋‘์šด ํšŒ์ƒ‰์œผ๋กœ ๋ณ€๊ฒฝ */
190
  color: #000; /* ์„ ํƒ๋œ ํƒญ์˜ ๊ธ€์ž์ƒ‰์„ ๊ฒ€์ •์ƒ‰์œผ๋กœ ๋ณ€๊ฒฝ */
191
  border-bottom: 2px solid #007BFF; /* ์„ ํƒ๋œ ํƒญ์˜ ํ•˜๋‹จ ํ…Œ๋‘๋ฆฌ ์Šคํƒ€์ผ */
192
  }
 
193
  /* ํƒญ ์ปจํ…์ธ  ์˜์—ญ ์Šคํƒ€์ผ */
194
  .tab-content {
195
  border: 1px solid #dcdcdc; /* ํƒญ ์ปจํ…์ธ  ์˜์—ญ์˜ ํ…Œ๋‘๋ฆฌ ์ƒ‰์ƒ */
196
  background-color: #f9f9f9; /* ํƒญ ์ปจํ…์ธ  ์˜์—ญ์˜ ๋ฐฐ๊ฒฝ์ƒ‰ */
197
  }
 
198
  /* ์ž…๋ ฅ ํผ ๋ฐ ์ถœ๋ ฅ ํผ ์Šคํƒ€์ผ๋ง */
199
  .input, .output {
200
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); /* ์ž…์ฒด๊ฐ์„ ์ฃผ๋Š” ๊ทธ๋ฆผ์ž ์ถ”๊ฐ€ */
201
  border: 2px solid #17a2b8; /* ์ปฌ๋Ÿฌ ํ…Œ๋‘๋ฆฌ ์ ์šฉ */
202
  border-radius: 5px; /* ํ…Œ๋‘๋ฆฌ ๋‘ฅ๊ธ€๊ฒŒ */
203
  }
 
204
  .input:hover, .output:hover {
205
  box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2); /* ํ˜ธ๋ฒ„ ์‹œ ๋” ํฐ ๊ทธ๋ฆผ์ž ํšจ๊ณผ */
206
  }
 
207
  /* ํƒ€์ดํ‹€๊ณผ ์„ค๋ช…๊ธ€ ๊ฐ€์šด๋ฐ ์ •๋ ฌ ์ถ”๊ฐ€ */
208
  .markdown {
209
  text-align: center; /* ํ…์ŠคํŠธ๋ฅผ ๊ฐ€์šด๋ฐ ์ •๋ ฌ */
 
210
  }
211
  /* ๊ฒฐ๊ณผ ์ถœ๋ ฅ ์ปดํฌ๋„ŒํŠธ์˜ ๊ธ€์ž ํฌ๊ธฐ 3๋ฐฐ๋กœ ์กฐ์ • */
212
  .output {
213
  font-size: 300%; /* ๊ธฐ๋ณธ ๊ธ€์ž ํฌ๊ธฐ์˜ 2๋ฐฐ */
214
  }
 
215
  /* ํƒญ ํด๋ฆญ ์‹œ ๋ˆŒ๋ฆฐ ํƒญ์— ์ ์šฉ๋  ์Šคํƒ€์ผ */
216
  .tab_button.selected {
217
  background-color: #007BFF; /* ์„ ํƒ๋œ ํƒญ์˜ ๋ฐฐ๊ฒฝ์ƒ‰์„ ๋ณ€๊ฒฝ */
 
233
  contact_phone = gr.Textbox(label="์—ฐ๋ฝ์ฒ˜")
234
  contact_email = gr.Textbox(label="์ด๋ฉ”์ผ ์ฃผ์†Œ")
235
 
236
+
237
+
238
  with gr.Tab("1๋‹จ๊ณ„"):
239
  answer1 = gr.Radio(choices=options[0], label=questions[0])
240
  answer2 = gr.Radio(choices=options[1], label=questions[1])
 
275
  answer30 = gr.Radio(choices=options[29], label=questions[29])
276
  answer31 = gr.Radio(choices=options[30], label=questions[30])
277
  answer32 = gr.Radio(choices=options[31], label=questions[31])
278
+
279
+
280
 
281
  submit_btn = gr.Button("์…€ํ”„ ์ง„๋‹จ ์„œ๋น„์Šค ๊ฒฐ๊ณผ ๋ณด๊ธฐ")
282
  score_output = gr.Number(label="์ด์ (73์  ๋งŒ์ )")
283
  grade_output = gr.Text(label="๋“ฑ๊ธ‰")
284
  definition_output = gr.Textbox(label="๋“ฑ๊ธ‰ ์ •์˜: ์…€ํ”„์ง„๋‹จ ๊ฒฐ๊ณผ๋Š” ์ดค์†Œํ•œ์˜ ํ•ญ๋ชฉ์— ์‚ฌ์šฉ์ž์˜ ์ž„์˜์  ๋‹ต๋ณ€์— ๊ธฐ๋ฐ˜ํ•œ ๊ฒฐ๊ณผ์ž…๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋ณธ ๊ฒฐ๊ณผ๋Š” ์ฝ”๋ ˆ์ดํŒ…์˜ ๊ณต์‹ ํ‰๊ฐ€ ๊ฒฐ๊ณผ๊ฐ€ ์•„๋‹˜์„ ์•Œ๋ ค๋“œ๋ฆฝ๋‹ˆ๋‹ค.")
285
 
286
+
287
+
288
  submit_btn.click(
289
+ fn=lambda project_name, contact_name, contact_phone, contact_email, *answers: calculate_score([project_name, contact_name, contact_phone, contact_email], answers),
290
+ inputs=[project_name, contact_name, contact_phone, contact_email] + [answer1, answer2, answer3, answer4, answer5, answer6, answer7, answer8, answer9, answer10, answer11, answer12, answer13, answer14, answer15, answer16, answer17, answer18, answer19, answer20, answer21, answer22, answer23, answer24, answer25, answer26, answer27, answer28, answer29, answer30, answer31, answer32],
291
  outputs=[score_output, grade_output, definition_output]
292
  )
293
 
294
+ demo.launch()