Javierss commited on
Commit
85b22ea
·
1 Parent(s): e7e6aa8

Update new version

Browse files
__pycache__/app.cpython-311.pyc CHANGED
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
 
__pycache__/game.cpython-311.pyc ADDED
Binary file (13.7 kB). View file
 
__pycache__/pistas.cpython-311.pyc CHANGED
Binary files a/__pycache__/pistas.cpython-311.pyc and b/__pycache__/pistas.cpython-311.pyc differ
 
app.py CHANGED
@@ -1,10 +1,76 @@
1
  import gradio as gr
 
 
2
 
3
 
 
4
 
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  with gr.Blocks() as demo:
7
  state = gr.State(-1)
 
 
 
 
 
 
 
8
 
9
  gr.Markdown(
10
  """
@@ -12,135 +78,78 @@ with gr.Blocks() as demo:
12
  """
13
  )
14
 
15
-
16
- lang = {
17
- "Introduction_0": "Bienvenido a Semantrix, el emocionante Juego de la adivinanza semántica. \n\n Tu misión es adivinar una palabra secreta que yo he escogido, pero no te preocupes, te ayudaré en el camino. \n\nLanza al aire la primera palabra que se te ocurra. Te daré pistas diciéndote si estás caliente, es decir muy cerca de adivinarla o frío, es decir, muy lejos de la palabra.",
18
- "Introduction_1": "¿Quieres saber cómo se juega?",
19
- # "Rules_1": "Tu misión es adivinar una palabra secreta que yo he escogido, pero no te preocupes, te ayudaré en el camino. \n\nLanza al aire la primera palabra que se te ocurra. Te daré pistas diciéndote si estás caliente, es decir muy cerca de adivinarla o frío, es decir, muy lejos de la palabra.",
20
- "Rules_3": "Adicionalmente, Cada palabra que propongas recibirá una puntuación entre 0 y 10, un puntaje alto significa que estás muy cerca de adivinar la palabra secreta\n\nSi veo que estás un poco perdido, estaré aquí para darte pistas que te ayudarán a acercarte a la palabra secreta.",
21
- "Rules_5": "Como ayuda extra, mostraré un ranking de todas las palabras que has propuesto, ordenadas según su puntuación. Así podrás tener una idea mejor de qué tan cerca están y qué palabras funcionan mejor.",
22
- "Rules_6": "Serás el ganador cuando adivines correctamente la palabra secreta. ¡No desistas, lo tienes al alcance!\n\nAsí que, ¡enciende tu mente, confía en tus ideas y por sobre todo, pasa un buen rato! Este es un juego en el que cada palabra, cada puntuación y cada pista te acerca a tu victoria. ¡Mucha suerte!",
23
- "Difficulty_presentation_Full": "En este emocionante desafío de adivinanza semántica, puedes elegir cuán grande quieres que sea el reto. Aquí te presento los niveles de dificultad:\n\nFácil: ¡Es hora de calentar motores! En este nivel, te daré pistas evidentes para que puedas adivinar la palabra secreta de manera más rápida. Si estás comenzando a jugar o simplemente quieres pasar un buen rato sin mucha presión, ¡este es tu nivel!\n\nNormal: Aquí es donde las cosas comienzan a ponerse interesantes. En este nivel, solo te daré pistas cuando te vea muy perdido. Es bueno para aquellos jugadores que quieren un reto, pero sin ser tan duros consigo mismos.\n\nDifícil: ¿Listo para un verdadero desafío? En este nivel, te ayudaré solo cuando te vea realmente perdido, y prepárate, porque las palabras pueden llegar a ser más complejas. Para esos pensadores agudos que les encanta una buena cabeza rompecabezas.\n\nExperto: ¿Eres un maestro de las palabras? Este es el camino menos transitado, para aquellos campeones de la semántica que buscan la pura adrenalina del reto. No te daré ninguna pista y las palabras serán complejas. Aquí es donde puedes demostrar tu verdadero poder.\n\nRecuerda, ganes o pierdas, cada nivel está diseñado para hacerte disfrutar y mejorar tus habilidades de adivinanza y comprensión de las palabras. ¡Escoge tu nivel y empieza a jugar!",
24
- "Difficulty": "Elige tu nivel de dificultad",
25
- "New_word": "Nueva palabra: ",
26
- "Feedback_0": "Helado, puntuación: ",
27
- "Feedback_1": "Frío, puntuación: ",
28
- "Feedback_2": "Templado, puntuación: ",
29
- "Feedback_3": "Caliente, puntuación: ",
30
- "Feedback_4": "Quemando, puntuación: ",
31
- "Feedback_5": "Ardiendo, puntuación: ",
32
- "Feedback_6": "Te estás acercando",
33
- "Feedback_7": "Te estás alejando",
34
- "Feedback_8": "¡Has ganado, ENHORABUENA!",
35
- "Feedback_9": "La palabra secreta era: ",
36
- "Feedback_10": "Aunque no fue una victoria esta vez, ¡no temas! ¡Cada intento es una nueva oportunidad para brillar! ¡Sigue adelante!",
37
- "secret_word": "PALABRA SECRETA",
38
- "hint_intro": [
39
- "Parece que las palabras están jugando al escondite contigo. ¿Necesitas una ayudita? Aquí va una pista:",
40
- "¡Vamos, estás tan cerca de descifrar el enigma semántico! Pero si sientes que te falta un empujón, aquí tienes una pista:",
41
- "Tu mente está explorando este campo semántico como un detective, ¡pero incluso los detectives a veces necesitan pistas extra! Así que, aquí va una para ti:",
42
- "El camino semántico puede volverse un poco sinuoso a veces. No te preocupes, estoy aquí para allanar el camino con una pista:",
43
- "Las palabras son como piezas de un rompecabezas, y sé que estás cerca de completar la imagen. Aquí va una pista para encajar las piezas restantes:",
44
- "Estás navegando por las aguas semánticas con destreza, ¡pero incluso los capitanes expertos pueden necesitar un faro de vez en cuando! Aquí está tu faro, tu pista:",
45
- "La danza de las palabras puede ser complicada, pero no te preocupes, estoy aquí para ser tu guía de baile. Aquí tienes una pista para que sigas moviéndote con gracia:",
46
- ],
47
- }
48
- introduction = []
49
- for i in range(7):
50
- introduction.append(lang[list(lang.keys())[i]])
51
 
52
 
53
- def reset():
54
- state = gr.State(-1)
55
- return gr.Textbox(visible=False, placeholder=lang[list(lang.keys())[0]], min_width=15),gr.Textbox(visible=False),gr.Image(interactive=False, visible=False),gr.Button("Empezar"),gr.Radio(["SÍ", "NO"], visible=False)
56
- # def change(radio):
57
- # global state
58
- # state = state + 1
59
- # if state == 2 and radio == "NO":
60
- # state = 7
61
- # # txt=gr.Textbox(lang[list(lang.keys())[i]],visible=True,label='')
62
- # # else:
63
- # txt = gr.Textbox(lang[list(lang.keys())[state]], visible=True, label="")
64
- # return txt
65
-
66
- def change(state):
 
 
 
67
 
68
  state = state + 1
69
- return state
70
-
71
- # def button_name(radio):
72
-
73
- # output = [gr.State)]
74
- # if state == 1:
75
- # output.extend(
76
- # [
77
- # gr.State(1),
78
- # gr.Button("Si", visible=False),
79
- # gr.Radio(["SÍ", "NO"], label="", visible=True),
80
- # gr.Textbox(lang[list(lang.keys())[state.value]], visible=True, label=""),
81
- # ]
82
- # )
83
- # elif state == 2:
84
- # if radio == "NO":
85
- # output.extend(
86
- # [
87
- # gr.State(7),
88
- # gr.Button("Introducir", visible=True),
89
- # gr.Radio(["SÍ", "NO"], visible=False),
90
- # gr.Textbox(lang[list(lang.keys())[state.value]], visible=True, label=""),
91
- # ]
92
- # )
93
- # else:
94
- # output.extend(
95
- # [
96
-
97
- # gr.Button("Siguiente", visible=True),
98
- # gr.Radio(["SÍ", "NO"], visible=False),
99
- # gr.Textbox(lang[list(lang.keys())[state.value]], visible=True, label=""),
100
- # ]
101
- # )
102
- # elif state == 7:
103
- # output.extend(
104
- # [
105
- # gr.Button("Siguiente", visible=False),
106
- # gr.Radio(["Fácil", "Normal", "Dificil", "Experto"], visible=True),
107
- # gr.Textbox(lang[list(lang.keys())[state.value]], visible=True, label=""),
108
- # ]
109
- # )
110
- # else:
111
- # output.extend(
112
- # [
113
- # gr.Button("Siguiente", visible=True),
114
- # gr.Radio(["SÍ", "NO"], label="", visible=False),
115
- # gr.Textbox(lang[list(lang.keys())[state.value]], visible=True, label=""),
116
- # ]
117
- # )
118
- # return output
119
-
120
- def update(state, radio,inp):
121
- print(state)
122
  output = [state]
123
- if state == 1:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  output.extend(
125
  [
126
  gr.Button("Si", visible=False),
127
  gr.Radio(["SÍ", "NO"], label="", visible=True),
128
- gr.Textbox(lang[list(lang.keys())[state]], visible=True, label=""),
129
  gr.Button("Rendirse", visible=False),
130
  gr.Textbox(visible=False),
131
  gr.Image(interactive=False, visible=False),
 
 
 
132
  ]
133
  )
134
- elif state == 2:
135
  if radio == "NO":
136
  output = [
137
- 7,
138
  gr.Button("Introducir", visible=True),
139
  gr.Radio(["SÍ", "NO"], visible=False),
140
- gr.Textbox(lang[list(lang.keys())[state]], visible=True, label=""),
141
  gr.Button("Rendirse", visible=False),
142
  gr.Textbox(visible=False),
143
  gr.Image(interactive=False, visible=False),
 
 
 
144
  ]
145
 
146
  else:
@@ -148,24 +157,30 @@ with gr.Blocks() as demo:
148
  [
149
  gr.Button("Siguiente", visible=True),
150
  gr.Radio(["SÍ", "NO"], visible=False),
151
- gr.Textbox(lang[list(lang.keys())[state]], visible=True, label=""),
152
  gr.Button("Rendirse", visible=False),
153
  gr.Textbox(visible=False),
154
- gr.Image(interactive=False, visible=False),
 
 
 
155
  ]
156
  )
157
- elif state == 7:
158
  output.extend(
159
  [
160
  gr.Button("Siguiente", visible=False),
161
- gr.Radio(["Fácil", "Normal", "Dificil", "Experto"], visible=True),
162
- gr.Textbox(lang[list(lang.keys())[state]], visible=True, label=""),
163
  gr.Button("Rendirse", visible=False),
164
  gr.Textbox(visible=False),
165
  gr.Image(interactive=False, visible=False),
 
 
 
166
  ]
167
  )
168
- elif state == 8:
169
  if radio == "Fácil":
170
  difficulty = 1
171
  elif radio == "Normal":
@@ -174,60 +189,129 @@ with gr.Blocks() as demo:
174
  difficulty = 3
175
  else:
176
  difficulty = 4
 
 
 
177
  output.extend(
178
  [
179
- gr.Button("Enviar", visible=True, variant="primary"),
180
- gr.Radio(["SÍ", "NO"], label="", visible=False),
181
- gr.Textbox(lang[list(lang.keys())[state]], visible=False, label=""),
182
- gr.Button(visible=True,variant='stop'),
183
- gr.Textbox(visible=True,placeholder="Nueva palabra"),
184
  gr.Image(interactive=False, visible=False),
 
 
 
185
 
186
  ]
187
  )
188
- print(difficulty)
189
- elif state > 8:
190
 
 
191
 
 
192
  output.extend(
193
  [
194
  gr.Button("Enviar", visible=True, variant="primary"),
195
  gr.Radio(["SÍ", "NO"], label="", visible=False),
196
- gr.Textbox(inp, visible=True, label=""),
197
  gr.Button(visible=True,variant='stop'),
198
- gr.Textbox(visible=True,placeholder="Nueva palabra"),
199
- gr.Image(interactive=False, visible=True),
 
 
 
200
  ]
201
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
202
  else:
203
  output.extend(
204
  [
205
  gr.Button("Siguiente", visible=True),
206
  gr.Radio(["SÍ", "NO"], label="", visible=False),
207
- gr.Textbox(lang[list(lang.keys())[state]], visible=True, label=""),
208
  gr.Button("Pista", visible=False),
209
  gr.Textbox(visible=False),
210
  gr.Image(interactive=False, visible=False),
 
 
 
211
  ]
212
  )
213
  return output
214
 
215
- img = gr.Image(interactive=False, visible=False)
216
- out = gr.Textbox(
217
- visible=False, placeholder=lang[list(lang.keys())[0]], min_width=15
 
 
 
218
  )
 
 
 
219
  radio = gr.Radio(["SÍ", "NO"], visible=False)
220
  with gr.Row():
221
- inp = gr.Textbox(visible=False,interactive=True)
222
  but = gr.Button("Empezar")
223
- pista = gr.Button("Pista", visible=False)
 
224
 
225
- inp.submit(change, inputs=state, outputs=state)
226
- but.click(change, inputs=state, outputs=state)
227
- radio.input(change, inputs=state, outputs=state)
228
- demo.load(reset,outputs=[out,inp,img, but, radio])
229
- # out.change(button_name, inputs=radio, outputs=[but, radio, out])
 
230
 
231
- state.change(update, inputs=[state, radio,inp], outputs=[state, but, radio, out,pista,inp,img])
 
 
232
  if __name__ == "__main__":
233
  demo.launch()
 
1
  import gradio as gr
2
+ import json
3
+ from game import Semantrix
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
+
13
+ lang = 0
14
+
15
+ if lang == 0:
16
+ Config = Config_full["SPA"]["Game"]
17
+ elif lang == 1:
18
+ Config = Config_full["ENG"]["Game"]
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('\n')
25
+
26
+ if not lines:
27
+ return ""
28
+
29
+ last_attempt = lines[0]
30
+ history_attempts = lines[2:12]
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"
38
+ markdown += " <tr>\n"
39
+ markdown += " <th>Ranking</th>\n"
40
+ markdown += " <th>Palabra</th>\n"
41
+ markdown += " <th>Puntuación</th>\n"
42
+ markdown += " </tr>\n"
43
+
44
+ for line in history_attempts:
45
+ items = eval(line.strip())
46
+ markdown += " <tr>\n"
47
+ markdown += f" <td><strong>{items[0]}</strong></td>\n"
48
+ markdown += f" <td>{items[1]}</td>\n"
49
+ markdown += f" <td>{items[2]}</td>\n"
50
+ markdown += " </tr>\n"
51
+
52
+ markdown += "</table>\n\n"
53
+
54
+ # Formatear el último intento
55
+ last_items = eval(last_attempt)
56
+ markdown += f"## Último Intento\n"
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)
68
+ hint = gr.State(False)
69
+ hint_path = "/home/user/Research/semantrix/config/hint.png"
70
+ game = Semantrix()
71
+
72
+
73
+
74
 
75
  gr.Markdown(
76
  """
 
78
  """
79
  )
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
 
83
+ def reset(difficulty):
84
+ game.prepare_game(difficulty)
85
+ output = [
86
+ -1,
87
+ gr.Textbox(visible=False),
88
+ gr.Textbox(visible=False),
89
+ gr.Image(hint_path,visible=True,interactive=False),
90
+ gr.Button("Empezar",visible=True,variant="secondary"),
91
+ gr.Radio(["SÍ", "NO"], visible=False),
92
+ gr.Textbox(visible=False),
93
+ gr.Button(visible=False)
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
+ gr.Button("Empezar", visible=True),
115
+ gr.Radio(["SÍ", "NO"], label="", visible=False),
116
+ gr.Textbox(Config[list(Config.keys())[state_int]], visible=False, label=""),
117
+ gr.Button("Rendirse", visible=False),
118
+ gr.Textbox(visible=False),
119
+ gr.Image(interactive=False, visible=True),
120
+ gr.Textbox(visible=False),
121
+ gr.Button(visible=False),
122
+ gr.Markdown(visible=False),
123
+ ]
124
+ )
125
+
126
+ if state_int == 1:
127
  output.extend(
128
  [
129
  gr.Button("Si", visible=False),
130
  gr.Radio(["SÍ", "NO"], label="", visible=True),
131
+ gr.Textbox(Config[list(Config.keys())[state_int]], visible=True, label=""),
132
  gr.Button("Rendirse", visible=False),
133
  gr.Textbox(visible=False),
134
  gr.Image(interactive=False, visible=False),
135
+ gr.Textbox(visible=False),
136
+ gr.Button(visible=False),
137
+ gr.Markdown(visible=False),
138
  ]
139
  )
140
+ elif state_int == 2:
141
  if radio == "NO":
142
  output = [
143
+ dif_state,
144
  gr.Button("Introducir", visible=True),
145
  gr.Radio(["SÍ", "NO"], visible=False),
146
+ gr.Textbox(Config[list(Config.keys())[state_int]], visible=True, label=""),
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:
 
157
  [
158
  gr.Button("Siguiente", visible=True),
159
  gr.Radio(["SÍ", "NO"], visible=False),
160
+ gr.Textbox(Config[list(Config.keys())[state_int]], visible=True, label=""),
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":
185
  difficulty = 1
186
  elif radio == "Normal":
 
189
  difficulty = 3
190
  else:
191
  difficulty = 4
192
+
193
+
194
+
195
  output.extend(
196
  [
197
+ gr.Button("Empezar", visible=True, variant="primary"),
198
+ gr.Radio(["SÍ", "NO"], visible=False),
199
+ gr.Textbox(Config[list(Config.keys())[state_int]], visible=True, label=""),
200
+ gr.Button("Rendirse", visible=False),
201
+ gr.Textbox(visible=False),
202
  gr.Image(interactive=False, visible=False),
203
+ gr.Textbox(visible=False),
204
+ gr.Button(visible=False),
205
+ gr.Markdown(visible=False),
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
  gr.Button("Enviar", visible=True, variant="primary"),
218
  gr.Radio(["SÍ", "NO"], label="", visible=False),
219
+ gr.Textbox( visible=False, label=""),
220
  gr.Button(visible=True,variant='stop'),
221
+ gr.Textbox(value="",visible=True,placeholder="Nueva palabra"),
222
+ gr.Image(interactive=False, visible=False),
223
+ gr.Textbox(visible=False),
224
+ gr.Button(visible=False),
225
+ gr.Markdown(visible=False),
226
  ]
227
  )
228
+ elif state_int > dif_state + 2:
229
+ feed = game.play_game(inp)
230
+ feedback_trim = feed.split("[rank]")
231
+ if len(feedback_trim) > 1:
232
+ ranking_md = convert_to_markdown_centered(feedback_trim[1])
233
+ feedback = feedback_trim[0].split("[hint]")
234
+ win = feedback_trim[0].split("[win]")
235
+ if len(feedback) > 1:
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
+ gr.Button("Enviar", visible=False, variant="primary"),
246
+ gr.Radio(["SÍ", "NO"], label="", visible=False),
247
+ gr.Textbox(win[1], visible=True, label=""),
248
+ gr.Button(visible=False,variant='stop'),
249
+ gr.Textbox(value="",visible=False,placeholder="Nueva palabra"),
250
+ gr.Image(hint_path,interactive=False, visible=True),
251
+ gr.Textbox(curiosity, visible=True, label="Curiosidad"),
252
+ gr.Button(visible=True),
253
+ gr.Markdown(visible=False),
254
+ ]
255
+ )
256
+ return output
257
+
258
+ output.extend(
259
+ [
260
+ gr.Button("Enviar", visible=True, variant="primary"),
261
+ gr.Radio(["SÍ", "NO"], label="", visible=False),
262
+ gr.Textbox(feedback[0], visible=True, label=""),
263
+ gr.Button(visible=True,variant='stop'),
264
+ gr.Textbox(value="",visible=True,placeholder="Nueva palabra"),
265
+ gr.Image(hint_path,interactive=False, visible=False),
266
+ gr.Textbox(feedback[1] if hint else "", visible=hint, label="Pista"),
267
+ gr.Button(visible=False),
268
+ gr.Markdown(ranking_md, visible=True),
269
+ ]
270
+ )
271
+
272
+
273
  else:
274
  output.extend(
275
  [
276
  gr.Button("Siguiente", visible=True),
277
  gr.Radio(["SÍ", "NO"], label="", visible=False),
278
+ gr.Textbox(Config[list(Config.keys())[state_int]], visible=True, label=""),
279
  gr.Button("Pista", visible=False),
280
  gr.Textbox(visible=False),
281
  gr.Image(interactive=False, visible=False),
282
+ gr.Textbox(visible=False),
283
+ gr.Button(visible=False),
284
+ gr.Markdown(visible=False),
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
+ visible=False, placeholder=Config[list(Config.keys())[0]]
295
  )
296
+ hint_out = gr.Textbox(
297
+ visible=False
298
+ )
299
  radio = gr.Radio(["SÍ", "NO"], 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(change, inputs=[state,gr.Textbox("give_up",visible=False,interactive=True,label="")], outputs=[state,inp])
309
+ reload.click(reset,inputs=difficulty,outputs=[state,out,inp,img, but, radio,hint_out,reload])
310
+ radio.input(change, inputs=[state,inp], outputs=[state,inp])
311
+ demo.load(reset,inputs=difficulty,outputs=[state,out,inp,img, but, radio,hint_out,reload])
312
 
313
+ # out.change(button_name, inputs=radio, outputs=[but, radio, out])
314
+
315
+ state.change(update, inputs=[state, radio,inp,hint], outputs=[state, but, radio, out, give_up, inp, img, hint_out, reload,ranking])
316
  if __name__ == "__main__":
317
  demo.launch()
config/hint.png ADDED
config/lang copy.json ADDED
@@ -0,0 +1,124 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "SPA": {
3
+ "Game": {
4
+ "Introduction_0": "Bienvenido a Semantrix, el emocionante Juego de la Adivinanza Semántica.",
5
+ "Introduction_1": "¿Quieres saber cómo se juega?",
6
+ "Rules_0": "Veamos cómo se juega:",
7
+ "Rules_1": "Tu misión es adivinar una palabra secreta que yo he escogido, pero no te preocupes, te ayudaré en el camino.",
8
+ "Rules_2": "Lanza al aire la primera palabra que se te ocurra. Te daré pistas diciéndote si estás caliente, es decir muy cerca de adivinarla o frío, es decir, muy lejos de la palabra.",
9
+ "Rules_3": "Adicionalmente, Cada palabra que propongas recibirá una puntuación entre 0 y 10, un puntaje alto significa que estás muy cerca de adivinar la palabra secreta",
10
+ "Rules_4": "Si veo que estás un poco perdido, estaré aquí para darte pistas que te ayudarán a acercarte a la palabra secreta.",
11
+ "Rules_5": " Como ayuda extra, mostraré en mi tablet un ranking de todas las palabras que has propuesto, ordenadas según su puntuación. Así podrás tener una idea mejor de qué tan cerca están y qué palabras funcionan mejor.",
12
+ "Rules_6": "Serás el ganador cuando adivines correctamente la palabra secreta. ¡No desistas, lo tienes al alcance!",
13
+ "Rules_7": "Así que, ¡enciende tu mente, confía en tus ideas y por sobre todo, pasa un buen rato! Este es un juego en el que cada palabra, cada puntuación y cada pista te acerca a tu victoria. ¡Mucha suerte!",
14
+ "Difficulty_presentation_Full": "En este emocionante desafío de adivinanza semántica, puedes elegir cuán grande quieres que sea el reto. Aquí te presento los niveles de dificultad:\n\nFácil: ¡Es hora de calentar motores! En este nivel, te daré pistas evidentes para que puedas adivinar la palabra secreta de manera más rápida. Si estás comenzando a jugar o simplemente quieres pasar un buen rato sin mucha presión, ¡este es tu nivel!\n\nNormal: Aquí es donde las cosas comienzan a ponerse interesantes. En este nivel, solo te daré pistas cuando te vea muy perdido. Es bueno para aquellos jugadores que quieren un reto, pero sin ser tan duros consigo mismos.\n\nDifícil: ¿Listo para un verdadero desafío? En este nivel, te ayudaré solo cuando te vea realmente perdido, y prepárate, porque las palabras pueden llegar a ser más complejas. Para esos pensadores agudos que les encanta una buena cabeza rompecabezas.\n\nExperto: ¿Eres un maestro de las palabras? Este es el camino menos transitado, para aquellos campeones de la semántica que buscan la pura adrenalina del reto. No te daré ninguna pista y las palabras serán complejas. Aquí es donde puedes demostrar tu verdadero poder.\n\nRecuerda, ganes o pierdas, cada nivel está diseñado para hacerte disfrutar y mejorar tus habilidades de adivinanza y comprensión de las palabras. ¡Escoge tu nivel y empieza a jugar!",
15
+ "Difficulty": "Elige tu nivel de dificultad",
16
+ "New_word": "Nueva palabra: ",
17
+ "Feedback_0": "Helado, puntuación: ",
18
+ "Feedback_1": "Frío, puntuación: ",
19
+ "Feedback_2": "Templado, puntuación: ",
20
+ "Feedback_3": "Caliente, puntuación: ",
21
+ "Feedback_4": "Quemando, puntuación: ",
22
+ "Feedback_5": "Ardiendo, puntuación: ",
23
+ "Feedback_6": "Te estás acercando",
24
+ "Feedback_7": "Te estás alejando",
25
+ "Feedback_8": "¡Has ganado, ENHORABUENA!",
26
+ "Feedback_9": "La palabra secreta era: ",
27
+ "Feedback_10": "Aunque no fue una victoria esta vez, ¡no temas! ¡Cada intento es una nueva oportunidad para brillar! ¡Sigue adelante!",
28
+ "secret_word": "PALABRA SECRETA",
29
+ "hint_intro": [
30
+ "Parece que las palabras están jugando al escondite contigo. ¿Necesitas una ayudita? Aquí va una pista:",
31
+ "¡Vamos, estás tan cerca de descifrar el enigma semántico! Pero si sientes que te falta un empujón, aquí tienes una pista:",
32
+ "Tu mente está explorando este campo semántico como un detective, ¡pero incluso los detectives a veces necesitan pistas extra! Así que, aquí va una para ti:",
33
+ "El camino semántico puede volverse un poco sinuoso a veces. No te preocupes, estoy aquí para allanar el camino con una pista:",
34
+ "Las palabras son como piezas de un rompecabezas, y sé que estás cerca de completar la imagen. Aquí va una pista para encajar las piezas restantes:",
35
+ "Estás navegando por las aguas semánticas con destreza, ¡pero incluso los capitanes expertos pueden necesitar un faro de vez en cuando! Aquí está tu faro, tu pista:",
36
+ "La danza de las palabras puede ser complicada, pero no te preocupes, estoy aquí para ser tu guía de baile. Aquí tienes una pista para que sigas moviéndote con gracia:"
37
+ ]
38
+ },
39
+ "Hint": {
40
+ "secret_word": "La palabra secreta",
41
+ "hint_0_0": "Define brevemente \"",
42
+ "hint_0_1": "\" sin incluir la propia palabra ni palabras de su familia léxica. En caso de usarla refiérete a ",
43
+ "hint_0_2": " como \"la palabra secreta\":",
44
+ "hint_0_3": "Podría definir la palabra secreta como:\n",
45
+ "hint_1_0": "Representa la palabra ",
46
+ "hint_1_1": " con emojis:",
47
+ "hint_1_2": "Voy a intentar representarte la palabra usando emojis:\n",
48
+ "hint_2_0": "Da una pista en forma de poema de 4 versos sobre ",
49
+ "hint_2_1": " que no incluya la propia palabra:",
50
+ "hint_2_2": "Me he inspirado un poco, voy a recitar un poema sobre la palabra secreta:\n",
51
+ "hint_3_0": "Dime tres palabras aleatorias separadas por coma:",
52
+ "hint_3_1": "Dime una palabra relacionada con",
53
+ "hint_3_2": " pero no puede ser la propia palabra ni de su familia léxica. No añadas texto adicional",
54
+ "hint_3_3": "Voy a pensar cuatro palabras y te muestro entre ellas cual se acerca más a la palabra secreta:\n",
55
+ "hint_4_0": "Dime el título de una película real donde aparece ",
56
+ "hint_4_1": ". Di únicamente el título, nada mas:",
57
+ "hint_4_2": "Representa la película ",
58
+ "hint_4_3": " únicamente con unos pocos emojis:",
59
+ "hint_4_4": "He pensado en una película relacionada con la palabra secreta y te la voy a representar con emojis, la película es:\n",
60
+ "curiosity": "Cuéntame una curiosidad sobre \""
61
+ }
62
+ },
63
+ "ENG": {
64
+ "Game": {
65
+ "Introduction_0": "Welcome to Semantrix, the exciting Semantic Guessing Game.",
66
+ "Introduction_1": "Do you want to know how to play?",
67
+ "Rules_0": "Let's see how to play:",
68
+ "Rules_1": "Your mission is to guess a secret word that I have chosen, but don't worry, I'll help you along the way.",
69
+ "Rules_2": "Throw out the first word that comes to your mind. I'll give you hints by telling you if you're hot, meaning very close to guessing it, or cold, meaning very far from the word.",
70
+ "Rules_3": "Additionally, each word you propose will receive a score between 0 and 10; a high score means you are very close to guessing the secret word.",
71
+ "Rules_4": "If I see that you're a bit lost, I'll be here to give you clues that will help you get closer to the secret word.",
72
+ "Rules_5": "As an extra help, I'll display on my tablet a ranking of all the words you've proposed, sorted by their score. This way, you can get a better idea of how close they are and which words work better.",
73
+ "Rules_6": "You will be the winner when you correctly guess the secret word. Don't give up; it's within your reach!",
74
+ "Rules_7": "So, ignite your mind, trust your ideas, and above all, have a good time! This is a game where each word, each score, and each clue brings you closer to victory. Good luck!",
75
+ "Difficulty_presentation_Full": "In this thrilling semantic guessing challenge, you can choose how big you want the challenge to be. Here are the difficulty levels:\n\nEasy: Time to warm up! In this level, I'll give you obvious clues so you can guess the secret word more quickly. If you're starting to play or just want to have a good time without much pressure, this is your level!\n\nNormal: This is where things start to get interesting. In this level, I'll only give you hints when I see you're very lost. It's good for players who want a challenge but without being too hard on themselves.\n\nHard: Ready for a real challenge? In this level, I'll help you only when I see you're truly lost, and get ready because the words can become more complex. For those sharp thinkers who love a good puzzle.\n\nExpert: Are you a master of words? This is the less-traveled path, for those semantic champions seeking the pure adrenaline of the challenge. I won't give you any hints, and the words will be complex. Here's where you can showcase your true power.\n\nRemember, win or lose, each level is designed to make you enjoy and improve your guessing and word comprehension skills. Choose your level and start playing!",
76
+ "Difficulty": "Choose your difficulty level",
77
+ "New_word": "New word: ",
78
+ "Feedback_0": "Ice-cold, score: ",
79
+ "Feedback_1": "Cold, score: ",
80
+ "Feedback_2": "Warm, score: ",
81
+ "Feedback_3": "Hot, score: ",
82
+ "Feedback_4": "Burning, score: ",
83
+ "Feedback_5": "On fire, score: ",
84
+ "Feedback_6": "You're getting closer",
85
+ "Feedback_7": "You're moving away",
86
+ "Feedback_8": "You've won, CONGRATULATIONS!",
87
+ "Feedback_9": "The secret word was: ",
88
+ "Feedback_10": "Though it wasn't a win this time, fear not! Each try is a new chance to shine! Keep going!",
89
+ "secret_word": "SECRET WORD",
90
+ "hint_intro": [
91
+ "It seems like the words are playing hide-and-seek with you. Need a little help? Here's a hint:",
92
+ "Come on, you're so close to unraveling the semantic mystery! But if you feel like you need a push, here's a hint:",
93
+ "Your mind is exploring this semantic field like a detective, but even detectives sometimes need extra clues! So, here's one for you:",
94
+ "The semantic path can get a bit winding at times. Don't worry, I'm here to smooth the way with a hint:",
95
+ "Words are like pieces of a puzzle, and I know you're close to completing the picture. Here's a hint to fit the remaining pieces:",
96
+ "You're navigating the semantic waters skillfully, but even expert captains may need a lighthouse now and then! Here's your lighthouse, your hint:",
97
+ "The dance of words can be intricate, but don't worry, I'm here to be your dance guide. Here's a hint to keep you moving with grace:"
98
+ ]
99
+ },
100
+ "Hint": {
101
+ "secret_word": "The secret word",
102
+ "hint_0_0": "Briefly define \"",
103
+ "hint_0_1": "\" without including the word itself or words from its lexical family. If using it, refer to ",
104
+ "hint_0_2": " as \"the secret word\":",
105
+ "hint_0_3": "I could define the secret word as:\n",
106
+ "hint_1_0": "Represent the word ",
107
+ "hint_1_1": " with emojis:",
108
+ "hint_1_2": "I'll try to represent the word using emojis:\n",
109
+ "hint_2_0": "Give a hint in the form of a 4-verse poem about ",
110
+ "hint_2_1": " that doesn't include the word itself:",
111
+ "hint_2_2": "I've been a bit inspired; I'll recite a poem about the secret word:\n",
112
+ "hint_3_0": "Tell me three random words separated by commas:",
113
+ "hint_3_1": "Tell me a word related to",
114
+ "hint_3_2": " but it can't be the word itself or from its lexical family. Don't add any additional text",
115
+ "hint_3_3": "I'll think of four words and show you which one comes closest to the secret word:\n",
116
+ "hint_4_0": "Tell me the title of a real movie where ",
117
+ "hint_4_1": ". Only say the title, nothing more:",
118
+ "hint_4_2": "Represent the movie ",
119
+ "hint_4_3": " only with a few emojis:",
120
+ "hint_4_4": "I've thought of a movie related to the secret word, and I'll represent it with emojis. The movie is:\n",
121
+ "curiosity": "Tell me an interesting fact about \""
122
+ }
123
+ }
124
+ }
config/lang.json CHANGED
@@ -1,18 +1,12 @@
1
  {
2
  "SPA": {
3
  "Game": {
4
- "Introduction_0": "Bienvenido a Semantrix, el emocionante Juego de la Adivinanza Semántica.",
5
  "Introduction_1": "¿Quieres saber cómo se juega?",
6
- "Rules_0": "Veamos cómo se juega:",
7
- "Rules_1": "Tu misión es adivinar una palabra secreta que yo he escogido, pero no te preocupes, te ayudaré en el camino.",
8
- "Rules_2": "Lanza al aire la primera palabra que se te ocurra. Te daré pistas diciéndote si estás caliente, es decir muy cerca de adivinarla o frío, es decir, muy lejos de la palabra.",
9
- "Rules_3": "Adicionalmente, Cada palabra que propongas recibirá una puntuación entre 0 y 10, un puntaje alto significa que estás muy cerca de adivinar la palabra secreta",
10
- "Rules_4": "Si veo que estás un poco perdido, estaré aquí para darte pistas que te ayudarán a acercarte a la palabra secreta.",
11
- "Rules_5": " Como ayuda extra, mostraré en mi tablet un ranking de todas las palabras que has propuesto, ordenadas según su puntuación. Así podrás tener una idea mejor de qué tan cerca están y qué palabras funcionan mejor.",
12
- "Rules_6": "Serás el ganador cuando adivines correctamente la palabra secreta. ¡No desistas, lo tienes al alcance!",
13
- "Rules_7": "Así que, ¡enciende tu mente, confía en tus ideas y por sobre todo, pasa un buen rato! Este es un juego en el que cada palabra, cada puntuación y cada pista te acerca a tu victoria. ¡Mucha suerte!",
14
- "Difficulty_presentation_Full": "En este emocionante desafío de adivinanza semántica, puedes elegir cuán grande quieres que sea el reto. Aquí te presento los niveles de dificultad:\n\nFácil: ¡Es hora de calentar motores! En este nivel, te daré pistas evidentes para que puedas adivinar la palabra secreta de manera más rápida. Si estás comenzando a jugar o simplemente quieres pasar un buen rato sin mucha presión, ¡este es tu nivel!\n\nNormal: Aquí es donde las cosas comienzan a ponerse interesantes. En este nivel, solo te daré pistas cuando te vea muy perdido. Es bueno para aquellos jugadores que quieren un reto, pero sin ser tan duros consigo mismos.\n\nDifícil: ¿Listo para un verdadero desafío? En este nivel, te ayudaré solo cuando te vea realmente perdido, y prepárate, porque las palabras pueden llegar a ser más complejas. Para esos pensadores agudos que les encanta una buena cabeza rompecabezas.\n\nExperto: ¿Eres un maestro de las palabras? Este es el camino menos transitado, para aquellos campeones de la semántica que buscan la pura adrenalina del reto. No te daré ninguna pista y las palabras serán complejas. Aquí es donde puedes demostrar tu verdadero poder.\n\nRecuerda, ganes o pierdas, cada nivel está diseñado para hacerte disfrutar y mejorar tus habilidades de adivinanza y comprensión de las palabras. ¡Escoge tu nivel y empieza a jugar!",
15
  "Difficulty": "Elige tu nivel de dificultad",
 
16
  "New_word": "Nueva palabra: ",
17
  "Feedback_0": "Helado, puntuación: ",
18
  "Feedback_1": "Frío, puntuación: ",
@@ -62,18 +56,13 @@
62
  },
63
  "ENG": {
64
  "Game": {
65
- "Introduction_0": "Welcome to Semantrix, the exciting Semantic Guessing Game.",
 
66
  "Introduction_1": "Do you want to know how to play?",
67
- "Rules_0": "Let's see how to play:",
68
- "Rules_1": "Your mission is to guess a secret word that I have chosen, but don't worry, I'll help you along the way.",
69
- "Rules_2": "Throw out the first word that comes to your mind. I'll give you hints by telling you if you're hot, meaning very close to guessing it, or cold, meaning very far from the word.",
70
- "Rules_3": "Additionally, each word you propose will receive a score between 0 and 10; a high score means you are very close to guessing the secret word.",
71
- "Rules_4": "If I see that you're a bit lost, I'll be here to give you clues that will help you get closer to the secret word.",
72
- "Rules_5": "As an extra help, I'll display on my tablet a ranking of all the words you've proposed, sorted by their score. This way, you can get a better idea of how close they are and which words work better.",
73
- "Rules_6": "You will be the winner when you correctly guess the secret word. Don't give up; it's within your reach!",
74
- "Rules_7": "So, ignite your mind, trust your ideas, and above all, have a good time! This is a game where each word, each score, and each clue brings you closer to victory. Good luck!",
75
- "Difficulty_presentation_Full": "In this thrilling semantic guessing challenge, you can choose how big you want the challenge to be. Here are the difficulty levels:\n\nEasy: Time to warm up! In this level, I'll give you obvious clues so you can guess the secret word more quickly. If you're starting to play or just want to have a good time without much pressure, this is your level!\n\nNormal: This is where things start to get interesting. In this level, I'll only give you hints when I see you're very lost. It's good for players who want a challenge but without being too hard on themselves.\n\nHard: Ready for a real challenge? In this level, I'll help you only when I see you're truly lost, and get ready because the words can become more complex. For those sharp thinkers who love a good puzzle.\n\nExpert: Are you a master of words? This is the less-traveled path, for those semantic champions seeking the pure adrenaline of the challenge. I won't give you any hints, and the words will be complex. Here's where you can showcase your true power.\n\nRemember, win or lose, each level is designed to make you enjoy and improve your guessing and word comprehension skills. Choose your level and start playing!",
76
  "Difficulty": "Choose your difficulty level",
 
77
  "New_word": "New word: ",
78
  "Feedback_0": "Ice-cold, score: ",
79
  "Feedback_1": "Cold, score: ",
 
1
  {
2
  "SPA": {
3
  "Game": {
4
+ "Introduction_0": "Bienvenido a Semantrix, el emocionante Juego de la adivinanza semántica. \n\nTu misión es adivinar una palabra secreta que yo he escogido, pero no te preocupes, te ayudaré en el camino. \n\nLanza al aire la primera palabra que se te ocurra. Te daré pistas diciéndote si estás caliente, es decir muy cerca de adivinarla o frío, es decir, muy lejos de la palabra.",
5
  "Introduction_1": "¿Quieres saber cómo se juega?",
6
+ "Rules": "Cada palabra que propongas recibirá una puntuación semántica entre 0 y 10, un puntaje alto significa que estás muy cerca de adivinar la palabra secreta\n\nSi veo que estás un poco perdido, estaré aquí para darte pistas que te ayudarán a acercarte a la palabra secreta.\n\nComo ayuda extra, mostraré un ranking de todas las palabras que has propuesto, ordenadas según su puntuación. Así podrás tener una idea mejor de qué tan cerca están y qué palabras funcionan mejor.\n\nSerás el ganador cuando adivines correctamente la palabra secreta. ¡No desistas, lo tienes al alcance!",
7
+ "Difficulty_presentation_Full": "En este emocionante desafío de adivinanza semántica, puedes elegir cuán grande quieres que sea el reto. Aquí te presento los niveles de dificultad:\n\n- Fácil: Pistas evidentes para una rápida adivinanza. Ideal para principiantes.\n\n- Normal: Pistas solo cuando estés muy perdido. Un reto intermedio.\n\n- Difícil: Ayuda mínima y palabras complejas. Para pensadores agudos.\n\n- Experto: Sin pistas y palabras difíciles. Para campeones de la semántica.\n\nRecuerda, ganes o pierdas, cada nivel está diseñado para hacerte disfrutar y mejorar tus habilidades de adivinanza y comprensión de las palabras. ¡Escoge tu nivel y empieza a jugar!",
 
 
 
 
 
 
 
8
  "Difficulty": "Elige tu nivel de dificultad",
9
+ "Begin": "¡Enciende tu mente, confía en tus ideas y por sobre todo, pasa un buen rato! Este es un juego en el que cada palabra, cada puntuación y cada pista te acerca a tu victoria. ¡Mucha suerte!",
10
  "New_word": "Nueva palabra: ",
11
  "Feedback_0": "Helado, puntuación: ",
12
  "Feedback_1": "Frío, puntuación: ",
 
56
  },
57
  "ENG": {
58
  "Game": {
59
+
60
+ "Introduction_0": "Welcome to Semantrix, the exciting semantic guessing game.\n\nYour mission is to guess a secret word I've chosen, but don't worry, I'll help you along the way.\n\nThrow out the first word that comes to your mind. I'll give you clues by telling you if you're hot, meaning very close to guessing it, or cold, meaning far from the word.",
61
  "Introduction_1": "Do you want to know how to play?",
62
+ "Rules": "Each word you propose will receive a semantic score between 0 and 10. A high score means you're very close to guessing the secret word.\n\nIf I see you're a bit lost, I'll be here to give you hints to help you get closer to the secret word.\n\nAs extra help, I'll show a ranking of all the words you've suggested, ordered by their score. This way, you can have a better idea of how close they are and which words work best.\n\nYou'll be the winner when you correctly guess the secret word. Don't give up, it's within your reach!",
63
+ "Difficulty_presentation_Full": "In this exciting semantic guessing challenge, you can choose how big you want the challenge to be. Here are the difficulty levels:\n\n- Easy: Obvious clues for quick guessing. Ideal for beginners.\n\n- Normal: Clues only when you're very lost. An intermediate challenge.\n\n- Hard: Minimal help and complex words. For sharp thinkers.\n\n- Expert: No clues and difficult words. For semantic champions.\n\nRemember, whether you win or lose, each level is designed to make you enjoy and improve your guessing and word comprehension skills. Choose your level and start playing!",
 
 
 
 
 
 
 
64
  "Difficulty": "Choose your difficulty level",
65
+ "Begin": "\n\nTurn on your mind, trust your ideas, and above all, have a good time! This is a game where each word, each score, and each clue brings you closer to your victory. Good luck!",
66
  "New_word": "New word: ",
67
  "Feedback_0": "Ice-cold, score: ",
68
  "Feedback_1": "Cold, score: ",
data/hospital_2024-01-09 12:01:14.954756 DELETED
@@ -1,9 +0,0 @@
1
- ['#8', 'médico', 6.33]
2
- ['#7', 'doctor', 6.13]
3
- ['#9', 'enfermo', 5.72]
4
- ['#1', 'álvaro', 3.45]
5
- ['#4', 'persona', 3.16]
6
- ['#6', 'morir', 2.71]
7
- ['#5', 'caca', 2.57]
8
- ['#2', 'amigo', 2.4]
9
- ['#3', 'saltar', 2.3]
 
 
 
 
 
 
 
 
 
 
data/lima_2024-02-16 13:43:11.426509 DELETED
@@ -1 +0,0 @@
1
- ['#1', 'amigo', 7.63]
 
 
data/pomelo_2024-01-09 11:59:50.395465 DELETED
File without changes
data/ranking.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ ['#1', 'dedo', 4.38]
2
+ ---------------------------
3
+ ['#1', 'dedo', 4.38]
flagged/log.csv DELETED
@@ -1,3 +0,0 @@
1
- word,output,flag,username,timestamp
2
- silla,"Caliente, puntuación: 6.9
3
- Te estás acercando",,,2024-02-16 13:51:47.368924
 
 
 
 
game.py ADDED
@@ -0,0 +1,269 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # %%
2
+ import json
3
+ import pickle as pk
4
+ import random
5
+ import threading
6
+ from datetime import datetime
7
+ import time
8
+ import gradio as gr
9
+ import numpy as np
10
+ from display import display_words
11
+ from gensim.models import KeyedVectors
12
+ from pistas import curiosity, hint
13
+ from seguimiento import calculate_moving_average, calculate_tendency_slope
14
+ from sentence_transformers import SentenceTransformer
15
+
16
+
17
+ class Semantrix:
18
+ model = KeyedVectors(768)
19
+ model_st = SentenceTransformer(
20
+ "sentence-transformers/paraphrase-multilingual-mpnet-base-v2"
21
+ )
22
+
23
+
24
+
25
+ config_file_path = "config/lang.json"
26
+ secret_file_path = "config/secret.json"
27
+ data_path = "data/"
28
+ class DictWrapper:
29
+ def __init__(self, data_dict):
30
+ self.__dict__.update(data_dict)
31
+
32
+ def __init__(self):
33
+
34
+ self.embeddings_dict = {}
35
+
36
+
37
+ with open(self.config_file_path, "r") as file:
38
+ self.Config_full = json.load(file)
39
+
40
+ with open(self.secret_file_path, "r") as file:
41
+ self.secret = json.load(file)
42
+
43
+ self.lang = 0
44
+
45
+ if self.lang == 0:
46
+ self.Config = self.DictWrapper(self.Config_full["SPA"]["Game"])
47
+ self.secret_dict = self.secret["SPA"]
48
+ elif self.lang == 1:
49
+ self.Config = self.DictWrapper(self.Config_full["ENG"]["Game"])
50
+ secret_dict = self.secret["ENG"]
51
+ else:
52
+ self.Config = self.DictWrapper(self.Config_full["SPA"]["Game"])
53
+ self.secret_dict = self.secret["SPA"]
54
+
55
+
56
+ with open(self.data_path + "ranking.txt", "w+") as file:
57
+ file.write("---------------------------")
58
+
59
+ # pca = pk.load(open("pca_mpnet.pkl", "rb"))
60
+
61
+ # print(Config.Difficulty_presentation_Full)
62
+ # difficulty = int(input(Config.Difficulty + ": "))
63
+
64
+ def prepare_game(self,difficulty):
65
+ # global secret, secret_list, words, scores, word_vect, thread, win, n, recent_hint, f_dev_avg, last_hint
66
+
67
+ self.secret_list = self.secret_dict["basic"] if difficulty <= 2 else self.secret_dict["advanced"]
68
+
69
+ self.secret = self.secret_list.pop(random.randint(0, len(self.secret_list) - 1))
70
+ self.secret = self.secret.lower()
71
+ self.secret = "amigo"
72
+
73
+ self.words = [self.Config.secret_word]
74
+ self.scores = [10]
75
+
76
+ if self.secret not in self.embeddings_dict.keys():
77
+ self.embeddings_dict[self.secret] = self.model_st.encode(self.secret, convert_to_tensor=True)
78
+ self.model.add_vector(self.secret, self.embeddings_dict[self.secret].tolist())
79
+
80
+ self.word_vect = [self.embeddings_dict[self.secret].tolist()]
81
+
82
+ # thread = threading.Thread(
83
+ # target=display_words, args=(words, pca.transform(word_vect), scores, -1)
84
+ # )
85
+ # thread.start()
86
+
87
+ self.win = False
88
+ self.n = 0
89
+ self.recent_hint = 0
90
+ self.f_dev_avg = 0
91
+ self.last_hint = -1
92
+ self.difficulty = difficulty
93
+
94
+ if self.difficulty == 1:
95
+ self.n = 3
96
+
97
+
98
+ def preproc_vectors(self,repeated):
99
+ ascending_indices = np.argsort(self.scores)
100
+ descending_indices = list(ascending_indices[::-1])
101
+ ranking_data = []
102
+ k = len(self.words) - 1
103
+ if repeated != -1:
104
+ k = repeated
105
+
106
+ ranking_data.append(["#" + str(k), self.words[k], self.scores[k]])
107
+
108
+ ranking_data.append("---------------------------")
109
+ for i in descending_indices:
110
+ if i == 0:
111
+ continue
112
+ ranking_data.append(["#" + str(i), self.words[i], self.scores[i]])
113
+
114
+ with open(self.data_path + "ranking.txt", "w+") as file:
115
+ for item in ranking_data:
116
+ file.write("%s\n" % item)
117
+
118
+ if len(self.words) > 11:
119
+ if k in descending_indices[:11]:
120
+ descending_indices = descending_indices[:11]
121
+ else:
122
+ descending_indices = descending_indices[:11]
123
+ descending_indices.append(k)
124
+ words_display = [self.words[i] for i in descending_indices]
125
+ # displayvect_display = pca.transform([word_vect[i] for i in descending_indices])
126
+ scores_display = [self.scores[i] for i in descending_indices]
127
+ bold = descending_indices.index(k)
128
+
129
+ else:
130
+ words_display = self.words
131
+ # displayvect_display = pca.transform(word_vect)
132
+ scores_display = self.scores
133
+ bold = k
134
+
135
+ return (
136
+ words_display,
137
+ # displayvect_display,
138
+ scores_display,
139
+ bold,
140
+ )
141
+
142
+
143
+
144
+
145
+
146
+ def play_game(self,word):
147
+ # global win, n, recent_hint, f_dev_avg, last_hint, words, word_vect, scores, thread
148
+
149
+ word = word.lower()
150
+ if word == "give_up":
151
+ text = (
152
+ "[win]"
153
+ +
154
+ self.Config.Feedback_9
155
+ + self.secret
156
+ + "\n\n"
157
+ + self.Config.Feedback_10
158
+ )
159
+ return text
160
+
161
+ if word in self.words:
162
+ repeated = self.words.index(word)
163
+ else:
164
+ repeated = -1
165
+ self.words.append(word)
166
+
167
+ # thread.join()
168
+
169
+ if word not in self.embeddings_dict.keys():
170
+ embedding = self.model_st.encode(word, convert_to_tensor=True)
171
+ self.embeddings_dict[word] = embedding
172
+ self.model.add_vector(word, embedding.tolist())
173
+
174
+ if repeated == -1:
175
+ self.word_vect.append(self.embeddings_dict[word].tolist())
176
+
177
+ score = round(self.model.similarity(self.secret, word) * 10, 2)
178
+
179
+ if repeated == -1:
180
+ self.scores.append(score)
181
+
182
+ if score <= 2.5:
183
+ feedback = self.Config.Feedback_0 + str(score)
184
+ elif score > 2.5 and score <= 4.0:
185
+ feedback = self.Config.Feedback_1 + str(score)
186
+ elif score > 4.0 and score <= 6.0:
187
+ feedback = self.Config.Feedback_2 + str(score)
188
+ elif score > 6.0 and score <= 7.5:
189
+ feedback = self.Config.Feedback_3 + str(score)
190
+ elif score > 7.5 and score <= 8.0:
191
+ feedback = self.Config.Feedback_4 + str(score)
192
+ elif score > 8.0 and score < 10.0:
193
+ feedback = self.Config.Feedback_5 + str(score)
194
+ else:
195
+ self.win = True
196
+ feedback = "[win]" + self.Config.Feedback_8
197
+ self.words[0] = self.secret
198
+ self.words.pop(len(self.words) - 1)
199
+ self.word_vect.pop(len(self.word_vect) - 1)
200
+ self.scores.pop(len(self.scores) - 1)
201
+
202
+ if score > self.scores[len(self.scores) - 2] and self.win == False:
203
+ feedback += "\n" + self.Config.Feedback_6
204
+ elif score < self.scores[len(self.scores) - 2] and self.win == False:
205
+ feedback += "\n" + self.Config.Feedback_7
206
+
207
+ if self.difficulty != 4:
208
+ mov_avg = calculate_moving_average(self.scores[1:], 5)
209
+
210
+ if len(mov_avg) > 1 and self.win == False:
211
+ f_dev = calculate_tendency_slope(mov_avg)
212
+ f_dev_avg = calculate_moving_average(f_dev, 3)
213
+ if f_dev_avg[len(f_dev_avg) - 1] < 0 and self.recent_hint == 0:
214
+ i = random.randint(0, len(self.Config.hint_intro) - 1)
215
+ feedback += "\n\n[hint]" + self.Config.hint_intro[i]
216
+ hint_text, self.n, self.last_hint = hint(
217
+ self.secret,
218
+ self.n,
219
+ self.model_st,
220
+ self.last_hint,
221
+ self.lang,
222
+ (
223
+ self.DictWrapper(self.Config_full["SPA"]["Hint"])
224
+ if self.lang == 0
225
+ else self.DictWrapper(self.Config_full["ENG"]["Hint"])
226
+ ),
227
+ )
228
+ feedback += "\n" + hint_text
229
+ self.recent_hint = 3
230
+
231
+ if self.recent_hint != 0:
232
+ self.recent_hint -= 1
233
+
234
+ (
235
+ words_display,
236
+ scores_display,
237
+ bold_display,
238
+ ) = self.preproc_vectors(repeated)
239
+
240
+ feedback += "[rank]" + open(self.data_path + "ranking.txt", "r").read()
241
+
242
+ if self.win:
243
+ bold_display = 0
244
+
245
+ # thread = threading.Thread(
246
+ # target=display_words,
247
+ # args=(words_display, displayvect_display, scores_display, bold_display),
248
+ # )
249
+ # thread.start()
250
+
251
+ if self.win:
252
+ # feedback += "\nCongratulations! You guessed the secret word."
253
+
254
+ with open(self.data_path + "ranking.txt", "r") as original_file:
255
+ file_content = original_file.readlines()
256
+
257
+ new_file_name = self.secret + "_" + str(datetime.now())
258
+
259
+ with open(self.data_path + "plays/" + new_file_name, "w+") as new_file:
260
+ new_file.writelines(file_content[2:])
261
+
262
+
263
+ return feedback
264
+
265
+ def curiosity(self):
266
+
267
+ feedback = curiosity(self.secret, self.DictWrapper(self.Config_full["SPA"]["Hint"]))
268
+
269
+ return feedback
juego_embbedings_chat.py CHANGED
@@ -57,10 +57,8 @@ pca = pk.load(open("pca_mpnet.pkl", "rb"))
57
  # difficulty = int(input(Config.Difficulty + ": "))
58
  difficulty = -1
59
 
60
- def prepare_game():
61
- global secret, secret_list, words, scores, word_vect, thread, win, n, recent_hint, f_dev_avg, last_hint, difficulty
62
- while difficulty == -1:
63
- print("waiting for difficulty")
64
 
65
  secret_list = secret_dict["basic"] if difficulty <= 2 else secret_dict["advanced"]
66
 
 
57
  # difficulty = int(input(Config.Difficulty + ": "))
58
  difficulty = -1
59
 
60
+ def prepare_game(difficulty):
61
+ global secret, secret_list, words, scores, word_vect, thread, win, n, recent_hint, f_dev_avg, last_hint
 
 
62
 
63
  secret_list = secret_dict["basic"] if difficulty <= 2 else secret_dict["advanced"]
64
 
pistas.py CHANGED
@@ -201,6 +201,7 @@ def hint(secret, n, model, last_pista, lang, Config):
201
 
202
 
203
  def curiosity(secret, Config):
 
204
  response = openai.chat.completions.create(
205
  model="gpt-3.5-turbo",
206
  messages=[
 
201
 
202
 
203
  def curiosity(secret, Config):
204
+
205
  response = openai.chat.completions.create(
206
  model="gpt-3.5-turbo",
207
  messages=[