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)