File size: 1,084 Bytes
7b06130 635422f af39961 635422f af39961 635422f af39961 3399dae 635422f 3399dae af0757c 3399dae 4d76783 3399dae 635422f 3399dae 7b06130 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
import gradio as gr
import spacy
nlp = spacy.load('es_core_news_sm')
def identify_pos(sentence):
doc = nlp(sentence)
pos_tags = [(token.text, token.pos_) for token in doc]
return pos_tags
def game_logic(sentence, user_word, user_pos):
correct_answers = identify_pos(sentence)
for word, pos in correct_answers:
if word == user_word:
if pos.lower() == user_pos.lower():
return True, f'¡Correcto! "{user_word}" es un {user_pos}.'
else:
return False, f'Incorrecto. "{user_word}" no es un {user_pos}, es un {pos}.'
return False, f'La palabra "{user_word}" no se encuentra en la frase.'
def main(sentence, user_word, user_pos):
if sentence and user_word and user_pos:
correct, message = game_logic(sentence, user_word, user_pos)
return message
else:
return 'Por favor, introduce una frase, una palabra y su función gramatical (sustantivo, verbo, adjetivo, artículo).'
iface = gr.Interface(fn=main, inputs=["text", "text", "text"], outputs="text")
iface.launch()
|