IrisDeng commited on
Commit
8498664
·
verified ·
1 Parent(s): a889633

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -17,18 +17,21 @@ def extract_image_caption(image_data):
17
  def compose_story_from_caption(caption_detail):
18
  prompt_text = (
19
  "You are a talented and imaginative storyteller for children aged 3 to 10. "
20
- "Using the details derived from the image below, craft a captivating tale that goes beyond merely describing the scene. "
21
- "Let your creativity shine by introducing engaging characters, adventurous journeys, and delightful surprises. "
22
  "Your story should be vivid, original, and between 90 and 100 words in length.\n\n"
23
  f"Image Details: {caption_detail}\n\nStory:"
24
  )
25
- story_results = story_pipeline(prompt_text, num_return_sequences=1)
 
 
26
  story_text = story_results[0]['generated_text']
27
 
 
28
  if "Story:" in story_text:
29
  return story_text.split("Story:", 1)[1].strip()
30
  return story_text.strip()
31
-
32
  def convert_text_to_audio(text_content, audio_path="output.mp3"):
33
  """
34
  将文本转换为音频文件。
 
17
  def compose_story_from_caption(caption_detail):
18
  prompt_text = (
19
  "You are a talented and imaginative storyteller for children aged 3 to 10. "
20
+ "Using the details derived from the image below, craft a captivating tale that includes three main characters, "
21
+ "an adventurous journey, and delightful surprises. "
22
  "Your story should be vivid, original, and between 90 and 100 words in length.\n\n"
23
  f"Image Details: {caption_detail}\n\nStory:"
24
  )
25
+
26
+ # 生成故事,设置最大长度为150,以确保有足够空间生成90-100词的内容
27
+ story_results = story_pipeline(prompt_text, num_return_sequences=1, max_length=150)
28
  story_text = story_results[0]['generated_text']
29
 
30
+ # 提取故事文本
31
  if "Story:" in story_text:
32
  return story_text.split("Story:", 1)[1].strip()
33
  return story_text.strip()
34
+
35
  def convert_text_to_audio(text_content, audio_path="output.mp3"):
36
  """
37
  将文本转换为音频文件。