GramAPP / app.py
Merlintxu's picture
Update app.py
ee758c2
raw
history blame
1.25 kB
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()