Update app.py
Browse files
app.py
CHANGED
@@ -19,13 +19,6 @@ def load_pipelines():
|
|
19 |
|
20 |
captioner, storyer, tts = load_pipelines()
|
21 |
|
22 |
-
# Function to extract keywords from caption
|
23 |
-
def extract_keywords(caption):
|
24 |
-
stop_words = {'the', 'a', 'an', 'in', 'on', 'at', 'of', 'to', 'is', 'are', 'with', 'and'}
|
25 |
-
words = caption.lower().split()
|
26 |
-
keywords = [word.strip(".,!?\"'") for word in words if word not in stop_words and len(word) > 2]
|
27 |
-
return keywords
|
28 |
-
|
29 |
# Function part
|
30 |
# Function to generate content from an image
|
31 |
def generate_content(image):
|
@@ -36,18 +29,11 @@ def generate_content(image):
|
|
36 |
st.write("**🌟 What's in the picture: 🌟**")
|
37 |
st.write(caption)
|
38 |
|
39 |
-
#
|
40 |
-
keywords = extract_keywords(caption)
|
41 |
-
keywords_str = ", ".join(keywords)
|
42 |
-
|
43 |
-
# Create prompt for story with narrative structure
|
44 |
prompt = (
|
45 |
f"Write a funny, warm children's story for ages 3-10, 50–100 words, "
|
46 |
-
f"in third-person narrative
|
47 |
-
f"
|
48 |
-
f"Feature a named protagonist (a child), a simple problem or goal, and a happy resolution. "
|
49 |
-
f"Mention the exact place, location, or venue from the scene (e.g., park, pool, gym). "
|
50 |
-
f"Keep the tone playful and engaging."
|
51 |
)
|
52 |
|
53 |
# Generate raw story
|
|
|
19 |
|
20 |
captioner, storyer, tts = load_pipelines()
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
# Function part
|
23 |
# Function to generate content from an image
|
24 |
def generate_content(image):
|
|
|
29 |
st.write("**🌟 What's in the picture: 🌟**")
|
30 |
st.write(caption)
|
31 |
|
32 |
+
# Create prompt for story
|
|
|
|
|
|
|
|
|
33 |
prompt = (
|
34 |
f"Write a funny, warm children's story for ages 3-10, 50–100 words, "
|
35 |
+
f"in third-person narrative, that describes this scene exactly: {caption} "
|
36 |
+
f"mention the exact place, location or venue within {caption}"
|
|
|
|
|
|
|
37 |
)
|
38 |
|
39 |
# Generate raw story
|