Update app.py
Browse files
app.py
CHANGED
|
@@ -76,8 +76,6 @@ def get_story(caption):
|
|
| 76 |
"""
|
| 77 |
Generates a humorous and engaging children's story based on the caption.
|
| 78 |
Uses a prompt to instruct the model and limits token generation to 80 tokens.
|
| 79 |
-
|
| 80 |
-
If no text is generated, a fallback story is returned.
|
| 81 |
"""
|
| 82 |
prompt = (
|
| 83 |
f"Write a funny, warm, and imaginative children's story for ages 3-10, 50-100 words, "
|
|
@@ -91,12 +89,16 @@ def get_story(caption):
|
|
| 91 |
top_p=0.9,
|
| 92 |
return_full_text=False
|
| 93 |
)
|
| 94 |
-
|
|
|
|
| 95 |
print("Story generation raw result:", result)
|
| 96 |
|
| 97 |
raw_story = result[0].get("generated_text", "").strip()
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
| 100 |
words = raw_story.split()
|
| 101 |
story = " ".join(words[:100])
|
| 102 |
return story
|
|
|
|
| 76 |
"""
|
| 77 |
Generates a humorous and engaging children's story based on the caption.
|
| 78 |
Uses a prompt to instruct the model and limits token generation to 80 tokens.
|
|
|
|
|
|
|
| 79 |
"""
|
| 80 |
prompt = (
|
| 81 |
f"Write a funny, warm, and imaginative children's story for ages 3-10, 50-100 words, "
|
|
|
|
| 89 |
top_p=0.9,
|
| 90 |
return_full_text=False
|
| 91 |
)
|
| 92 |
+
|
| 93 |
+
# Log the raw result for debugging (this is viewable in the server logs)
|
| 94 |
print("Story generation raw result:", result)
|
| 95 |
|
| 96 |
raw_story = result[0].get("generated_text", "").strip()
|
| 97 |
+
|
| 98 |
+
# Remove the prompt from the output if it is included.
|
| 99 |
+
if raw_story.startswith(prompt):
|
| 100 |
+
raw_story = raw_story[len(prompt):].strip()
|
| 101 |
+
|
| 102 |
words = raw_story.split()
|
| 103 |
story = " ".join(words[:100])
|
| 104 |
return story
|