|
from transformers import pipeline |
|
import gradio as gr |
|
import pygame |
|
|
|
|
|
nlp = pipeline("text2text-generation", model="datificate/gpt2-small-spanish") |
|
|
|
|
|
def generate_sentence(): |
|
sentence = nlp("Genera una oraci贸n en espa帽ol")[0]["generated_text"] |
|
return sentence |
|
|
|
|
|
def check_answer(sentence, verb): |
|
words = sentence.split() |
|
if verb in words: |
|
return "隆Correcto! El verbo est谩 en la oraci贸n." |
|
else: |
|
return "Lo siento, el verbo no est谩 en la oraci贸n." |
|
|
|
|
|
def chatbot(): |
|
|
|
pygame.mixer.init() |
|
|
|
|
|
sound_effect = pygame.mixer.Sound("ding.wav") |
|
|
|
|
|
sentence = generate_sentence() |
|
|
|
|
|
verb = input("Identifica el verbo en la siguiente oraci贸n: " + sentence + "\n") |
|
|
|
|
|
result = check_answer(sentence, verb) |
|
|
|
|
|
if "Correcto" in result: |
|
sound_effect.play() |
|
|
|
return result |
|
|
|
|
|
gr.Interface(fn=chatbot, inputs=None, outputs="text").launch() |
|
|