Spaces:
Runtime error
Runtime error
Yoon-gu Hwang
commited on
Commit
β’
766c5e5
1
Parent(s):
04b5b70
multiple choice
Browse files
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 =
|
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 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
|
|
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:
|