GramAPP / app.py
Merlintxu's picture
Update app.py
af39961
raw
history blame
1.52 kB
from transformers import pipeline
import gradio as gr
import pygame
# Load the pre-trained Spanish language model using HuggingFace
nlp = pipeline("text2text-generation", model="datificate/gpt2-small-spanish")
# Define a function that generates a random Spanish sentence using the pre-trained model
def generate_sentence():
sentence = nlp("Genera una oraci贸n en espa帽ol")[0]["generated_text"]
return sentence
# Define a function that checks if the child identifies the verb in the 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."
# Define a function that creates the chatbot interface using Gradio and adds fun animations or sound effects
def chatbot():
# Initialize pygame mixer for sound effects
pygame.mixer.init()
# Load sound effect
sound_effect = pygame.mixer.Sound("ding.wav")
# Generate a random sentence
sentence = generate_sentence()
# Ask the child to identify the verb in the sentence
verb = input("Identifica el verbo en la siguiente oraci贸n: " + sentence + "\n")
# Check if the child's answer is correct
result = check_answer(sentence, verb)
# Play sound effect if the answer is correct
if "Correcto" in result:
sound_effect.play()
return result
# Run the chatbot interface using Gradio
gr.Interface(fn=chatbot, inputs=None, outputs="text").launch()