Yoon-gu Hwang commited on
Commit
766c5e5
β€’
1 Parent(s): 04b5b70

multiple choice

Browse files
Files changed (1) hide show
  1. app.py +15 -7
app.py CHANGED
@@ -13,7 +13,7 @@ run = wandb.init(project="pokemon-quiz", entity="yoon-gu")
13
 
14
  with open('pokemon.json', 'r') as f:
15
  pokemons = json.load(f)
16
- pokemons_types = ["λͺ¨λ“  νƒ€μž…"] + sorted(set([t for poke in pokemons for t in poke['types']]))
17
  df = pd.DataFrame(pokemons)
18
  GEN_RANGE = {
19
  "λͺ¨λ“  μ„ΈλŒ€": [1, 1017],
@@ -90,13 +90,15 @@ with gr.Blocks() as demo:
90
  with gr.Column():
91
  with gr.Row():
92
  generation = gr.Dropdown(
93
- [f"{k}μ„ΈλŒ€" for k in range(1, 10)] + ["λͺ¨λ“  μ„ΈλŒ€"],
94
- value="λͺ¨λ“  μ„ΈλŒ€",
 
95
  label="포켓λͺ¬ μ„ΈλŒ€",
96
  info="μ›ν•˜λŠ” 포켓λͺ¬ μ„ΈλŒ€λ₯Ό μ„ νƒν•˜μ„Έμš”."
97
  )
98
  poke_types = gr.Dropdown(
99
- pokemons_types, value="λͺ¨λ“  νƒ€μž…",
 
100
  label="포켓λͺ¬ νƒ€μž…",
101
  info="μ›ν•˜λŠ” 포켓λͺ¬ νƒ€μž…μ„ μ„ νƒν•˜μ„Έμš”."
102
  )
@@ -119,9 +121,13 @@ with gr.Blocks() as demo:
119
  raise gr.Error("μ‚¬μš©μž 이름을 μž…λ ₯ν•˜μ„Έμš”.")
120
  message = message.strip()
121
  done = infos[user].done
122
- start, end = GEN_RANGE[gen]
123
- sdf = df[start:end]
124
- pokemons_set = sdf[sdf['types'].apply(lambda x: (types in x)) | (types == "λͺ¨λ“  νƒ€μž…")]
 
 
 
 
125
  pokemons_set = pokemons_set.to_dict("records")
126
  if done:
127
  infos[user].history = []
@@ -133,6 +139,8 @@ with gr.Blocks() as demo:
133
  infos[user].score = 0
134
  infos[user].count = 0
135
  infos[user].time = time.time()
 
 
136
  else:
137
  bot_message = "ν€΄μ¦ˆλ₯Ό μ‹œμž‘ν•˜κ³  μ‹ΆμœΌμ‹œλ©΄, **ν€΄μ¦ˆ μ‹œμž‘** λ²„νŠΌμ„ λˆ„λ₯΄μ„Έμš”."
138
  else:
 
13
 
14
  with open('pokemon.json', 'r') as f:
15
  pokemons = json.load(f)
16
+ pokemons_types = sorted(set([t for poke in pokemons for t in poke['types']]))
17
  df = pd.DataFrame(pokemons)
18
  GEN_RANGE = {
19
  "λͺ¨λ“  μ„ΈλŒ€": [1, 1017],
 
90
  with gr.Column():
91
  with gr.Row():
92
  generation = gr.Dropdown(
93
+ [f"{k}μ„ΈλŒ€" for k in range(1, 10)],
94
+ value=[f"{k}μ„ΈλŒ€" for k in range(1, 10)],
95
+ multiselect=True,
96
  label="포켓λͺ¬ μ„ΈλŒ€",
97
  info="μ›ν•˜λŠ” 포켓λͺ¬ μ„ΈλŒ€λ₯Ό μ„ νƒν•˜μ„Έμš”."
98
  )
99
  poke_types = gr.Dropdown(
100
+ pokemons_types, value=pokemons_types,
101
+ multiselect=True,
102
  label="포켓λͺ¬ νƒ€μž…",
103
  info="μ›ν•˜λŠ” 포켓λͺ¬ νƒ€μž…μ„ μ„ νƒν•˜μ„Έμš”."
104
  )
 
121
  raise gr.Error("μ‚¬μš©μž 이름을 μž…λ ₯ν•˜μ„Έμš”.")
122
  message = message.strip()
123
  done = infos[user].done
124
+
125
+ dfs = []
126
+ for g in gen:
127
+ start, end = GEN_RANGE[g]
128
+ dfs.append(df[start-1:end])
129
+ sdf = pd.concat(dfs)
130
+ pokemons_set = sdf[sdf['types'].apply(lambda x: any([t in x for t in types]))]
131
  pokemons_set = pokemons_set.to_dict("records")
132
  if done:
133
  infos[user].history = []
 
139
  infos[user].score = 0
140
  infos[user].count = 0
141
  infos[user].time = time.time()
142
+ infos[user].generations = gen
143
+ infos[user].types = types
144
  else:
145
  bot_message = "ν€΄μ¦ˆλ₯Ό μ‹œμž‘ν•˜κ³  μ‹ΆμœΌμ‹œλ©΄, **ν€΄μ¦ˆ μ‹œμž‘** λ²„νŠΌμ„ λˆ„λ₯΄μ„Έμš”."
146
  else: