File size: 1,523 Bytes
af39961 c7be05a af39961 |
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 |
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()
|