Update app.py
Browse files
app.py
CHANGED
@@ -8,23 +8,22 @@ def identify_pos(sentence):
|
|
8 |
pos_tags = [(token.text, token.pos_) for token in doc]
|
9 |
return pos_tags
|
10 |
|
11 |
-
def game_logic(sentence,
|
12 |
correct_answers = identify_pos(sentence)
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
19 |
|
20 |
-
def main(sentence,
|
21 |
-
if sentence and
|
22 |
-
|
23 |
-
|
24 |
-
else:
|
25 |
-
return 'Incorrecto. Intenta de nuevo.'
|
26 |
else:
|
27 |
-
return 'Por favor, introduce una frase
|
28 |
|
29 |
-
iface = gr.Interface(fn=main, inputs=["text", "text"], outputs="text")
|
30 |
iface.launch()
|
|
|
8 |
pos_tags = [(token.text, token.pos_) for token in doc]
|
9 |
return pos_tags
|
10 |
|
11 |
+
def game_logic(sentence, user_word, user_pos):
|
12 |
correct_answers = identify_pos(sentence)
|
13 |
+
for word, pos in correct_answers:
|
14 |
+
if word == user_word:
|
15 |
+
if pos.lower() == user_pos.lower():
|
16 |
+
return True, f'¡Correcto! "{user_word}" es un {user_pos}.'
|
17 |
+
else:
|
18 |
+
return False, f'Incorrecto. "{user_word}" no es un {user_pos}, es un {pos}.'
|
19 |
+
return False, f'La palabra "{user_word}" no se encuentra en la frase.'
|
20 |
|
21 |
+
def main(sentence, user_word, user_pos):
|
22 |
+
if sentence and user_word and user_pos:
|
23 |
+
correct, message = game_logic(sentence, user_word, user_pos)
|
24 |
+
return message
|
|
|
|
|
25 |
else:
|
26 |
+
return 'Por favor, introduce una frase, una palabra y su función gramatical (sustantivo, verbo, adjetivo, artículo).'
|
27 |
|
28 |
+
iface = gr.Interface(fn=main, inputs=["text", "text", "text"], outputs="text")
|
29 |
iface.launch()
|