Update app.py
Browse files
app.py
CHANGED
@@ -1,37 +1,45 @@
|
|
1 |
-
|
2 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline,GPTNeoXForCausalLM, AutoConfig
|
3 |
-
from gradio import Interface
|
4 |
import gradio as gr
|
5 |
-
|
6 |
-
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
"
|
13 |
-
|
14 |
-
|
15 |
-
# Define
|
16 |
-
def
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
#
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
|
|
|
|
2 |
import gradio as gr
|
3 |
+
import pygame
|
4 |
+
|
5 |
+
# Load the pre-trained Spanish language model using HuggingFace
|
6 |
+
nlp = pipeline("text2text-generation", model="datificate/gpt2-small-spanish")
|
7 |
+
|
8 |
+
# Define a function that generates a random Spanish sentence using the pre-trained model
|
9 |
+
def generate_sentence():
|
10 |
+
sentence = nlp("Genera una oraci贸n en espa帽ol")[0]["generated_text"]
|
11 |
+
return sentence
|
12 |
+
|
13 |
+
# Define a function that checks if the child identifies the verb in the sentence
|
14 |
+
def check_answer(sentence, verb):
|
15 |
+
words = sentence.split()
|
16 |
+
if verb in words:
|
17 |
+
return "隆Correcto! El verbo est谩 en la oraci贸n."
|
18 |
+
else:
|
19 |
+
return "Lo siento, el verbo no est谩 en la oraci贸n."
|
20 |
+
|
21 |
+
# Define a function that creates the chatbot interface using Gradio and adds fun animations or sound effects
|
22 |
+
def chatbot():
|
23 |
+
# Initialize pygame mixer for sound effects
|
24 |
+
pygame.mixer.init()
|
25 |
+
|
26 |
+
# Load sound effect
|
27 |
+
sound_effect = pygame.mixer.Sound("ding.wav")
|
28 |
+
|
29 |
+
# Generate a random sentence
|
30 |
+
sentence = generate_sentence()
|
31 |
+
|
32 |
+
# Ask the child to identify the verb in the sentence
|
33 |
+
verb = input("Identifica el verbo en la siguiente oraci贸n: " + sentence + "\n")
|
34 |
+
|
35 |
+
# Check if the child's answer is correct
|
36 |
+
result = check_answer(sentence, verb)
|
37 |
+
|
38 |
+
# Play sound effect if the answer is correct
|
39 |
+
if "Correcto" in result:
|
40 |
+
sound_effect.play()
|
41 |
+
|
42 |
+
return result
|
43 |
+
|
44 |
+
# Run the chatbot interface using Gradio
|
45 |
+
gr.Interface(fn=chatbot, inputs=None, outputs="text").launch()
|