Yoon-gu Hwang commited on
Commit
385222f
โ€ข
1 Parent(s): 4b5f2cf
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -36,6 +36,7 @@ def get_question_answer(pokemons_set):
36
  return q, a
37
 
38
  info = {u: {"done" : True, "score": 0, "count": 0} for u in USERS}
 
39
  MD = """# ํฌ์ผ“๋ชฌ ํ€ด์ฆˆ
40
  ## ์‚ฌ์šฉ๋ฐฉ๋ฒ•
41
 
@@ -47,11 +48,15 @@ MD = """# ํฌ์ผ“๋ชฌ ํ€ด์ฆˆ
47
  ## ์ ์ˆ˜ํŒ
48
  {content}
49
  """
 
50
  with gr.Blocks() as demo:
 
 
 
51
  answer = gr.State(value="")
52
  with gr.Row():
53
  with gr.Column():
54
- markdown = gr.Markdown(MD.format(content=""))
55
  user = gr.Radio(USERS, value="Dummy", label="์‚ฌ์šฉ์ž", info="๋‹น์‹ ์€ ๋ˆ„๊ตฌ์‹ ๊ฐ€์š”?")
56
  quiz_count = gr.Radio([10, 20, 30], value=10, label="์ด ํ€ด์ฆˆ ๊ฐœ์ˆ˜", info="ํ€ด์ฆˆ๋ฅผ ๋ช‡ ๊ฐœ ํ’€ ์˜ˆ์ •์ธ๊ฐ€์š”?")
57
  with gr.Column():
@@ -69,10 +74,8 @@ with gr.Blocks() as demo:
69
  )
70
  chatbot = gr.Chatbot(bubble_full_width=False)
71
  msg = gr.Textbox(value="ํ€ด์ฆˆ ์‹œ์ž‘", label="๋‹ต")
72
- clear = gr.ClearButton([msg, chatbot])
73
 
74
  def respond(user, quiz_count, gen, types, message, chat_history, request: gr.Request):
75
- global info
76
  done = info[user]['done']
77
  start, end = GEN_RANGE[gen]
78
  sdf = df[start:end]
@@ -102,8 +105,17 @@ with gr.Blocks() as demo:
102
 
103
  chat_history.append((message, bot_message))
104
  print(info)
105
- return "", chat_history, MD.format(content='\n'.join([f"- {user}({info[user]['score']}์ )"]))
 
 
 
 
 
 
106
 
 
 
 
107
  msg.submit(respond, [user, quiz_count, generation, poke_types, msg, chatbot], [msg, chatbot, markdown])
108
 
109
  demo.queue(concurrency_count=1)
 
36
  return q, a
37
 
38
  info = {u: {"done" : True, "score": 0, "count": 0} for u in USERS}
39
+
40
  MD = """# ํฌ์ผ“๋ชฌ ํ€ด์ฆˆ
41
  ## ์‚ฌ์šฉ๋ฐฉ๋ฒ•
42
 
 
48
  ## ์ ์ˆ˜ํŒ
49
  {content}
50
  """
51
+
52
  with gr.Blocks() as demo:
53
+ if os.path.exists('info.json'):
54
+ with open('info.json', 'r') as f:
55
+ info = json.load(f)
56
  answer = gr.State(value="")
57
  with gr.Row():
58
  with gr.Column():
59
+ markdown = gr.Markdown(MD.format(content='\n'.join([f"- {u}({v['score']:3.1f}์ )" for u, v in info.items()])))
60
  user = gr.Radio(USERS, value="Dummy", label="์‚ฌ์šฉ์ž", info="๋‹น์‹ ์€ ๋ˆ„๊ตฌ์‹ ๊ฐ€์š”?")
61
  quiz_count = gr.Radio([10, 20, 30], value=10, label="์ด ํ€ด์ฆˆ ๊ฐœ์ˆ˜", info="ํ€ด์ฆˆ๋ฅผ ๋ช‡ ๊ฐœ ํ’€ ์˜ˆ์ •์ธ๊ฐ€์š”?")
62
  with gr.Column():
 
74
  )
75
  chatbot = gr.Chatbot(bubble_full_width=False)
76
  msg = gr.Textbox(value="ํ€ด์ฆˆ ์‹œ์ž‘", label="๋‹ต")
 
77
 
78
  def respond(user, quiz_count, gen, types, message, chat_history, request: gr.Request):
 
79
  done = info[user]['done']
80
  start, end = GEN_RANGE[gen]
81
  sdf = df[start:end]
 
105
 
106
  chat_history.append((message, bot_message))
107
  print(info)
108
+ with open('info.json', 'w') as f:
109
+ json.dump(info, f, ensure_ascii=False, indent=4)
110
+ with open('info.json', 'r') as f:
111
+ info_ = json.load(f)
112
+ from pprint import pprint
113
+ pprint(info_)
114
+ return "", chat_history, MD.format(content='\n'.join([f"- {u}({v['score']:3.1f}์ )" for u, v in info.items()]))
115
 
116
+ demo.load(lambda : MD.format(content='\n'.join([f"- {u}({v['score']:3.1f}์ )" for u, v in info.items()])),
117
+ inputs=None,
118
+ outputs=markdown)
119
  msg.submit(respond, [user, quiz_count, generation, poke_types, msg, chatbot], [msg, chatbot, markdown])
120
 
121
  demo.queue(concurrency_count=1)