Szeyu commited on
Commit
2e2fdf8
·
verified ·
1 Parent(s): e1351c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -5
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
- # Log the raw result for debugging (viewable in server logs)
 
95
  print("Story generation raw result:", result)
96
 
97
  raw_story = result[0].get("generated_text", "").strip()
98
- if not raw_story:
99
- raw_story = "Once upon a time, the park was filled with laughter as children played happily under the bright sun."
 
 
 
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