yoon-gu commited on
Commit
00166b0
1 Parent(s): 97b3e3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -1,10 +1,13 @@
1
  import os
2
- os.system("pip install gradio==3.47.1")
3
  import gradio as gr
4
  import pandas as pd
5
  import random
6
  import json
7
  import time
 
 
 
 
8
 
9
  with open('pokemon.json', 'r') as f:
10
  pokemons = json.load(f)
@@ -35,7 +38,12 @@ def get_question_answer(pokemons_set):
35
  a = QUESTION_TEMPLATE['answer'].format(name=name)
36
  return q, a
37
 
38
- info = {u: {"done" : True, "score": 0, "count": 0, "best_score": 0, "best_time": float("inf"), "time": 0.0} for u in USERS}
 
 
 
 
 
39
 
40
  MD = """# 포켓몬 퀴즈
41
  ## 공부 방법
@@ -135,6 +143,11 @@ with gr.Blocks() as demo:
135
  if info[user]['score'] >= info[user]['best_score']:
136
  info[user]['best_score'] = info[user]['score']
137
  info[user]['best_time'] = min(time.time() - info[user]['time'], info[user]['best_time'])
 
 
 
 
 
138
 
139
  chat_history.append((message, bot_message))
140
 
 
1
  import os
 
2
  import gradio as gr
3
  import pandas as pd
4
  import random
5
  import json
6
  import time
7
+ import wandb
8
+
9
+ wandb.login(key=os.environ['WANDB_KEY'])
10
+ run = wandb.init(project="pokemon-quiz", entity="yoon-gu")
11
 
12
  with open('pokemon.json', 'r') as f:
13
  pokemons = json.load(f)
 
38
  a = QUESTION_TEMPLATE['answer'].format(name=name)
39
  return q, a
40
 
41
+ try:
42
+ folder = run.use_artifact("settings:latest").download()
43
+ with open(os.path.join(folder, "info.json"), "r") as f:
44
+ info = json.load(f)
45
+ except:
46
+ info = {u: {"done" : True, "score": 0, "count": 0, "best_score": 0, "best_time": float("inf"), "time": 0.0} for u in USERS}
47
 
48
  MD = """# 포켓몬 퀴즈
49
  ## 공부 방법
 
143
  if info[user]['score'] >= info[user]['best_score']:
144
  info[user]['best_score'] = info[user]['score']
145
  info[user]['best_time'] = min(time.time() - info[user]['time'], info[user]['best_time'])
146
+ with open("info.json", "w") as f:
147
+ json.dump(info, f, indent=4)
148
+ artifact = wandb.Artifact("settings", type="info")
149
+ artifact.add_file("info.json")
150
+ run.log_artifact(artifact)
151
 
152
  chat_history.append((message, bot_message))
153