Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -28,15 +28,15 @@ def generate_caption(image):
|
|
28 |
|
29 |
def generate_story(caption):
|
30 |
# Generate the story based on the caption using the GPT-2 model
|
31 |
-
prompt = f"Once upon a time, in a world inspired by the image
|
32 |
story = story_generator(prompt, max_length=500, num_return_sequences=1)[0]["generated_text"]
|
33 |
|
34 |
# Extract the story text from the generated output
|
35 |
story_parts = story.split("\n\n")
|
36 |
-
if len(story_parts) >
|
37 |
-
story = "\n\n".join(story_parts[
|
38 |
else:
|
39 |
-
story = story_parts
|
40 |
|
41 |
# Post-process the story (example: remove inappropriate words)
|
42 |
inappropriate_words = ["violence", "horror", "scary"]
|
|
|
28 |
|
29 |
def generate_story(caption):
|
30 |
# Generate the story based on the caption using the GPT-2 model
|
31 |
+
prompt = f"Once upon a time, in a world inspired by the image of {caption}, a magical story took place. The fairy tale, suitable for children aged 3-10, unfolds as follows:\n\nIntroduction: Set the scene and introduce the main characters.\n\nConflict: Present a problem or challenge the characters face.\n\nResolution: Describe how the characters solve the problem or overcome the challenge.\n\nMoral: Conclude with a positive message or lesson learned.\n\nThe story should be well-structured, engaging, and easy to understand for young children. Let's begin:\n\n"
|
32 |
story = story_generator(prompt, max_length=500, num_return_sequences=1)[0]["generated_text"]
|
33 |
|
34 |
# Extract the story text from the generated output
|
35 |
story_parts = story.split("\n\n")
|
36 |
+
if len(story_parts) > 5:
|
37 |
+
story = "\n\n".join(story_parts[5:]).strip()
|
38 |
else:
|
39 |
+
story = "\n\n".join(story_parts).strip()
|
40 |
|
41 |
# Post-process the story (example: remove inappropriate words)
|
42 |
inappropriate_words = ["violence", "horror", "scary"]
|