File size: 1,949 Bytes
7b06130
635422f
c895dc0
af39961
c895dc0
635422f
af39961
c895dc0
1c9efe9
 
 
 
 
 
 
c895dc0
635422f
 
 
 
af39961
c895dc0
3399dae
635422f
1c9efe9
3399dae
 
 
 
 
 
 
af0757c
c895dc0
3399dae
d0dc687
3399dae
 
4d76783
d0dc687
635422f
c895dc0
 
5c90650
c895dc0
 
 
5c90650
c895dc0
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import gradio as gr
import spacy
from kommunicate import Kommunicate

# Load the Spanish model for spaCy
nlp = spacy.load('es_core_news_sm')

# Map the Spanish POS tags to their English equivalents
pos_map = {
    'sustantivo': 'NOUN',
    'verbo': 'VERB',
    'adjetivo': 'ADJ',
    'artículo': 'DET'
}

# Function to identify the POS tags in a sentence
def identify_pos(sentence):
    doc = nlp(sentence)
    pos_tags = [(token.text, token.pos_) for token in doc]
    return pos_tags

# Game logic
def game_logic(sentence, user_word, user_pos):
    correct_answers = identify_pos(sentence)
    user_pos = pos_map[user_pos.lower()]
    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.'

# Main function for the Gradio interface
def main(sentence, user_word, user_pos):
    if sentence and user_word and user_pos and user_pos != 'Selecciona una función gramatical...':
        correct, message = game_logic(sentence, user_word, user_pos)
        return message
    else:
        return 'Por favor, introduce una frase, una palabra y selecciona una función gramatical válida (sustantivo, verbo, adjetivo, artículo).'

# Create the Gradio interface
iface = gr.Interface(fn=main, 
                  inputs=[
                      gr.inputs.Textbox(lines=2, placeholder='Introduce una frase aquí...'),
                      gr.inputs.Textbox(lines=1, placeholder='Introduce una palabra aquí...'),
                      gr.inputs.Dropdown(choices=['Selecciona una función gramatical...', 'sustantivo', 'verbo', 'adjetivo', 'artículo'])
                  ], 
                  outputs=gr.outputs.Textbox())
iface.launch()