Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -44,7 +44,7 @@ def generate_caption(image):
|
|
44 |
def generate_story(caption):
|
45 |
# Generate the story based on the caption using the GPT-2 model
|
46 |
prompt = f"Once upon a time, based on the image described as '{caption}', here is a short, simple, and engaging story for children aged 3-10. The story should be easy to understand, use age-appropriate language, and convey a positive message. Focus on the main elements in the image and create a story that sparks their imagination:\n\n"
|
47 |
-
story = story_generator(prompt, max_length=
|
48 |
|
49 |
# Extract the story text from the generated output
|
50 |
story = story.split("\n\n")[1].strip()
|
@@ -53,8 +53,14 @@ def generate_story(caption):
|
|
53 |
inappropriate_words = ["violence", "horror", "scary"]
|
54 |
for word in inappropriate_words:
|
55 |
story = story.replace(word, "")
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
return story
|
|
|
58 |
|
59 |
def convert_to_audio(story):
|
60 |
# Convert the story to audio using gTTS
|
|
|
44 |
def generate_story(caption):
|
45 |
# Generate the story based on the caption using the GPT-2 model
|
46 |
prompt = f"Once upon a time, based on the image described as '{caption}', here is a short, simple, and engaging story for children aged 3-10. The story should be easy to understand, use age-appropriate language, and convey a positive message. Focus on the main elements in the image and create a story that sparks their imagination:\n\n"
|
47 |
+
story = story_generator(prompt, max_length=500, num_return_sequences=1)[0]["generated_text"]
|
48 |
|
49 |
# Extract the story text from the generated output
|
50 |
story = story.split("\n\n")[1].strip()
|
|
|
53 |
inappropriate_words = ["violence", "horror", "scary"]
|
54 |
for word in inappropriate_words:
|
55 |
story = story.replace(word, "")
|
56 |
+
|
57 |
+
# Limit the story to approximately 100 words
|
58 |
+
words = story.split()
|
59 |
+
if len(words) > 100:
|
60 |
+
story = " ".join(words[:100]) + "..."
|
61 |
|
62 |
return story
|
63 |
+
|
64 |
|
65 |
def convert_to_audio(story):
|
66 |
# Convert the story to audio using gTTS
|