Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -30,11 +30,16 @@ def text2story(text):
|
|
30 |
Returns:
|
31 |
str: Generated story suitable for kids aged 3-10.
|
32 |
"""
|
33 |
-
#
|
34 |
-
prompt = f"Write a short, happy, and fun story for kids aged 3-10
|
35 |
|
36 |
text_generator = pipeline("text2text-generation", model="t5-small")
|
37 |
-
story = text_generator(prompt, max_length=100)[0]['generated_text']
|
|
|
|
|
|
|
|
|
|
|
38 |
return story
|
39 |
|
40 |
# Function to convert text to audio using gTTS
|
|
|
30 |
Returns:
|
31 |
str: Generated story suitable for kids aged 3-10.
|
32 |
"""
|
33 |
+
# Adjusted prompt to ensure the model generates a story
|
34 |
+
prompt = f"Write a short, happy, and fun story for kids aged 3-10 about: {text}. Make it cheerful, imaginative, and suitable for young children. Avoid any scary or sad elements. The story should be under 95 words."
|
35 |
|
36 |
text_generator = pipeline("text2text-generation", model="t5-small")
|
37 |
+
story = text_generator(prompt, max_length=100, num_return_sequences=1)[0]['generated_text']
|
38 |
+
|
39 |
+
# Remove any repetition of the prompt in the output
|
40 |
+
if prompt in story:
|
41 |
+
story = story.replace(prompt, "").strip()
|
42 |
+
|
43 |
return story
|
44 |
|
45 |
# Function to convert text to audio using gTTS
|