Update app.py
Browse files
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: {
|
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) >
|
50 |
-
trimmed_story = " ".join(story_words[:
|
51 |
last_period = trimmed_story.rfind(".")
|
52 |
last_exclamation = trimmed_story.rfind("!")
|
53 |
last_question = trimmed_story.rfind("?")
|
54 |
-
|
55 |
|
56 |
-
if
|
57 |
-
trimmed_story = trimmed_story[:
|
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 |
|