File size: 1,364 Bytes
c2fc6b8
a8bb7b0
b09df44
c2fc6b8
a8bb7b0
 
c2fc6b8
a8bb7b0
dbcf61e
 
b09df44
c2fc6b8
 
32bf464
 
a8bb7b0
b09df44
a8bb7b0
c2fc6b8
a8bb7b0
d8db9a1
 
 
32bf464
 
dbcf61e
b09df44
dbcf61e
 
d8db9a1
 
 
 
 
 
 
 
 
 
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
## app.py ##
import gradio as gr
import spacy
from transformers import pipeline

nlp = spacy.load('es_core_news_sm')
text_generator = pipeline('text-generation', model='gpt2')

pos_tags = ['ADJ', 'ADP', 'ADV', 'AUX', 'CONJ', 'DET', 'INTJ', 'NOUN', 'NUM', 'PART', 'PRON', 'PROPN', 'PUNCT', 'SCONJ', 'SYM', 'VERB', 'X']

def generate_sentence():
    result = text_generator('')[0]
    sentence = result['generated_text']
    tagged_words = analyze_sentence(sentence)
    return sentence, [word for word, _ in tagged_words]

def analyze_sentence(sentence):
    doc = nlp(sentence)
    return [(token.text, token.pos_) for token in doc]

def check_answer(sentence, *args):
    tagged_words = analyze_sentence(sentence)
    correct_answer = [tag for word, tag in tagged_words]
    user_answer = list(args)
    if user_answer == correct_answer:
        return 'Correcto!'
    else:
        return 'Incorrecto. La respuesta correcta es: ' + str(correct_answer)

generate_iface = gr.Interface(fn=generate_sentence, 
                              inputs='number', 
                              outputs=['textbox', 'textbox'])

check_iface = gr.Interface(fn=check_answer, 
                           inputs=['textbox'] + [gr.inputs.Dropdown(choices=pos_tags) for _ in range(10)], 
                           outputs='textbox')

generate_iface.launch()
check_iface.launch()