File size: 1,245 Bytes
a8bb7b0
b09df44
 
a8bb7b0
ee758c2
a8bb7b0
ee758c2
 
b09df44
a8bb7b0
b09df44
ee758c2
 
 
 
 
 
 
a8bb7b0
b09df44
ee758c2
a8bb7b0
 
 
 
b09df44
ee758c2
b09df44
 
 
 
 
 
a8bb7b0
ee758c2
 
 
 
 
 
 
 
 
 
 
 
 
 
b09df44
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
import gradio as gr
import spacy
from transformers import pipeline

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

# Load the text generation pipeline
text_generator = pipeline('text-generation', model='gpt2')

def generate_sentence():
    # Generate a sentence
    try:
        result = text_generator('', max_length=50)[0]
        sentence = result['generated_text']
        return sentence
    except Exception as e:
        return str(e)

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

def check_answer(sentence, answer):
    # Check the user's answer
    tagged_words = analyze_sentence(sentence)
    correct_answer = [tag for word, tag in tagged_words]
    if answer == correct_answer:
        return 'Correcto!'
    else:
        return 'Incorrecto. La respuesta correcta es: ' + str(correct_answer)

# Define the Gradio interface
iface = gr.Interface(
    fn={
        "generate_sentence": generate_sentence,
        "check_answer": check_answer
    }, 
    inputs={
        "sentence": "text", 
        "answer": "list"
    }, 
    outputs="text"
)

# Launch the interface
iface.launch()