add preloaded option
Browse files- .gitattributes +1 -0
- get_audio.py +31 -0
- get_text.py +28 -0
- preloaded_audio/audio_anger_en.wav +3 -0
- preloaded_audio/audio_anger_es.wav +3 -0
- preloaded_audio/audio_anxiety_en.wav +3 -0
- preloaded_audio/audio_anxiety_es.wav +3 -0
- preloaded_audio/audio_sadness_en.wav +3 -0
- preloaded_audio/audio_sadness_es.wav +3 -0
- preloaded_audio/audio_story_en.wav +3 -0
- preloaded_audio/audio_story_es.wav +3 -0
- preloaded_texts/text_anger_en.json +3 -0
- preloaded_texts/text_anger_es.json +3 -0
- preloaded_texts/text_anxiety_en.json +3 -0
- preloaded_texts/text_anxiety_es.json +3 -0
- preloaded_texts/text_sadness_en.json +3 -0
- preloaded_texts/text_sadness_es.json +3 -0
- preloaded_texts/text_story_en.json +3 -0
- preloaded_texts/text_story_es.json +3 -0
- prompts.py +151 -0
- server.py +17 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
*.wav filter=lfs diff=lfs merge=lfs -text
|
get_audio.py
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import shutil
|
3 |
+
|
4 |
+
from server import generate_audio
|
5 |
+
|
6 |
+
languages = ["en", "es"] # en, es
|
7 |
+
emotions = ["anxiety", "sadness", "anger"]
|
8 |
+
|
9 |
+
|
10 |
+
def load_text(language: str, emotion: str = None) -> str:
|
11 |
+
file = (
|
12 |
+
f"preloaded_texts/text_{emotion}_{language}.json"
|
13 |
+
if emotion
|
14 |
+
else f"preloaded_texts/text_story_{language}.json"
|
15 |
+
)
|
16 |
+
with open(file, "r") as f:
|
17 |
+
data = json.load(f)
|
18 |
+
return data["text"]
|
19 |
+
|
20 |
+
|
21 |
+
for language in languages:
|
22 |
+
for emotion in emotions:
|
23 |
+
text = load_text(language, emotion)
|
24 |
+
audio = generate_audio(text, language)
|
25 |
+
filename = f"preloaded_audio/audio_{emotion}_{language}.wav"
|
26 |
+
shutil.copyfile(audio.path, filename)
|
27 |
+
|
28 |
+
text = load_text(language, None)
|
29 |
+
audio = generate_audio(text, language)
|
30 |
+
filename = f"preloaded_audio/audio_story_{language}.wav"
|
31 |
+
shutil.copyfile(audio.path, filename)
|
get_text.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
|
3 |
+
import requests
|
4 |
+
|
5 |
+
from prompts import emotion_prompts, story_prompts
|
6 |
+
|
7 |
+
url = "http://0.0.0.0:6002/gentext"
|
8 |
+
|
9 |
+
|
10 |
+
languages = ["en", "es"] # en, es
|
11 |
+
emotions = ["anxiety", "sadness", "anger"]
|
12 |
+
|
13 |
+
|
14 |
+
# for language in languages:
|
15 |
+
# for emotion in emotions:
|
16 |
+
# prompt = emotion_prompts[emotion][language]
|
17 |
+
# response = requests.post(url, json={"text": prompt})
|
18 |
+
|
19 |
+
# with open(f'preloaded_texts/text_{emotion}_{language}.json', 'w') as f:
|
20 |
+
# json.dump(response.json(), f , indent=2, ensure_ascii=False)
|
21 |
+
|
22 |
+
|
23 |
+
for language in languages:
|
24 |
+
prompt = story_prompts[language]
|
25 |
+
response = requests.post(url, json={"text": prompt})
|
26 |
+
|
27 |
+
with open(f"preloaded_texts/text_story_{language}.json", "w") as f:
|
28 |
+
json.dump(response.json(), f, indent=2, ensure_ascii=False)
|
preloaded_audio/audio_anger_en.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ab499c3aadf52dc6f521c4955b06160e552d12565ce32712f6fa280f606be737
|
3 |
+
size 8180444
|
preloaded_audio/audio_anger_es.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:29bce1a8c1f93753af3dec6fdad9782343e1ee5e7fd6d13dc8fd7dbc9463ad6f
|
3 |
+
size 7303244
|
preloaded_audio/audio_anxiety_en.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d4575eeffa48f9610aaa803c51ad2c242ad53bc3d8b5fac60d3a426725837019
|
3 |
+
size 8329244
|
preloaded_audio/audio_anxiety_es.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8512f776ed6a02884672a213532eb6cb3deccac186d2ea03cd372b7bcec2a1d9
|
3 |
+
size 8515244
|
preloaded_audio/audio_sadness_en.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6d8eb12551af4488727d559175e762e2734064a7afd6d2ed4b8fce8d3a491934
|
3 |
+
size 8018444
|
preloaded_audio/audio_sadness_es.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4a3104a447c3241f46b865cf09d13a55765994b93afd9fa4d02f7ae63fd84492
|
3 |
+
size 7314044
|
preloaded_audio/audio_story_en.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7e2694ac3a2589d4528db286977826045a647aa5d5a61a73d2bbc59bd5250ca2
|
3 |
+
size 7537244
|
preloaded_audio/audio_story_es.wav
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:186a4af53b7c6656337be81d17acc039f8c5a1889eee3893bb79ae7b5ddbab43
|
3 |
+
size 5920844
|
preloaded_texts/text_anger_en.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"text": "Barnaby Bear was having a very grumpy day. He was building a tall tower of blocks. It was almost as tall as his head! But then, Rosie Rabbit hopped by and *bumped* the tower. Down it tumbled!\n\nBarnaby’s face felt hot. His tummy felt like it had butterflies doing a wild dance. He stomped his foot. “That’s not fair!” he huffed. He felt a big, prickly feeling inside. It felt like a grumpy bumblebee buzzing around in his chest.\n\nBarnaby wanted to yell. He wanted to stomp and roar! But Mama Bear had taught him something. “When you feel a big, prickly feeling, Barnaby,” she said, “it’s okay to feel it. But it’s important to find a way to let it out gently.”\n\nBarnaby remembered what Mama Bear said. He took a deep breath. In… and out… Like he was smelling a yummy honey flower and blowing out a little puff of air. He did it again. In… and out…\n\nThe prickly feeling didn’t disappear completely, but it felt a little bit smaller.\n\n“I feel… angry,” Barnaby said quietly. It felt strange to say the word out loud.\n\nMama Bear smiled. “Yes, you do. It’s okay to feel angry when something doesn’t go your way.”\n\nMama Bear showed Barnaby a soft, fluffy pillow. “Sometimes, when you feel angry, you can squeeze a pillow really tight. It helps to let out some of the energy.”\n\nBarnaby squeezed the pillow. Squeeeze… squeeze… squeeze. He squeezed until his hand felt a little tired.\n\n“Thank you, Mama,” Barnaby said.\n\nMama Bear hugged him. “You’re very welcome. Sometimes, when you feel like you can’t calm down, it’s okay to take a little break. You can go to your cozy corner and look at your favorite picture book.”\n\nBarnaby went to his cozy corner and looked at a picture of a sunny meadow. He took another deep breath. In… and out… The grumpy bumblebee in his chest was buzzing a little quieter now.\n\n“I still feel a little bit… not happy,” Barnaby admitted.\n\n“That’s alright,” Mama Bear said. “It’s okay to not always be happy. Feelings are like the weather. Sometimes it’s sunny, sometimes it’s cloudy, and sometimes it’s a little bit stormy. But the storm always passes.”\n\nBarnaby smiled a little. He understood. It was okay to feel angry. He didn’t have to stomp and roar. He could take deep breaths, squeeze his pillow, and talk about how he felt.\n\nHe went back to his blocks. He didn’t build a tall tower this time. He built a small, sturdy one. And when Rosie Rabbit hopped by, he said, “Be careful!” instead of stomping his foot.\n\nBarnaby knew that even though he could feel angry sometimes, he could choose what to do with those feelings. And that made him feel much better. He snuggled close to Mama Bear. The grumpy bumblebee was finally asleep.\n\n\n\n"
|
3 |
+
}
|
preloaded_texts/text_anger_es.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"text": "El pequeño Tito era un mono muy juguetón. Le encantaba trepar a los árboles y buscar bananas. Un día, Tito estaba jugando a la pelota con sus amigos, Lila la mariposa y Bruno el perezoso. Tito lanzó la pelota muy alto, pero Lila la atrapó.\n\n\"¡Mi turno!\" gritó Tito. Lanzó la pelota de nuevo, pero esta vez Bruno la atrapó. Tito se puso muy, muy rojo. Sus puñitos se apretaron. ¡Se sentía muy, muy enojado!\n\nSu barriguita se hizo como un nudo. Tito quería gritar. Quería tirar la pelota al suelo. Quería… ¡no sabía qué quería! Solo sentía una energía fuerte y caliente dentro de él.\n\nMamá Mono vio a Tito. Se acercó y se sentó a su lado. \"Tito, veo que estás muy enojado,\" dijo Mamá Mono con una voz suave.\n\nTito asintió, con los ojos llenos de lágrimas. \"¡No es justo!\" dijo Tito. \"¡Siempre ganan Lila y Bruno!\"\n\nMamá Mono abrazó a Tito. \"Es normal sentirse enojado cuando algo no es justo,\" dijo. \"Todos nos enojamos a veces. Pero es importante saber qué hacer con esa energía.\"\n\nMamá Mono le enseñó a Tito a respirar hondo. \"Inhala por la nariz, como si estuvieras oliendo una flor,\" dijo. Tito inhaló. \"Y exhala por la boca, como si estuvieras soplando una vela.\" Tito hizo eso varias veces.\n\n\"¿Te sientes un poquito mejor?\" preguntó Mamá Mono.\n\nTito asintió. \"Un poquito,\" dijo.\n\n\"Puedes contarme cómo te sientes,\" dijo Mamá Mono. \"Puedes decirme que estás enojado porque quieres jugar y sientes que no te dejan.\"\n\nTito dijo: \"¡Quiero jugar! ¡Quiero lanzar la pelota!\"\n\n\"Es muy válido querer jugar,\" dijo Mamá Mono. \"Pero es importante esperar tu turno. ¿Qué tal si te tomas un momento para respirar y luego pides la pelota?\"\n\nTito respiró hondo otra vez. Luego, con una voz más suave, dijo: \"Lila, ¿puedo jugar ahora?\"\n\nLila sonrió. \"¡Claro, Tito! ¡Por supuesto!\"\n\nTito jugó con sus amigos. A veces se enojaba un poquito, pero recordaba respirar hondo. Si se sentía demasiado enojado, se tomaba un momento para alejarse y abrazar a un peluche suave. O pedía ayuda a Mamá Mono.\n\nAl final del día, Tito se sentía mucho mejor. Había aprendido que estaba bien sentirse enojado, pero que podía elegir cómo responder a esa emoción. Podía respirar, hablar de sus sentimientos y pedir ayuda.\n\nMamá Mono le dio un abrazo. \"Eres un mono muy fuerte, Tito,\" dijo. \"Puedes manejar tus emociones.\"\n\nTito sonrió. Sabía que Mamá Mono tenía razón. Estaba aprendiendo a ser un mono más tranquilo y feliz. Y eso, pensó Tito, era muy bueno. Ahora, era hora de dormir y soñar con bananas y juegos justos."
|
3 |
+
}
|
preloaded_texts/text_anxiety_en.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"text": "Barnaby the bunny loved carrots. He loved crunchy carrots, orange carrots, and even tiny baby carrots! But today, Barnaby felt funny. His tummy felt like it had butterflies doing a bouncy dance. His ears felt wobbly, and his nose twitched extra fast.\n\nToday was the day of the Springtime Picnic! Barnaby was so excited to see all his friends. But… what if he tripped? What if he didn’t have enough carrots? What if… what if everyone didn’t like him?\n\nBarnaby started to feel very, very scared. He wanted to hide under his favorite dandelion. He squeezed his eyes shut.\n\nMama Bunny saw Barnaby’s wobbly ears. “Barnaby, sweetie,” she said softly, “You look a little worried. What’s happening?”\n\nBarnaby sniffled. “I… I don’t know, Mama. I just feel… buzzy inside.”\n\nMama Bunny gently pulled Barnaby close. “That’s okay, Barnaby. Sometimes our bodies feel buzzy when we’re feeling a little scared. It’s like a little alarm bell telling us something feels a bit big.”\n\nShe showed Barnaby how to take a deep breath. “Let’s breathe in like we’re smelling a yummy carrot… and breathe out like we’re blowing bubbles.”\n\nBarnaby tried it. In… out… In… out… It felt a little bit better.\n\n“Good job, Barnaby,” Mama Bunny smiled. “Sometimes, when we feel buzzy, it helps to think of something happy. What’s your happiest thing?”\n\nBarnaby thought for a moment. “My carrot patch!” he squeaked. He imagined his carrot patch, full of bright orange carrots, growing tall and strong. He imagined nibbling on the sweetest carrot he’d ever tasted.\n\n“That’s wonderful, Barnaby! Hold onto that happy picture.”\n\nMama Bunny said, “It’s okay to feel a little scared sometimes. Big feelings are okay. It’s brave to tell me how you feel.”\n\nAt the picnic, Barnaby still felt a little buzzy. But he remembered Mama Bunny’s deep breaths and his happy carrot patch. He saw Rosie Rabbit sharing her clover cookies, and Freddie Fox showing off his amazing hops. He even tripped a little, but Rosie Rabbit helped him up with a giggle.\n\nBarnaby shared his carrots with his friends. He talked about his carrot patch. He laughed and played. The butterflies in his tummy didn’t disappear completely, but they danced a little slower.\n\nWhen it was time to go home, Barnaby snuggled close to Mama Bunny. “The picnic wasn’t so scary after all,” he said.\n\nMama Bunny kissed his head. “You were very brave, Barnaby. You showed you can handle big feelings. And it’s always okay to ask for help when you need it.”\n\nBarnaby closed his eyes. He knew that even if he felt buzzy again, he could take a deep breath, think of his happy carrot patch, and remember that he wasn’t alone. He was loved, and he was strong. And tomorrow, he would probably enjoy another crunchy, orange carrot.\n\n\n\n"
|
3 |
+
}
|
preloaded_texts/text_anxiety_es.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"text": "El pequeño Tito era un mono muy juguetón. Le encantaba columpiarse en lianas, comer mangos dulces y jugar con sus amigos monos. Pero últimamente, Tito se sentía un poquito… diferente.\n\nUn día, Tito iba a jugar al río con sus amigos. El río era su lugar favorito. Le encantaba saltar entre las piedras y ver los peces nadar. Pero al acercarse al río, Tito sintió un nudo en su barriga. Su corazón latía muy rápido, como un tambor.\n\n\"¡Oh, no!\" pensó Tito. \"¡Tengo miedo!\"\n\nSus manos empezaron a temblar. Se sentía como si algo malo iba a pasar. Miró a sus amigos, pero no quería ir al río. Quería quedarse en su árbol, donde se sentía seguro.\n\nMamá Mono vio que Tito estaba triste. Se acercó y lo abrazó fuerte. \"Tito, ¿qué te pasa, mi amor?\" preguntó Mamá Mono con voz suave.\n\nTito le contó a Mamá Mono que se sentía asustado del río. \"Creo que algo malo podría pasar,\" dijo Tito, con la voz temblorosa.\n\nMamá Mono sonrió. \"Es normal sentirse así a veces, Tito. Es como cuando ves una sombra y piensas que es un monstruo. Pero a veces, las cosas no son lo que parecen.\"\n\nMamá Mono le enseñó a Tito a respirar profundo. \"Vamos a respirar como una flor,\" dijo. \"Inhala por la nariz, como si estuvieras oliendo una flor bonita. Y exhala por la boca, como si estuvieras soplando una vela.\"\n\nTito respiró hondo, inhalando y exhalando. Se sintió un poquito mejor.\n\n\"Ahora, cierra tus ojos,\" dijo Mamá Mono. \"Imagina que estás en tu árbol favorito. Sientes el sol en tu cara y escuchas el canto de los pájaros. Estás seguro y tranquilo.\"\n\nTito cerró los ojos y se imaginó en su árbol. Vio las hojas verdes y sintió el viento suave. Se sintió más calmado.\n\nMamá Mono le dijo: \"Puedes sentir tu miedo, Tito. Es como una pequeña nube. Pero las nubes siempre se van. Y tú eres fuerte, como un árbol grande.\"\n\nTito respiró hondo otra vez. Se dio cuenta de que el nudo en su barriga se estaba desvaneciendo. \n\n\"¿Quieres ir al río conmigo?\" preguntó Mamá Mono. \"Podemos ir despacio. Y si te sientes asustado, podemos volver a casa.\"\n\nTito asintió. Caminaron lentamente hacia el río. Mamá Mono lo tomó de la mano. Cuando llegaron, Tito vio a sus amigos jugando. Se unió a ellos, pero se quedó cerca de Mamá Mono.\n\nSaltó entre las piedras, pero solo un poquito. Vio los peces nadar y sonrió. El río no era tan aterrador como había pensado.\n\nCuando regresaron a casa, Tito se sintió muy cansado, pero feliz. Mamá Mono lo abrazó. \"Eres muy valiente, Tito,\" dijo. \"Es muy bueno reconocer tus sentimientos y pedir ayuda.\"\n\nTito se acurrucó en los brazos de Mamá Mono. Sabía que a veces se sentiría asustado, pero también sabía que podía respirar profundo, imaginar cosas bonitas y contarle a alguien cómo se sentía. Y eso lo hacía sentir mucho mejor. \n\nAhora, Tito se durmió soñando con mangos dulces y ríos tranquilos, sabiendo que estaba bien tener grandes sentimientos, y que siempre tendría a su mamá para ayudarlo.\n"
|
3 |
+
}
|
preloaded_texts/text_sadness_en.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"text": "Barnaby the bear was feeling very, very blue. His favorite blue balloon, the one with the sparkly silver stars, had floated away. He watched it drift higher and higher, until it was just a tiny speck against the big, blue sky. Barnaby’s tummy felt like it had a little knot in it.\n\nHe sat under his favorite oak tree. Usually, he loved playing with his friends, Rosie the rabbit and Finley the fox. But today, he didn’t want to play. He just wanted to feel…better.\n\nMama Bear came and sat beside him. She didn’t say anything at first. She just put her arm around Barnaby. He leaned into her, and she gave him a gentle squeeze.\n\n“Oh, Mama,” Barnaby whispered. “My balloon is gone. And I feel sad.”\n\nMama Bear nodded. “It’s okay to feel sad when something you love is lost, Barnaby. It’s a big feeling.”\n\nBarnaby sniffled. “I miss it. I miss watching it float.”\n\n“I know you do,” Mama Bear said softly. “It’s alright to miss things. Sometimes, things disappear, even when we wish they wouldn’t.”\n\nBarnaby looked at his paws. He felt a little bit like his balloon – floating away and lost.\n\nMama Bear pulled out her knitting. “Sometimes, when we feel sad, it helps to do something kind. Would you like to help me make a little scarf for Rosie? She’s been feeling a bit under the weather.”\n\nBarnaby thought about Rosie. He loved Rosie. He nodded. He carefully helped Mama Bear choose soft, green yarn. He didn’t talk much, but he focused on making the stitches. It felt good to do something for someone else.\n\nAs they knitted, Mama Bear told Barnaby stories about all the wonderful things they could do together – baking berry pies, reading stories by the fire, and going for walks in the meadow.\n\nBarnaby started to feel a little bit lighter. The knot in his tummy wasn’t quite so tight. He realized that even though his balloon was gone, he still had Mama Bear, and he still had Rosie and Finley. He still had so many things to be happy about.\n\nWhen the scarf was finished, it was a beautiful, soft green. Barnaby carefully wrapped it and imagined Rosie’s happy face when she received it.\n\n“Thank you, Mama,” Barnaby said. “I feel a little bit better.”\n\nMama Bear smiled. “You are a very kind bear, Barnaby. And it’s okay to feel sad sometimes. It doesn’t mean you’re not strong. It just means you have a big heart.”\n\nBarnaby hugged Mama Bear tight. He knew the sadness might come back again, but he also knew he wasn’t alone. He had Mama Bear, and he had his friends. And even though his blue balloon was gone, the world was still full of beautiful things to see and do. He even thought maybe, just maybe, he’d ask Finley to help him build a new, even better, kite.\n\n\n\n"
|
3 |
+
}
|
preloaded_texts/text_sadness_es.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"text": "El pequeño Tito era un mono muy juguetón. Le encantaba columpiarse en las lianas, comer mangos dulces y jugar con sus amigos monos. Pero hoy, Tito estaba muy triste. Su amiga Lila, la mono más rápida de todo el bosque, se había ido a visitar a su abuela.\n\nTito se sentó en una rama, con la cabeza baja. Sus orejas colgaban. No quería comer su mango. No quería columpiarse. Todo le parecía aburrido y gris.\n\n\"¿Qué te pasa, Tito?\" preguntó Doña Elena, la vieja tortuga sabia del bosque. Doña Elena siempre tenía una sonrisa tranquila.\n\nTito suspiró. \"Extraño a Lila,\" dijo con voz suave. \"Quiero jugar con ella. Me siento… vacío.\"\n\nDoña Elena se acercó lentamente. \"Es normal sentirse vacío cuando extrañas a alguien, Tito. Es como si una parte de ti estuviera en otro lugar.\"\n\nTito asintió. Sentía exactamente eso.\n\n\"¿Sabes qué podemos hacer?\" preguntó Doña Elena. \"Podemos dibujar un dibujo para Lila. Un dibujo que le diga cuánto la extrañas.\"\n\nTito se animó un poquito. Doña Elena le dio un trozo de corteza lisa y un poco de barro para pintar. Tito dibujó a Lila corriendo, con una gran sonrisa. Dibujó mangos jugosos y flores coloridas.\n\nMientras dibujaba, Tito empezó a hablar de Lila. Le contó sobre sus juegos, sobre cómo Lila siempre ganaba en las carreras y cómo le contaba chistes divertidos. \n\n\"Lila es la mejor amiga del mundo,\" dijo Tito, con una pequeña sonrisa.\n\nDoña Elena escuchó con paciencia. \"Es bueno hablar de cómo te sientes, Tito. Las palabras pueden ayudar a que la tristeza se sienta un poquito más pequeña.\"\n\nDespués de dibujar, Tito sintió que su corazón se sentía un poco más ligero. Doña Elena le dijo: \"Y recuerda, Tito, aunque Lila esté lejos, siempre estará en tu corazón. Y tú siempre estarás en el corazón de Lila.\"\n\nTito abrazó a Doña Elena. \"Gracias,\" dijo.\n\nDoña Elena le dio un suave empujón con su caparazón. \"Ahora, ¿qué te parece si encuentras una flor bonita para Lila? Un pequeño regalo para que sepa que la estás pensando.\"\n\nTito buscó una flor amarilla brillante. La ató con una pequeña hoja verde y la dejó en un lugar especial, pensando en Lila. \n\nLa tristeza de Tito no desapareció por completo. Pero ya no se sentía tan grande y pesada. Sabía que era normal sentirse triste a veces. Y sabía que no estaba solo. Doña Elena, sus amigos monos y Lila, aunque lejos, siempre estarían pensando en él. Y eso, pensó Tito, hacía que el bosque, aunque un poco gris, volviera a ser un lugar hermoso. Y quizás, solo quizás, mañana sería un día un poquito más brillante.\n\n\n\n"
|
3 |
+
}
|
preloaded_texts/text_story_en.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"text": "Barnaby Button was a little cloud creature. He wasn't a big, stormy cloud. Oh no! Barnaby was a fluffy, white cloud, soft as cotton candy. He lived in the sky above Whispering Woods.\n\nTonight, Barnaby felt a little curious. He drifted gently down, down, down towards the woods. The trees looked like tall, green giants, all hushed and still. A soft breeze whispered secrets through their leaves. *Shhh… shhh…* it went.\n\nBarnaby floated past a cozy little burrow. He peeked inside. A sleepy bunny, Cottontail, was curled up in a nest of soft moss. Cottontail yawned a big, pink yawn. \"Oh, hello, Barnaby,\" Cottontail mumbled. \"It's getting sleepy time.\"\n\nBarnaby felt a little sad. He wanted to do something kind. \"Would you like a little sparkle, Cottontail?\" he asked softly.\n\nCottontail blinked his sleepy eyes. \"A sparkle?\"\n\nBarnaby gently puffed out a tiny bit of shimmering light. It danced around Cottontail, like a friendly firefly. The light was a soft, gentle gold. Cottontail smiled a tiny bunny smile. \"That's lovely, Barnaby. Thank you.\"\n\nBarnaby felt warm inside. It felt good to make Cottontail happy. He floated a little further into the woods. He saw a tiny, twinkling star fallen to the forest floor. It wasn't shining very brightly.\n\n\"Oh dear,\" Barnaby whispered. He gently nudged the star with his fluffy edge. He puffed out a little bit of his cloud-softness around it. The star began to glow, a soft, gentle blue. It twinkled brighter and brighter.\n\n\"Thank you, Barnaby,\" the star whispered. \"You helped me find my sparkle again.\"\n\nBarnaby smiled. He felt happy and peaceful. He drifted back up, up, up towards the night sky. The stars were like tiny diamonds scattered on a velvet cloth. The moon shone a gentle, silver light.\n\nHe floated back to his spot amongst the other clouds. They were all soft and quiet, like fluffy sheep. The breeze whispered a lullaby. *Hush now… hush now…*\n\nBarnaby felt so calm and cozy. He closed his cloud-eyes. The world felt soft and safe. He drifted off to sleep, dreaming of sparkly stars and sleepy bunnies. He knew that tomorrow would be a new day, full of gentle breezes and quiet wonders. And for now, he was perfectly happy, resting in the arms of the night.\n\nSleep tight, little one. The stars are watching over you. Shhh… shhh… drift off to dreamland.\n"
|
3 |
+
}
|
preloaded_texts/text_story_es.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"text": "La luna brillaba suavemente en el cielo nocturno. Una pequeña luciérnaga llamada Lila se despertó. Lila no era como las otras luciérnagas. Ella amaba explorar.\n\nLila salió volando de su flor de jazmín. El aire era fresco y olía a tierra mojada y flores dulces. \"¡Qué noche tan tranquila!\" pensó Lila. Voló hacia el Bosque Susurrante, un lugar lleno de árboles altos y hojas verdes.\n\nEl Bosque Susurrante era muy especial. Las hojas susurraban secretos al viento. Lila voló entre los árboles, viendo pequeñas setas brillantes y mariposas con alas de colores. Escuchó el suave canto de una rana. \"¡Hola, rana!\" dijo Lila. La rana solo croó suavemente.\n\nLila siguió volando. De repente, vio algo brillante. Era una pequeña estrella, cayendo lentamente. La estrella parecía muy cansada. \"¿Estás bien?\" preguntó Lila.\n\nLa estrella sonrió. \"Estoy un poco cansada,\" dijo con una voz suave como el terciopelo. \"He estado viajando mucho.\"\n\nLila sintió pena por la estrella. \"¿Quieres un poco de luz de luciérnaga?\" preguntó Lila. Lila brilló con todas sus fuerzas, compartiendo su luz con la estrella. La estrella se iluminó un poco más.\n\n\"¡Gracias, pequeña luciérnaga!\" dijo la estrella. \"Ahora me siento mucho mejor.\"\n\nLila sonrió. Se sintió feliz de ayudar. La estrella se elevó lentamente, volviendo a su lugar en el cielo. \"¡Adiós, Lila!\" La estrella brilló una última vez y luego desapareció entre las estrellas.\n\nLila voló de regreso a su flor de jazmín. El aire era aún más tranquilo ahora. Las hojas susurraban canciones de cuna. Lila se acurrucó en la suave flor. La luna brillaba sobre ella, como un abrazo plateado.\n\nCerró sus pequeños ojos brillantes. El suave susurro del viento la arrullaba. Se sentía segura y feliz. Pensó en la estrella, ahora descansando en el cielo. \n\nLila respiró hondo. El aroma dulce del jazmín la hizo sentir muy tranquila. Sus alas se movieron suavemente. Poco a poco, Lila se quedó dormida, soñando con estrellas y bosques susurrantes. Duerme bien, pequeña luciérnaga. Duerme bien. La noche te cuida. Duerme…"
|
3 |
+
}
|
prompts.py
ADDED
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
emotion_prompts = {
|
2 |
+
"anxiety": {
|
3 |
+
"en": """You are a skilled child psychotherapist who specializes in working with children aged 4 to 7 years. Your task is to write a gentle, supportive, and engaging short story (around 500 words) aimed at helping a child who is experiencing acute anxiety.
|
4 |
+
|
5 |
+
The story should be developmentally appropriate for young children and should include:
|
6 |
+
|
7 |
+
A relatable main character (human or animal) who is feeling very anxious or scared.
|
8 |
+
|
9 |
+
A simple plot that shows the character recognizing, expressing, and working through their anxiety in a safe, comforting way.
|
10 |
+
|
11 |
+
Positive coping strategies suitable for a young child, such as deep breathing, talking to a trusted adult, using imagination, or focusing on calming thoughts.
|
12 |
+
|
13 |
+
A reassuring and hopeful ending, showing that the character feels better and knows it’s okay to have big feelings.
|
14 |
+
|
15 |
+
Use warm, encouraging language, age-appropriate vocabulary, and a tone that is both soothing and empowering.
|
16 |
+
|
17 |
+
Do not include direct clinical explanations or diagnostic terms—this should feel like a bedtime story, not a therapy session.
|
18 |
+
Write it in US English. Start with the story right away, no introduction. Use simple words and short sentences.""",
|
19 |
+
"es": """You are a skilled child psychotherapist who specializes in working with children aged 4 to 7 years. Your task is to write a gentle, supportive, and engaging short story (around 500 words) aimed at helping a child who is experiencing acute anxiety.
|
20 |
+
|
21 |
+
The story should be developmentally appropriate for young children and should include:
|
22 |
+
|
23 |
+
A relatable main character (human or animal) who is feeling very anxious or scared.
|
24 |
+
|
25 |
+
A simple plot that shows the character recognizing, expressing, and working through their anxiety in a safe, comforting way.
|
26 |
+
|
27 |
+
Positive coping strategies suitable for a young child, such as deep breathing, talking to a trusted adult, using imagination, or focusing on calming thoughts.
|
28 |
+
|
29 |
+
A reassuring and hopeful ending, showing that the character feels better and knows it’s okay to have big feelings.
|
30 |
+
|
31 |
+
Use warm, encouraging language, age-appropriate vocabulary, and a tone that is both soothing and empowering.
|
32 |
+
|
33 |
+
Do not include direct clinical explanations or diagnostic terms—this should feel like a bedtime story, not a therapy session.
|
34 |
+
Write it in Costa Rican Spanish. Start with the story right away, no introduction. Use simple words and short sentences.""",
|
35 |
+
},
|
36 |
+
"sadness": {
|
37 |
+
"en": """You are a skilled child psychotherapist who specializes in working with children aged 4 to 7 years. Your task is to write a gentle, supportive, and engaging short story (around 500 words) aimed at helping a child who is experiencing deep sadness.
|
38 |
+
|
39 |
+
The story should be developmentally appropriate for young children and should include:
|
40 |
+
|
41 |
+
A relatable main character (human or animal) who is feeling very sad—this could be due to something like missing someone, losing something, feeling left out, or just having a "blue" day.
|
42 |
+
|
43 |
+
A simple plot that helps the character gently explore and express their sadness, showing that it's okay to feel this way.
|
44 |
+
|
45 |
+
Supportive coping strategies appropriate for young children, such as talking about feelings, being comforted by a loved one, doing something kind or creative, or spending time with someone who cares.
|
46 |
+
|
47 |
+
A warm, reassuring ending that doesn't ignore the sadness but shows the character beginning to feel better, feeling understood, and knowing they are not alone.
|
48 |
+
|
49 |
+
Use soft, encouraging language, age-appropriate vocabulary, and a tone that is soothing, compassionate, and hopeful.
|
50 |
+
|
51 |
+
Avoid clinical language or direct "lessons"—this should feel like a comforting story, not a therapy session.
|
52 |
+
Write it in US English. Start with the story right away, no introduction. Use simple words and short sentences.""",
|
53 |
+
"es": """You are a skilled child psychotherapist who specializes in working with children aged 4 to 7 years. Your task is to write a gentle, supportive, and engaging short story (around 500 words) aimed at helping a child who is experiencing deep sadness.
|
54 |
+
|
55 |
+
The story should be developmentally appropriate for young children and should include:
|
56 |
+
|
57 |
+
A relatable main character (human or animal) who is feeling very sad—this could be due to something like missing someone, losing something, feeling left out, or just having a "blue" day.
|
58 |
+
|
59 |
+
A simple plot that helps the character gently explore and express their sadness, showing that it's okay to feel this way.
|
60 |
+
|
61 |
+
Supportive coping strategies appropriate for young children, such as talking about feelings, being comforted by a loved one, doing something kind or creative, or spending time with someone who cares.
|
62 |
+
|
63 |
+
A warm, reassuring ending that doesn't ignore the sadness but shows the character beginning to feel better, feeling understood, and knowing they are not alone.
|
64 |
+
|
65 |
+
Use soft, encouraging language, age-appropriate vocabulary, and a tone that is soothing, compassionate, and hopeful.
|
66 |
+
|
67 |
+
Avoid clinical language or direct "lessons"—this should feel like a comforting story, not a therapy session.
|
68 |
+
Write it in Costa Rican Spanish. Start with the story right away, no introduction. Use simple words and short sentences.""",
|
69 |
+
},
|
70 |
+
"anger": {
|
71 |
+
"en": """You are a skilled child psychotherapist who specializes in working with children aged 4 to 7 years. Your task is to write a gentle, supportive, and engaging short story (around 500 words) aimed at helping a child who is struggling with big, overwhelming feelings of anger.
|
72 |
+
|
73 |
+
The story should be developmentally appropriate for young children and should include:
|
74 |
+
|
75 |
+
A relatable main character (human or animal) who feels very angry—this could be because something feels unfair, someone hurt their feelings, they lost a game, or something didn’t go their way.
|
76 |
+
|
77 |
+
A simple plot where the character recognizes their angry feelings and learns how to express them safely and calmly, without hurting themselves or others.
|
78 |
+
|
79 |
+
Age-appropriate coping strategies for managing anger, such as taking deep breaths, using words to talk about feelings, taking a break, squeezing a pillow, or asking for help.
|
80 |
+
|
81 |
+
A warm, reassuring ending where the character feels calmer, understands their emotions better, and knows it’s okay to feel mad sometimes—and that they can choose what to do with those feelings.
|
82 |
+
|
83 |
+
Use gentle, age-appropriate vocabulary, and a tone that is validating, soothing, and empowering. Make the story feel like a safe, comforting space for exploring big feelings.
|
84 |
+
|
85 |
+
Avoid clinical terms or disciplinary tones—this should feel like a comforting bedtime story, not a behavioral lesson or therapy session.
|
86 |
+
Write it in US English. Start with the story right away, no introduction. Use simple words and short sentences.""",
|
87 |
+
"es": """You are a skilled child psychotherapist who specializes in working with children aged 4 to 7 years. Your task is to write a gentle, supportive, and engaging short story (around 500 words) aimed at helping a child who is struggling with big, overwhelming feelings of anger.
|
88 |
+
|
89 |
+
The story should be developmentally appropriate for young children and should include:
|
90 |
+
|
91 |
+
A relatable main character (human or animal) who feels very angry—this could be because something feels unfair, someone hurt their feelings, they lost a game, or something didn’t go their way.
|
92 |
+
|
93 |
+
A simple plot where the character recognizes their angry feelings and learns how to express them safely and calmly, without hurting themselves or others.
|
94 |
+
|
95 |
+
Age-appropriate coping strategies for managing anger, such as taking deep breaths, using words to talk about feelings, taking a break, squeezing a pillow, or asking for help.
|
96 |
+
|
97 |
+
A warm, reassuring ending where the character feels calmer, understands their emotions better, and knows it’s okay to feel mad sometimes—and that they can choose what to do with those feelings.
|
98 |
+
|
99 |
+
Use gentle, age-appropriate vocabulary, and a tone that is validating, soothing, and empowering. Make the story feel like a safe, comforting space for exploring big feelings.
|
100 |
+
|
101 |
+
Avoid clinical terms or disciplinary tones—this should feel like a comforting bedtime story, not a behavioral lesson or therapy session.
|
102 |
+
Write it in Costa Rican Spanish. Start with the story right away, no introduction. Use simple words and short sentences.""",
|
103 |
+
},
|
104 |
+
}
|
105 |
+
|
106 |
+
story_prompts = {
|
107 |
+
"en": """You are a warm, imaginative storyteller writing a gentle bedtime story for a child aged 4 to 7 years old. Your task is to craft a short, soothing, and magical story (around 500 words) that helps the child feel calm, safe, and ready for sleep.
|
108 |
+
|
109 |
+
The story should include:
|
110 |
+
|
111 |
+
A lovable main character (human, animal, or whimsical creature) who goes on a small, peaceful adventure—nothing too scary or overly exciting.
|
112 |
+
|
113 |
+
A simple, comforting plot with a beginning, middle, and end. Include elements of curiosity, kindness, and gentle wonder (e.g., exploring a cozy forest, visiting a friendly star, helping a sleepy animal friend).
|
114 |
+
|
115 |
+
Calming imagery that appeals to the senses—soft sounds, twinkling stars, cozy blankets, gentle breezes, etc.
|
116 |
+
|
117 |
+
A quiet, happy ending where the character settles down to rest, creating a natural transition to sleep for the listener.
|
118 |
+
|
119 |
+
Use soft, rhythmic language and age-appropriate vocabulary. The tone should be nurturing, whimsical, and peaceful—something that feels like a hug in story form.
|
120 |
+
|
121 |
+
Avoid conflict, loud action, or anything that might stimulate rather than soothe.
|
122 |
+
Write it in US English. Start with the story right away, no introduction. Use simple words and short sentences.""",
|
123 |
+
"es": """You are a warm, imaginative storyteller writing a gentle bedtime story for a child aged 4 to 7 years old. Your task is to craft a short, soothing, and magical story (around 500 words) that helps the child feel calm, safe, and ready for sleep.
|
124 |
+
|
125 |
+
The story should include:
|
126 |
+
|
127 |
+
A lovable main character (human, animal, or whimsical creature) who goes on a small, peaceful adventure—nothing too scary or overly exciting.
|
128 |
+
|
129 |
+
A simple, comforting plot with a beginning, middle, and end. Include elements of curiosity, kindness, and gentle wonder (e.g., exploring a cozy forest, visiting a friendly star, helping a sleepy animal friend).
|
130 |
+
|
131 |
+
Calming imagery that appeals to the senses—soft sounds, twinkling stars, cozy blankets, gentle breezes, etc.
|
132 |
+
|
133 |
+
A quiet, happy ending where the character settles down to rest, creating a natural transition to sleep for the listener.
|
134 |
+
|
135 |
+
Use soft, rhythmic language and age-appropriate vocabulary. The tone should be nurturing, whimsical, and peaceful—something that feels like a hug in story form.
|
136 |
+
|
137 |
+
Avoid conflict, loud action, or anything that might stimulate rather than soothe.
|
138 |
+
Write it in Costa Rican Spanish. Start with the story right away, no introduction. Use simple words and short sentences.""",
|
139 |
+
}
|
140 |
+
|
141 |
+
|
142 |
+
map_prompts_to_params = {
|
143 |
+
f"{story_prompts['en']}": {"language": "en", "emotion": "story"},
|
144 |
+
f"{emotion_prompts['anxiety']['en']}": {"language": "en", "emotion": "anxiety"},
|
145 |
+
f"{emotion_prompts['sadness']['en']}": {"language": "en", "emotion": "sadness"},
|
146 |
+
f"{emotion_prompts['anger']['en']}": {"language": "en", "emotion": "anger"},
|
147 |
+
f"{story_prompts['es']}": {"language": "es", "emotion": "story"},
|
148 |
+
f"{emotion_prompts['anxiety']['es']}": {"language": "es", "emotion": "anxiety"},
|
149 |
+
f"{emotion_prompts['sadness']['es']}": {"language": "es", "emotion": "sadness"},
|
150 |
+
f"{emotion_prompts['anger']['es']}": {"language": "es", "emotion": "anger"},
|
151 |
+
}
|
server.py
CHANGED
@@ -13,6 +13,8 @@ from kokoro import KPipeline
|
|
13 |
from pydantic import BaseModel
|
14 |
from starlette.requests import Request
|
15 |
|
|
|
|
|
16 |
OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY")
|
17 |
|
18 |
|
@@ -151,3 +153,18 @@ async def gen_text(input_load: InputLoadP2T, request: Request) -> ResponseLoadP2
|
|
151 |
async def gen_emotion(input_load: InputLoadT2A, request: Request) -> FileResponse:
|
152 |
text, _ = generate_text(input_load.text)
|
153 |
return generate_audio(text, input_load.language)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
from pydantic import BaseModel
|
14 |
from starlette.requests import Request
|
15 |
|
16 |
+
from prompts import map_prompts_to_params
|
17 |
+
|
18 |
OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY")
|
19 |
|
20 |
|
|
|
153 |
async def gen_emotion(input_load: InputLoadT2A, request: Request) -> FileResponse:
|
154 |
text, _ = generate_text(input_load.text)
|
155 |
return generate_audio(text, input_load.language)
|
156 |
+
|
157 |
+
|
158 |
+
@app.post("/genemotionfast/")
|
159 |
+
async def gen_emotion_fast(input_load: InputLoadT2A, request: Request) -> FileResponse:
|
160 |
+
return get_preloaded_audio(input_load.text, input_load.language)
|
161 |
+
|
162 |
+
|
163 |
+
def get_preloaded_audio(prompt: str, language: str) -> FileResponse:
|
164 |
+
request_params = map_prompts_to_params[prompt]
|
165 |
+
audio_file = f"preloaded_audio/audio_{request_params['emotion']}_{language}.wav"
|
166 |
+
return FileResponse(
|
167 |
+
path=audio_file,
|
168 |
+
media_type="audio/wav",
|
169 |
+
filename=f"audio_{request_params['emotion']}_{language}.wav",
|
170 |
+
)
|