Yoon-gu Hwang commited on
Commit
21ef542
β€’
1 Parent(s): 9c8b9fe
Files changed (1) hide show
  1. app.py +21 -12
app.py CHANGED
@@ -109,12 +109,7 @@ with gr.Blocks() as demo:
109
  info[user]['score'] += 1
110
  info[user]['count'] += 1
111
  bot_message = f"πŸŽ‰μ •λ‹΅μž…λ‹ˆλ‹€! λ‹€μŒ λ¬Έμ œμž…λ‹ˆλ‹€.\n{q}\n- ν˜„μž¬ 점수: {info[user]['score']}점\n- μ†Œμš” μ‹œκ°„: {time.time() - info[user]['time']:4.3f}초"
112
- if quiz_count == info[user]['count']:
113
- bot_message = f"λͺ¨λ“  ν€΄μ¦ˆλ₯Ό λ‹€ ν’€μ—ˆμŠ΅λ‹ˆλ‹€. μ μˆ˜λŠ” {info[user]['score']:3.1f}점 μž…λ‹ˆλ‹€."
114
- info[user]['done'] = True
115
- if info[user]['score'] >= info[user]['best_score']:
116
- info[user]['best_score'] = info[user]['score']
117
- info[user]['best_time'] = min(time.time() - info[user]['time'], info[user]['best_time'])
118
  elif "ν€΄μ¦ˆμ’…λ£Œ" == message.replace(" ", ""):
119
  bot_message = f"ν€΄μ¦ˆλ₯Ό κ°•μ œ μ’…λ£Œν•©λ‹ˆλ‹€."
120
  info[user]['done'] = True
@@ -135,9 +130,21 @@ with gr.Blocks() as demo:
135
  hint1 += "X"
136
  bot_message = f"***{message}***!? 🧐 λ‹€μ‹œ ν•œλ²ˆ μƒκ°ν•΄λ³΄μ„Έμš”.\n힌트: {hint1}"
137
  info[user]['score'] -= 0.1
 
 
 
 
 
 
 
138
 
139
  chat_history.append((message, bot_message))
140
- return "", chat_history, MD.format(content='\n'.join([f"- {u}({v['best_score']:3.1f}점, {v['best_time']:3.1f}초)" for u, v in info.items()]))
 
 
 
 
 
141
 
142
  play.click(respond,
143
  inputs=[play, chatbot, user, quiz_count, generation, poke_types],
@@ -148,11 +155,13 @@ with gr.Blocks() as demo:
148
  stop.click(respond,
149
  inputs=[stop, chatbot, user, quiz_count, generation, poke_types],
150
  outputs=[msg, chatbot, markdown])
151
- leader_board = sorted(info.items(), key=lambda x: (x[1]['best_score'], -x[1]['best_time']), reverse=True)
152
- lbdf = pd.DataFrame([dict(**a[1], name=a[0]) for a in leader_board])
153
- lbdf.index += 1
154
- md = lbdf[['name', 'best_score', 'best_time']].to_markdown()
155
- demo.load(lambda : MD.format(content=md),
 
 
156
  inputs=None,
157
  outputs=markdown)
158
  msg.submit(respond, [msg, chatbot, user, quiz_count, generation, poke_types], [msg, chatbot, markdown])
 
109
  info[user]['score'] += 1
110
  info[user]['count'] += 1
111
  bot_message = f"πŸŽ‰μ •λ‹΅μž…λ‹ˆλ‹€! λ‹€μŒ λ¬Έμ œμž…λ‹ˆλ‹€.\n{q}\n- ν˜„μž¬ 점수: {info[user]['score']}점\n- μ†Œμš” μ‹œκ°„: {time.time() - info[user]['time']:4.3f}초"
112
+
 
 
 
 
 
113
  elif "ν€΄μ¦ˆμ’…λ£Œ" == message.replace(" ", ""):
114
  bot_message = f"ν€΄μ¦ˆλ₯Ό κ°•μ œ μ’…λ£Œν•©λ‹ˆλ‹€."
115
  info[user]['done'] = True
 
130
  hint1 += "X"
131
  bot_message = f"***{message}***!? 🧐 λ‹€μ‹œ ν•œλ²ˆ μƒκ°ν•΄λ³΄μ„Έμš”.\n힌트: {hint1}"
132
  info[user]['score'] -= 0.1
133
+
134
+ if quiz_count == info[user]['count']:
135
+ bot_message = f"λͺ¨λ“  ν€΄μ¦ˆλ₯Ό λ‹€ ν’€μ—ˆμŠ΅λ‹ˆλ‹€. μ μˆ˜λŠ” {info[user]['score']:3.1f}점 μž…λ‹ˆλ‹€."
136
+ info[user]['done'] = True
137
+ if info[user]['score'] >= info[user]['best_score']:
138
+ info[user]['best_score'] = info[user]['score']
139
+ info[user]['best_time'] = min(time.time() - info[user]['time'], info[user]['best_time'])
140
 
141
  chat_history.append((message, bot_message))
142
+
143
+ leader_board = sorted(info.items(), key=lambda x: (x[1]['best_score'], -x[1]['best_time']), reverse=True)
144
+ lbdf = pd.DataFrame([dict(**a[1], name=a[0]) for a in leader_board])
145
+ lbdf.index += 1
146
+ md = lbdf[['name', 'best_score', 'best_time']].to_markdown()
147
+ return "", chat_history, MD.format(content=md)
148
 
149
  play.click(respond,
150
  inputs=[play, chatbot, user, quiz_count, generation, poke_types],
 
155
  stop.click(respond,
156
  inputs=[stop, chatbot, user, quiz_count, generation, poke_types],
157
  outputs=[msg, chatbot, markdown])
158
+ def update_table():
159
+ leader_board = sorted(info.items(), key=lambda x: (x[1]['best_score'], -x[1]['best_time']), reverse=True)
160
+ lbdf = pd.DataFrame([dict(**a[1], name=a[0]) for a in leader_board])
161
+ lbdf.index += 1
162
+ md = lbdf[['name', 'best_score', 'best_time']].to_markdown()
163
+ return MD.format(content=md)
164
+ demo.load(update_table,
165
  inputs=None,
166
  outputs=markdown)
167
  msg.submit(respond, [msg, chatbot, user, quiz_count, generation, poke_types], [msg, chatbot, markdown])