Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
-
from gradio import Interface
|
3 |
-
from gradio.components import Textbox, Dropdown
|
4 |
-
|
5 |
-
|
6 |
import spacy
|
|
|
7 |
|
|
|
8 |
nlp = spacy.load('es_core_news_sm')
|
9 |
|
|
|
10 |
pos_map = {
|
11 |
'sustantivo': 'NOUN',
|
12 |
'verbo': 'VERB',
|
@@ -14,11 +13,13 @@ pos_map = {
|
|
14 |
'artículo': 'DET'
|
15 |
}
|
16 |
|
|
|
17 |
def identify_pos(sentence):
|
18 |
doc = nlp(sentence)
|
19 |
pos_tags = [(token.text, token.pos_) for token in doc]
|
20 |
return pos_tags
|
21 |
|
|
|
22 |
def game_logic(sentence, user_word, user_pos):
|
23 |
correct_answers = identify_pos(sentence)
|
24 |
user_pos = pos_map[user_pos.lower()]
|
@@ -30,7 +31,7 @@ def game_logic(sentence, user_word, user_pos):
|
|
30 |
return False, f'Incorrecto. "{user_word}" no es un {user_pos}, es un {pos}.'
|
31 |
return False, f'La palabra "{user_word}" no se encuentra en la frase.'
|
32 |
|
33 |
-
|
34 |
def main(sentence, user_word, user_pos):
|
35 |
if sentence and user_word and user_pos and user_pos != 'Selecciona una función gramatical...':
|
36 |
correct, message = game_logic(sentence, user_word, user_pos)
|
@@ -38,11 +39,12 @@ def main(sentence, user_word, user_pos):
|
|
38 |
else:
|
39 |
return 'Por favor, introduce una frase, una palabra y selecciona una función gramatical válida (sustantivo, verbo, adjetivo, artículo).'
|
40 |
|
41 |
-
|
|
|
42 |
inputs=[
|
43 |
-
Textbox(lines=2, placeholder='Introduce una frase aquí...'),
|
44 |
-
Textbox(lines=1, placeholder='Introduce una palabra aquí...'),
|
45 |
-
Dropdown(choices=['Selecciona una función gramatical...', 'sustantivo', 'verbo', 'adjetivo', 'artículo'])
|
46 |
],
|
47 |
-
outputs=Textbox())
|
48 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
import spacy
|
3 |
+
from kommunicate import Kommunicate
|
4 |
|
5 |
+
# Load the Spanish model for spaCy
|
6 |
nlp = spacy.load('es_core_news_sm')
|
7 |
|
8 |
+
# Map the Spanish POS tags to their English equivalents
|
9 |
pos_map = {
|
10 |
'sustantivo': 'NOUN',
|
11 |
'verbo': 'VERB',
|
|
|
13 |
'artículo': 'DET'
|
14 |
}
|
15 |
|
16 |
+
# Function to identify the POS tags in a sentence
|
17 |
def identify_pos(sentence):
|
18 |
doc = nlp(sentence)
|
19 |
pos_tags = [(token.text, token.pos_) for token in doc]
|
20 |
return pos_tags
|
21 |
|
22 |
+
# Game logic
|
23 |
def game_logic(sentence, user_word, user_pos):
|
24 |
correct_answers = identify_pos(sentence)
|
25 |
user_pos = pos_map[user_pos.lower()]
|
|
|
31 |
return False, f'Incorrecto. "{user_word}" no es un {user_pos}, es un {pos}.'
|
32 |
return False, f'La palabra "{user_word}" no se encuentra en la frase.'
|
33 |
|
34 |
+
# Main function for the Gradio interface
|
35 |
def main(sentence, user_word, user_pos):
|
36 |
if sentence and user_word and user_pos and user_pos != 'Selecciona una función gramatical...':
|
37 |
correct, message = game_logic(sentence, user_word, user_pos)
|
|
|
39 |
else:
|
40 |
return 'Por favor, introduce una frase, una palabra y selecciona una función gramatical válida (sustantivo, verbo, adjetivo, artículo).'
|
41 |
|
42 |
+
# Create the Gradio interface
|
43 |
+
iface = gr.Interface(fn=main,
|
44 |
inputs=[
|
45 |
+
gr.inputs.Textbox(lines=2, placeholder='Introduce una frase aquí...'),
|
46 |
+
gr.inputs.Textbox(lines=1, placeholder='Introduce una palabra aquí...'),
|
47 |
+
gr.inputs.Dropdown(choices=['Selecciona una función gramatical...', 'sustantivo', 'verbo', 'adjetivo', 'artículo'])
|
48 |
],
|
49 |
+
outputs=gr.outputs.Textbox())
|
50 |
+
iface.launch()
|