Yoon-gu Hwang commited on
Commit
6d1bed2
1 Parent(s): 385222f

file 없이도 구현 가능

Browse files
Files changed (1) hide show
  1. app.py +6 -12
app.py CHANGED
@@ -50,9 +50,6 @@ MD = """# 포켓몬 퀴즈
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():
@@ -82,7 +79,7 @@ with gr.Blocks() as demo:
82
  pokemons_set = sdf[sdf['types'].apply(lambda x: (types in x)) | (types == "모든 타입")]
83
  pokemons_set = pokemons_set.to_dict("records")
84
  if done:
85
- if "퀴즈 시작" == message:
86
  q, a = get_question_answer(pokemons_set)
87
  bot_message = f"퀴즈를 시작합니다.\n{q}"
88
  answer.value = a
@@ -98,19 +95,16 @@ with gr.Blocks() as demo:
98
  info[user]['count'] += 1
99
  bot_message = f"🎉정답입니다! 다음 문제입니다.\n{q}"
100
  if quiz_count == info[user]['count']:
101
- bot_message = f"모든 퀴즈를 다 풀었습니다. 점수는 {info[user]['score']}점 입니다."
 
 
 
 
102
  else:
103
  bot_message = f"***{message}***!? 🧐 다시 한번 생각해보세요."
104
  info[user]['score'] -= 0.1
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()])),
 
50
  """
51
 
52
  with gr.Blocks() as demo:
 
 
 
53
  answer = gr.State(value="")
54
  with gr.Row():
55
  with gr.Column():
 
79
  pokemons_set = sdf[sdf['types'].apply(lambda x: (types in x)) | (types == "모든 타입")]
80
  pokemons_set = pokemons_set.to_dict("records")
81
  if done:
82
+ if "퀴즈시작" == message.replace(" ", ""):
83
  q, a = get_question_answer(pokemons_set)
84
  bot_message = f"퀴즈를 시작합니다.\n{q}"
85
  answer.value = a
 
95
  info[user]['count'] += 1
96
  bot_message = f"🎉정답입니다! 다음 문제입니다.\n{q}"
97
  if quiz_count == info[user]['count']:
98
+ bot_message = f"모든 퀴즈를 다 풀었습니다. 점수는 {info[user]['score']:3.1f}점 입니다."
99
+ elif "퀴즈종료" == message.replace(" ", ""):
100
+ bot_message = f"퀴즈를 강제 종료합니다."
101
+ info[user]['done'] = True
102
+ info[user]['score'] = 0
103
  else:
104
  bot_message = f"***{message}***!? 🧐 다시 한번 생각해보세요."
105
  info[user]['score'] -= 0.1
106
 
107
  chat_history.append((message, bot_message))
 
 
 
 
 
 
 
108
  return "", chat_history, MD.format(content='\n'.join([f"- {u}({v['score']:3.1f}점)" for u, v in info.items()]))
109
 
110
  demo.load(lambda : MD.format(content='\n'.join([f"- {u}({v['score']:3.1f}점)" for u, v in info.items()])),