Javierss
commited on
Commit
•
2d20748
1
Parent(s):
ed4f43e
Add word check
Browse files- .gitattributes +1 -0
- .gitignore +1 -1
- __pycache__/app.cpython-311.pyc +0 -0
- __pycache__/game_transformer.cpython-311.pyc +0 -0
- __pycache__/game_word2vec.cpython-311.pyc +0 -0
- __pycache__/hints.cpython-311.pyc +0 -0
- app.py +14 -3
- app_trans.py +173 -149
- config/words.txt +3 -0
- data/plays/__init__.py +0 -0
- data/ranking.txt +1 -1
- game.py → game_transformer.py +35 -6
- game_word2vec.py +6 -3
.gitattributes
CHANGED
@@ -36,3 +36,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
36 |
*.gif filter=lfs diff=lfs merge=lfs -text
|
37 |
config/w2v_models/esp_w2v_model filter=lfs diff=lfs merge=lfs -text
|
38 |
config/w2v_models/eng_w2v_model filter=lfs diff=lfs merge=lfs -text
|
|
|
|
36 |
*.gif filter=lfs diff=lfs merge=lfs -text
|
37 |
config/w2v_models/esp_w2v_model filter=lfs diff=lfs merge=lfs -text
|
38 |
config/w2v_models/eng_w2v_model filter=lfs diff=lfs merge=lfs -text
|
39 |
+
config/words.txt filter=lfs diff=lfs merge=lfs -text
|
.gitignore
CHANGED
@@ -1 +1 @@
|
|
1 |
-
data/plays
|
|
|
1 |
+
data/plays/*.txt
|
__pycache__/app.cpython-311.pyc
CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
|
|
__pycache__/game_transformer.cpython-311.pyc
ADDED
Binary file (13.8 kB). View file
|
|
__pycache__/game_word2vec.cpython-311.pyc
CHANGED
Binary files a/__pycache__/game_word2vec.cpython-311.pyc and b/__pycache__/game_word2vec.cpython-311.pyc differ
|
|
__pycache__/hints.cpython-311.pyc
CHANGED
Binary files a/__pycache__/hints.cpython-311.pyc and b/__pycache__/hints.cpython-311.pyc differ
|
|
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
from game_word2vec import Semantrix as semantrix_word2vec
|
4 |
-
from
|
5 |
|
6 |
|
7 |
config_file_path = "config/lang.json"
|
@@ -256,7 +256,12 @@ with gr.Blocks() as demo:
|
|
256 |
gr.Radio(label="", visible=False),
|
257 |
gr.Textbox(visible=False, label=""),
|
258 |
gr.Button(visible=True, variant="stop"),
|
259 |
-
gr.Textbox(
|
|
|
|
|
|
|
|
|
|
|
260 |
gr.Image(interactive=False, visible=False),
|
261 |
gr.Textbox(visible=False),
|
262 |
gr.Button(visible=False),
|
@@ -267,7 +272,13 @@ with gr.Blocks() as demo:
|
|
267 |
feed = game.play_game(inp)
|
268 |
feedback_trim = feed.split("[rank]")
|
269 |
if len(feedback_trim) > 1:
|
|
|
270 |
ranking_md = convert_to_markdown_centered(feedback_trim[1])
|
|
|
|
|
|
|
|
|
|
|
271 |
feedback = feedback_trim[0].split("[hint]")
|
272 |
win = feedback_trim[0].split("[win]")
|
273 |
lose = feedback_trim[0].split("[lose]")
|
@@ -312,7 +323,7 @@ with gr.Blocks() as demo:
|
|
312 |
feedback[1] if hint else "", visible=hint, label="Pista"
|
313 |
),
|
314 |
gr.Button(visible=False),
|
315 |
-
gr.Markdown(ranking_md, visible=
|
316 |
]
|
317 |
)
|
318 |
|
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
from game_word2vec import Semantrix as semantrix_word2vec
|
4 |
+
from game_transformer import Semantrix as semantrix_sentence_transformers
|
5 |
|
6 |
|
7 |
config_file_path = "config/lang.json"
|
|
|
256 |
gr.Radio(label="", visible=False),
|
257 |
gr.Textbox(visible=False, label=""),
|
258 |
gr.Button(visible=True, variant="stop"),
|
259 |
+
gr.Textbox(
|
260 |
+
value="",
|
261 |
+
visible=True,
|
262 |
+
autofocus=True,
|
263 |
+
placeholder=Menu["New_word"],
|
264 |
+
),
|
265 |
gr.Image(interactive=False, visible=False),
|
266 |
gr.Textbox(visible=False),
|
267 |
gr.Button(visible=False),
|
|
|
272 |
feed = game.play_game(inp)
|
273 |
feedback_trim = feed.split("[rank]")
|
274 |
if len(feedback_trim) > 1:
|
275 |
+
ranking_vis = True
|
276 |
ranking_md = convert_to_markdown_centered(feedback_trim[1])
|
277 |
+
|
278 |
+
else:
|
279 |
+
ranking_vis = False
|
280 |
+
ranking_md = ""
|
281 |
+
|
282 |
feedback = feedback_trim[0].split("[hint]")
|
283 |
win = feedback_trim[0].split("[win]")
|
284 |
lose = feedback_trim[0].split("[lose]")
|
|
|
323 |
feedback[1] if hint else "", visible=hint, label="Pista"
|
324 |
),
|
325 |
gr.Button(visible=False),
|
326 |
+
gr.Markdown(ranking_md, visible=ranking_vis),
|
327 |
]
|
328 |
)
|
329 |
|
app_trans.py
CHANGED
@@ -1,12 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
-
from
|
4 |
|
5 |
|
6 |
config_file_path = "config/lang.json"
|
7 |
|
8 |
|
9 |
-
|
10 |
with open(config_file_path, "r") as file:
|
11 |
Config_full = json.load(file)
|
12 |
|
@@ -19,10 +18,11 @@ elif lang == 1:
|
|
19 |
else:
|
20 |
Config = Config_full["SPA"]["Game"]
|
21 |
|
|
|
22 |
def convert_to_markdown_centered(text):
|
23 |
# Separar el texto de último intento y el historial
|
24 |
-
lines = text.strip().split(
|
25 |
-
|
26 |
if not lines:
|
27 |
return ""
|
28 |
|
@@ -31,7 +31,6 @@ def convert_to_markdown_centered(text):
|
|
31 |
# Crear el formato Markdown
|
32 |
markdown = '<div align="center">\n\n'
|
33 |
|
34 |
-
|
35 |
# Crear la tabla de historial
|
36 |
markdown += "## Mejores intentos\n"
|
37 |
markdown += "<table>\n"
|
@@ -57,11 +56,11 @@ def convert_to_markdown_centered(text):
|
|
57 |
markdown += f"**{last_items[0]}:** {last_items[1]} - Score: {last_items[2]}\n\n"
|
58 |
markdown += "---\n\n"
|
59 |
|
60 |
-
|
61 |
markdown += "</div>"
|
62 |
|
63 |
return markdown
|
64 |
|
|
|
65 |
with gr.Blocks() as demo:
|
66 |
state = gr.State(-1)
|
67 |
difficulty = gr.State(-1)
|
@@ -69,73 +68,71 @@ with gr.Blocks() as demo:
|
|
69 |
hint_path = "config/hint.png"
|
70 |
game = Semantrix()
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
gr.Markdown(
|
76 |
"""
|
77 |
<p style="text-align:center"> SEMANTRIX: EL JUEGO DE LAS PALABRAS </p>
|
78 |
"""
|
79 |
)
|
80 |
|
81 |
-
|
82 |
-
|
83 |
def reset(difficulty):
|
84 |
game.prepare_game(difficulty)
|
85 |
output = [
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
]
|
96 |
|
97 |
return output
|
98 |
|
99 |
-
def change(state,inp):
|
100 |
|
101 |
state = state + 1
|
102 |
-
return [state,inp]
|
103 |
|
104 |
-
def update(state, radio,inp,hint):
|
105 |
global difficulty
|
106 |
dif_state = 4
|
107 |
output = [state]
|
108 |
-
|
109 |
state_int = state
|
110 |
|
111 |
if state_int == -1:
|
112 |
output.extend(
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
125 |
|
126 |
if state_int == 1:
|
127 |
output.extend(
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
|
|
|
|
139 |
)
|
140 |
elif state_int == 2:
|
141 |
if radio == "NO":
|
@@ -143,42 +140,50 @@ with gr.Blocks() as demo:
|
|
143 |
dif_state,
|
144 |
gr.Button("Introducir", visible=True),
|
145 |
gr.Radio(visible=False),
|
146 |
-
gr.Textbox(
|
|
|
|
|
147 |
gr.Button("Rendirse", visible=False),
|
148 |
gr.Textbox(visible=False),
|
149 |
gr.Image(interactive=False, visible=False),
|
150 |
gr.Textbox(visible=False),
|
151 |
gr.Button(visible=False),
|
152 |
gr.Markdown(visible=False),
|
153 |
-
|
154 |
-
|
155 |
else:
|
156 |
output.extend(
|
157 |
[
|
158 |
-
|
159 |
-
|
160 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
gr.Button("Rendirse", visible=False),
|
162 |
gr.Textbox(visible=False),
|
163 |
gr.Image(interactive=False, visible=False),
|
164 |
gr.Textbox(visible=False),
|
165 |
gr.Button(visible=False),
|
166 |
gr.Markdown(visible=False),
|
167 |
-
|
168 |
-
)
|
169 |
-
elif state_int == dif_state:
|
170 |
-
output.extend(
|
171 |
-
[
|
172 |
-
gr.Button("Siguiente", visible=False),
|
173 |
-
gr.Radio(["Fácil", "Normal", "Difícil", "Experto"], visible=True),
|
174 |
-
gr.Textbox(Config[list(Config.keys())[state_int]], visible=True, label=""),
|
175 |
-
gr.Button("Rendirse", visible=False),
|
176 |
-
gr.Textbox(visible=False),
|
177 |
-
gr.Image(interactive=False, visible=False),
|
178 |
-
gr.Textbox(visible=False),
|
179 |
-
gr.Button(visible=False),
|
180 |
-
gr.Markdown(visible=False),
|
181 |
-
]
|
182 |
)
|
183 |
elif state_int == dif_state + 1:
|
184 |
if radio == "Fácil":
|
@@ -190,40 +195,39 @@ with gr.Blocks() as demo:
|
|
190 |
else:
|
191 |
difficulty = 4
|
192 |
|
193 |
-
|
194 |
-
|
195 |
output.extend(
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
|
|
208 |
)
|
209 |
-
|
210 |
elif state_int == dif_state + 2:
|
211 |
|
212 |
game.prepare_game(difficulty)
|
213 |
|
214 |
# feed = game.play_game(inp)
|
215 |
output.extend(
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
)
|
228 |
elif state_int > dif_state + 2:
|
229 |
feed = game.play_game(inp)
|
@@ -236,82 +240,102 @@ with gr.Blocks() as demo:
|
|
236 |
hint = True
|
237 |
else:
|
238 |
hint = False
|
239 |
-
|
240 |
if len(win) > 1:
|
241 |
won = True
|
242 |
curiosity = game.curiosity()
|
243 |
output.extend(
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
|
|
|
|
256 |
return output
|
257 |
|
258 |
output.extend(
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
|
|
272 |
|
273 |
else:
|
274 |
output.extend(
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
|
|
|
|
286 |
)
|
287 |
return output
|
288 |
-
|
289 |
-
img = gr.Image(hint_path,height=430,interactive=False, visible=True)
|
290 |
ranking = gr.Markdown(visible=False)
|
291 |
|
292 |
with gr.Row():
|
293 |
-
out = gr.Textbox(
|
294 |
-
|
295 |
-
)
|
296 |
-
hint_out = gr.Textbox(
|
297 |
-
visible=False
|
298 |
-
)
|
299 |
radio = gr.Radio(visible=False)
|
300 |
with gr.Row():
|
301 |
-
inp = gr.Textbox(visible=False,interactive=True,label="")
|
302 |
but = gr.Button("Empezar")
|
303 |
give_up = gr.Button("Pista", visible=False)
|
304 |
reload = gr.Button("Volver a jugar", visible=False)
|
305 |
|
306 |
-
inp.submit(change, inputs=[state,inp], outputs=[state,inp])
|
307 |
-
but.click(change, inputs=[state,inp], outputs=[state,inp])
|
308 |
-
give_up.click(
|
309 |
-
|
310 |
-
|
311 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
312 |
|
313 |
# out.change(button_name, inputs=radio, outputs=[but, radio, out])
|
314 |
-
|
315 |
-
state.change(
|
|
|
|
|
|
|
|
|
316 |
if __name__ == "__main__":
|
317 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import json
|
3 |
+
from Research.semantrix.game_transformer import Semantrix
|
4 |
|
5 |
|
6 |
config_file_path = "config/lang.json"
|
7 |
|
8 |
|
|
|
9 |
with open(config_file_path, "r") as file:
|
10 |
Config_full = json.load(file)
|
11 |
|
|
|
18 |
else:
|
19 |
Config = Config_full["SPA"]["Game"]
|
20 |
|
21 |
+
|
22 |
def convert_to_markdown_centered(text):
|
23 |
# Separar el texto de último intento y el historial
|
24 |
+
lines = text.strip().split("\n")
|
25 |
+
|
26 |
if not lines:
|
27 |
return ""
|
28 |
|
|
|
31 |
# Crear el formato Markdown
|
32 |
markdown = '<div align="center">\n\n'
|
33 |
|
|
|
34 |
# Crear la tabla de historial
|
35 |
markdown += "## Mejores intentos\n"
|
36 |
markdown += "<table>\n"
|
|
|
56 |
markdown += f"**{last_items[0]}:** {last_items[1]} - Score: {last_items[2]}\n\n"
|
57 |
markdown += "---\n\n"
|
58 |
|
|
|
59 |
markdown += "</div>"
|
60 |
|
61 |
return markdown
|
62 |
|
63 |
+
|
64 |
with gr.Blocks() as demo:
|
65 |
state = gr.State(-1)
|
66 |
difficulty = gr.State(-1)
|
|
|
68 |
hint_path = "config/hint.png"
|
69 |
game = Semantrix()
|
70 |
|
|
|
|
|
|
|
71 |
gr.Markdown(
|
72 |
"""
|
73 |
<p style="text-align:center"> SEMANTRIX: EL JUEGO DE LAS PALABRAS </p>
|
74 |
"""
|
75 |
)
|
76 |
|
|
|
|
|
77 |
def reset(difficulty):
|
78 |
game.prepare_game(difficulty)
|
79 |
output = [
|
80 |
+
-1,
|
81 |
+
gr.Textbox(visible=False),
|
82 |
+
gr.Textbox(visible=False),
|
83 |
+
gr.Image(hint_path, visible=True, interactive=False),
|
84 |
+
gr.Button("Empezar", visible=True, variant="secondary"),
|
85 |
+
gr.Radio(visible=False),
|
86 |
+
gr.Textbox(visible=False),
|
87 |
+
gr.Button(visible=False),
|
88 |
+
]
|
|
|
89 |
|
90 |
return output
|
91 |
|
92 |
+
def change(state, inp):
|
93 |
|
94 |
state = state + 1
|
95 |
+
return [state, inp]
|
96 |
|
97 |
+
def update(state, radio, inp, hint):
|
98 |
global difficulty
|
99 |
dif_state = 4
|
100 |
output = [state]
|
101 |
+
|
102 |
state_int = state
|
103 |
|
104 |
if state_int == -1:
|
105 |
output.extend(
|
106 |
+
[
|
107 |
+
gr.Button("Empezar", visible=True),
|
108 |
+
gr.Radio(label="", visible=False),
|
109 |
+
gr.Textbox(
|
110 |
+
Config[list(Config.keys())[state_int]], visible=False, label=""
|
111 |
+
),
|
112 |
+
gr.Button("Rendirse", visible=False),
|
113 |
+
gr.Textbox(visible=False),
|
114 |
+
gr.Image(interactive=False, visible=True),
|
115 |
+
gr.Textbox(visible=False),
|
116 |
+
gr.Button(visible=False),
|
117 |
+
gr.Markdown(visible=False),
|
118 |
+
]
|
119 |
+
)
|
120 |
|
121 |
if state_int == 1:
|
122 |
output.extend(
|
123 |
+
[
|
124 |
+
gr.Button("Si", visible=False),
|
125 |
+
gr.Radio(["SÍ", "NO"], label="", visible=True),
|
126 |
+
gr.Textbox(
|
127 |
+
Config[list(Config.keys())[state_int]], visible=True, label=""
|
128 |
+
),
|
129 |
+
gr.Button("Rendirse", visible=False),
|
130 |
+
gr.Textbox(visible=False),
|
131 |
+
gr.Image(interactive=False, visible=False),
|
132 |
+
gr.Textbox(visible=False),
|
133 |
+
gr.Button(visible=False),
|
134 |
+
gr.Markdown(visible=False),
|
135 |
+
]
|
136 |
)
|
137 |
elif state_int == 2:
|
138 |
if radio == "NO":
|
|
|
140 |
dif_state,
|
141 |
gr.Button("Introducir", visible=True),
|
142 |
gr.Radio(visible=False),
|
143 |
+
gr.Textbox(
|
144 |
+
Config[list(Config.keys())[state_int]], visible=True, label=""
|
145 |
+
),
|
146 |
gr.Button("Rendirse", visible=False),
|
147 |
gr.Textbox(visible=False),
|
148 |
gr.Image(interactive=False, visible=False),
|
149 |
gr.Textbox(visible=False),
|
150 |
gr.Button(visible=False),
|
151 |
gr.Markdown(visible=False),
|
152 |
+
]
|
153 |
+
|
154 |
else:
|
155 |
output.extend(
|
156 |
[
|
157 |
+
gr.Button("Siguiente", visible=True),
|
158 |
+
gr.Radio(visible=False),
|
159 |
+
gr.Textbox(
|
160 |
+
Config[list(Config.keys())[state_int]],
|
161 |
+
visible=True,
|
162 |
+
label="",
|
163 |
+
),
|
164 |
+
gr.Button("Rendirse", visible=False),
|
165 |
+
gr.Textbox(visible=False),
|
166 |
+
gr.Image(interactive=False, visible=False),
|
167 |
+
gr.Textbox(visible=False),
|
168 |
+
gr.Button(visible=False),
|
169 |
+
gr.Markdown(visible=False),
|
170 |
+
]
|
171 |
+
)
|
172 |
+
elif state_int == dif_state:
|
173 |
+
output.extend(
|
174 |
+
[
|
175 |
+
gr.Button("Siguiente", visible=False),
|
176 |
+
gr.Radio(["Fácil", "Normal", "Difícil", "Experto"], visible=True),
|
177 |
+
gr.Textbox(
|
178 |
+
Config[list(Config.keys())[state_int]], visible=True, label=""
|
179 |
+
),
|
180 |
gr.Button("Rendirse", visible=False),
|
181 |
gr.Textbox(visible=False),
|
182 |
gr.Image(interactive=False, visible=False),
|
183 |
gr.Textbox(visible=False),
|
184 |
gr.Button(visible=False),
|
185 |
gr.Markdown(visible=False),
|
186 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
187 |
)
|
188 |
elif state_int == dif_state + 1:
|
189 |
if radio == "Fácil":
|
|
|
195 |
else:
|
196 |
difficulty = 4
|
197 |
|
|
|
|
|
198 |
output.extend(
|
199 |
+
[
|
200 |
+
gr.Button("Empezar", visible=True, variant="primary"),
|
201 |
+
gr.Radio(visible=False),
|
202 |
+
gr.Textbox(
|
203 |
+
Config[list(Config.keys())[state_int]], visible=True, label=""
|
204 |
+
),
|
205 |
+
gr.Button("Rendirse", visible=False),
|
206 |
+
gr.Textbox(visible=False),
|
207 |
+
gr.Image(interactive=False, visible=False),
|
208 |
+
gr.Textbox(visible=False),
|
209 |
+
gr.Button(visible=False),
|
210 |
+
gr.Markdown(visible=False),
|
211 |
+
]
|
212 |
)
|
213 |
+
|
214 |
elif state_int == dif_state + 2:
|
215 |
|
216 |
game.prepare_game(difficulty)
|
217 |
|
218 |
# feed = game.play_game(inp)
|
219 |
output.extend(
|
220 |
+
[
|
221 |
+
gr.Button("Enviar", visible=True, variant="primary"),
|
222 |
+
gr.Radio(label="", visible=False),
|
223 |
+
gr.Textbox(visible=False, label=""),
|
224 |
+
gr.Button(visible=True, variant="stop"),
|
225 |
+
gr.Textbox(value="", visible=True, placeholder="Nueva palabra"),
|
226 |
+
gr.Image(interactive=False, visible=False),
|
227 |
+
gr.Textbox(visible=False),
|
228 |
+
gr.Button(visible=False),
|
229 |
+
gr.Markdown(visible=False),
|
230 |
+
]
|
231 |
)
|
232 |
elif state_int > dif_state + 2:
|
233 |
feed = game.play_game(inp)
|
|
|
240 |
hint = True
|
241 |
else:
|
242 |
hint = False
|
243 |
+
|
244 |
if len(win) > 1:
|
245 |
won = True
|
246 |
curiosity = game.curiosity()
|
247 |
output.extend(
|
248 |
+
[
|
249 |
+
gr.Button("Enviar", visible=False, variant="primary"),
|
250 |
+
gr.Radio(label="", visible=False),
|
251 |
+
gr.Textbox(win[1], visible=True, label=""),
|
252 |
+
gr.Button(visible=False, variant="stop"),
|
253 |
+
gr.Textbox(
|
254 |
+
value="", visible=False, placeholder="Nueva palabra"
|
255 |
+
),
|
256 |
+
gr.Image(hint_path, interactive=False, visible=True),
|
257 |
+
gr.Textbox(curiosity, visible=True, label="Curiosidad"),
|
258 |
+
gr.Button(visible=True),
|
259 |
+
gr.Markdown(visible=False),
|
260 |
+
]
|
261 |
+
)
|
262 |
return output
|
263 |
|
264 |
output.extend(
|
265 |
+
[
|
266 |
+
gr.Button("Enviar", visible=True, variant="primary"),
|
267 |
+
gr.Radio(label="", visible=False),
|
268 |
+
gr.Textbox(feedback[0], visible=True, label=""),
|
269 |
+
gr.Button(visible=True, variant="stop"),
|
270 |
+
gr.Textbox(value="", visible=True, placeholder="Nueva palabra"),
|
271 |
+
gr.Image(hint_path, interactive=False, visible=False),
|
272 |
+
gr.Textbox(
|
273 |
+
feedback[1] if hint else "", visible=hint, label="Pista"
|
274 |
+
),
|
275 |
+
gr.Button(visible=False),
|
276 |
+
gr.Markdown(ranking_md, visible=True),
|
277 |
+
]
|
278 |
+
)
|
279 |
|
280 |
else:
|
281 |
output.extend(
|
282 |
+
[
|
283 |
+
gr.Button("Siguiente", visible=True),
|
284 |
+
gr.Radio(label="", visible=False),
|
285 |
+
gr.Textbox(
|
286 |
+
Config[list(Config.keys())[state_int]], visible=True, label=""
|
287 |
+
),
|
288 |
+
gr.Button("Pista", visible=False),
|
289 |
+
gr.Textbox(visible=False),
|
290 |
+
gr.Image(interactive=False, visible=False),
|
291 |
+
gr.Textbox(visible=False),
|
292 |
+
gr.Button(visible=False),
|
293 |
+
gr.Markdown(visible=False),
|
294 |
+
]
|
295 |
)
|
296 |
return output
|
297 |
+
|
298 |
+
img = gr.Image(hint_path, height=430, interactive=False, visible=True)
|
299 |
ranking = gr.Markdown(visible=False)
|
300 |
|
301 |
with gr.Row():
|
302 |
+
out = gr.Textbox(visible=False, placeholder=Config[list(Config.keys())[0]])
|
303 |
+
hint_out = gr.Textbox(visible=False)
|
|
|
|
|
|
|
|
|
304 |
radio = gr.Radio(visible=False)
|
305 |
with gr.Row():
|
306 |
+
inp = gr.Textbox(visible=False, interactive=True, label="")
|
307 |
but = gr.Button("Empezar")
|
308 |
give_up = gr.Button("Pista", visible=False)
|
309 |
reload = gr.Button("Volver a jugar", visible=False)
|
310 |
|
311 |
+
inp.submit(change, inputs=[state, inp], outputs=[state, inp])
|
312 |
+
but.click(change, inputs=[state, inp], outputs=[state, inp])
|
313 |
+
give_up.click(
|
314 |
+
change,
|
315 |
+
inputs=[
|
316 |
+
state,
|
317 |
+
gr.Textbox("give_up", visible=False, interactive=True, label=""),
|
318 |
+
],
|
319 |
+
outputs=[state, inp],
|
320 |
+
)
|
321 |
+
reload.click(
|
322 |
+
reset,
|
323 |
+
inputs=difficulty,
|
324 |
+
outputs=[state, out, inp, img, but, radio, hint_out, reload],
|
325 |
+
)
|
326 |
+
radio.input(change, inputs=[state, inp], outputs=[state, inp])
|
327 |
+
demo.load(
|
328 |
+
reset,
|
329 |
+
inputs=difficulty,
|
330 |
+
outputs=[state, out, inp, img, but, radio, hint_out, reload],
|
331 |
+
)
|
332 |
|
333 |
# out.change(button_name, inputs=radio, outputs=[but, radio, out])
|
334 |
+
|
335 |
+
state.change(
|
336 |
+
update,
|
337 |
+
inputs=[state, radio, inp, hint],
|
338 |
+
outputs=[state, but, radio, out, give_up, inp, img, hint_out, reload, ranking],
|
339 |
+
)
|
340 |
if __name__ == "__main__":
|
341 |
demo.launch()
|
config/words.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7b687a6378e0c894c3060004ddab0076557b36ac650506a33abdd250165bd050
|
3 |
+
size 53583817
|
data/plays/__init__.py
ADDED
File without changes
|
data/ranking.txt
CHANGED
@@ -1 +1 @@
|
|
1 |
-
---------------------------
|
|
|
1 |
+
---------------------------
|
game.py → game_transformer.py
RENAMED
@@ -23,6 +23,7 @@ class Semantrix:
|
|
23 |
|
24 |
config_file_path = "config/lang.json"
|
25 |
secret_file_path = "config/secret.json"
|
|
|
26 |
data_path = "data/"
|
27 |
|
28 |
class DictWrapper:
|
@@ -51,6 +52,12 @@ class Semantrix:
|
|
51 |
with open(self.data_path + "ranking.txt", "w+") as file:
|
52 |
file.write("---------------------------")
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
def prepare_game(self, difficulty):
|
55 |
|
56 |
self.secret_list = (
|
@@ -149,11 +156,33 @@ class Semantrix:
|
|
149 |
self.words.append(word)
|
150 |
|
151 |
if word not in self.embeddings_dict.keys():
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
|
158 |
if repeated == -1:
|
159 |
self.word_vect.append(self.embeddings_dict[word].tolist())
|
@@ -223,7 +252,7 @@ class Semantrix:
|
|
223 |
with open(self.data_path + "ranking.txt", "r") as original_file:
|
224 |
file_content = original_file.readlines()
|
225 |
|
226 |
-
new_file_name = self.secret + "_" + str(datetime.now())
|
227 |
|
228 |
with open(self.data_path + "plays/" + new_file_name, "w+") as new_file:
|
229 |
new_file.writelines(file_content[2:])
|
|
|
23 |
|
24 |
config_file_path = "config/lang.json"
|
25 |
secret_file_path = "config/secret.json"
|
26 |
+
possible_words_file_path = "config/words.txt"
|
27 |
data_path = "data/"
|
28 |
|
29 |
class DictWrapper:
|
|
|
52 |
with open(self.data_path + "ranking.txt", "w+") as file:
|
53 |
file.write("---------------------------")
|
54 |
|
55 |
+
with open(self.possible_words_file_path, "r") as file:
|
56 |
+
|
57 |
+
data = file.read()
|
58 |
+
|
59 |
+
self.possible_words = data.split("\n")
|
60 |
+
|
61 |
def prepare_game(self, difficulty):
|
62 |
|
63 |
self.secret_list = (
|
|
|
156 |
self.words.append(word)
|
157 |
|
158 |
if word not in self.embeddings_dict.keys():
|
159 |
+
if word not in self.possible_words:
|
160 |
+
self.words.pop(len(self.words) - 1)
|
161 |
+
feedback = (
|
162 |
+
"I don't know that word. Try again."
|
163 |
+
if self.lang == 1
|
164 |
+
else "No conozco esa palabra. Inténtalo de nuevo."
|
165 |
+
)
|
166 |
+
feedback += (
|
167 |
+
"[rank]" + open(self.data_path + "ranking.txt", "r").read()
|
168 |
+
if len(self.words) > 1
|
169 |
+
else "\n\n"
|
170 |
+
)
|
171 |
+
|
172 |
+
return feedback
|
173 |
+
else:
|
174 |
+
embedding = self.model_st.encode(word, convert_to_tensor=True)
|
175 |
+
self.embeddings_dict[word] = embedding
|
176 |
+
self.model.add_vector(word, embedding.tolist())
|
177 |
+
|
178 |
+
score = round(
|
179 |
+
np.interp(
|
180 |
+
np.log(self.model.similarity(self.secret, word) * 10),
|
181 |
+
[0, np.log(10)],
|
182 |
+
[0, 10],
|
183 |
+
),
|
184 |
+
2,
|
185 |
+
)
|
186 |
|
187 |
if repeated == -1:
|
188 |
self.word_vect.append(self.embeddings_dict[word].tolist())
|
|
|
252 |
with open(self.data_path + "ranking.txt", "r") as original_file:
|
253 |
file_content = original_file.readlines()
|
254 |
|
255 |
+
new_file_name = self.secret + "_" + str(datetime.now()) + ".txt"
|
256 |
|
257 |
with open(self.data_path + "plays/" + new_file_name, "w+") as new_file:
|
258 |
new_file.writelines(file_content[2:])
|
game_word2vec.py
CHANGED
@@ -152,7 +152,11 @@ class Semantrix:
|
|
152 |
if self.lang == 1
|
153 |
else "No conozco esa palabra. Inténtalo de nuevo."
|
154 |
)
|
155 |
-
feedback +=
|
|
|
|
|
|
|
|
|
156 |
|
157 |
return feedback
|
158 |
|
@@ -229,8 +233,7 @@ class Semantrix:
|
|
229 |
with open(self.data_path + "ranking.txt", "r") as original_file:
|
230 |
file_content = original_file.readlines()
|
231 |
|
232 |
-
new_file_name = self.secret + "_" + str(datetime.now())
|
233 |
-
|
234 |
with open(self.data_path + "plays/" + new_file_name, "w+") as new_file:
|
235 |
new_file.writelines(file_content[2:])
|
236 |
|
|
|
152 |
if self.lang == 1
|
153 |
else "No conozco esa palabra. Inténtalo de nuevo."
|
154 |
)
|
155 |
+
feedback += (
|
156 |
+
"[rank]" + open(self.data_path + "ranking.txt", "r").read()
|
157 |
+
if len(self.words) > 1
|
158 |
+
else "\n\n"
|
159 |
+
)
|
160 |
|
161 |
return feedback
|
162 |
|
|
|
233 |
with open(self.data_path + "ranking.txt", "r") as original_file:
|
234 |
file_content = original_file.readlines()
|
235 |
|
236 |
+
new_file_name = self.secret + "_" + str(datetime.now()) + ".txt"
|
|
|
237 |
with open(self.data_path + "plays/" + new_file_name, "w+") as new_file:
|
238 |
new_file.writelines(file_content[2:])
|
239 |
|