IrisDeng commited on
Commit
9e09636
·
verified ·
1 Parent(s): 97efbf3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -28,7 +28,7 @@ def build_children_story(image_description):
28
  "Using the details derived from the image below, craft a complete and captivating tale that includes three main characters, "
29
  "an adventurous journey, and delightful surprises. "
30
  "Your story should have a clear beginning, middle, and end, and be between 80 and 100 words in length.\n\n"
31
- f"Image Details: {caption_detail}\n\nStory:"
32
  )
33
 
34
  generated_output = story_pipeline(
@@ -46,15 +46,15 @@ def build_children_story(image_description):
46
  story_text = raw_story.strip()
47
 
48
  story_words = story_text.split()
49
- if len(story_words) > 100:
50
- trimmed_story = " ".join(story_words[:100])
51
  last_period = trimmed_story.rfind(".")
52
  last_exclamation = trimmed_story.rfind("!")
53
  last_question = trimmed_story.rfind("?")
54
- final_index = max(last_period, last_exclamation, last_question)
55
 
56
- if final_index != -1:
57
- trimmed_story = trimmed_story[:final_index + 1]
58
 
59
  story_text = trimmed_story
60
 
 
28
  "Using the details derived from the image below, craft a complete and captivating tale that includes three main characters, "
29
  "an adventurous journey, and delightful surprises. "
30
  "Your story should have a clear beginning, middle, and end, and be between 80 and 100 words in length.\n\n"
31
+ f"Image Details: {caption_result}\n\nStory:"
32
  )
33
 
34
  generated_output = story_pipeline(
 
46
  story_text = raw_story.strip()
47
 
48
  story_words = story_text.split()
49
+ if len(story_words) > 95:
50
+ trimmed_story = " ".join(story_words[:95])
51
  last_period = trimmed_story.rfind(".")
52
  last_exclamation = trimmed_story.rfind("!")
53
  last_question = trimmed_story.rfind("?")
54
+ index = max(last_period, last_exclamation, last_question)
55
 
56
+ if index != -1:
57
+ trimmed_story = trimmed_story[:index + 1]
58
 
59
  story_text = trimmed_story
60