Update app.py
Browse files
app.py
CHANGED
@@ -19,15 +19,7 @@ def load_pipelines():
|
|
19 |
|
20 |
captioner, storyer, tts = load_pipelines()
|
21 |
|
22 |
-
# Function
|
23 |
-
def extract_keywords(caption):
|
24 |
-
# Simple keyword extraction: split words and filter out common stop words
|
25 |
-
stop_words = {'the', 'a', 'an', 'in', 'on', 'at', 'of', 'to', 'is', 'are', 'with', 'and'}
|
26 |
-
words = caption.lower().split()
|
27 |
-
# Keep words longer than 2 characters and not in stop words
|
28 |
-
keywords = [word.strip(".,!?\"'") for word in words if word not in stop_words and len(word) > 2]
|
29 |
-
return keywords
|
30 |
-
|
31 |
# Function to generate content from an image
|
32 |
def generate_content(image):
|
33 |
pil_image = Image.open(image)
|
@@ -37,16 +29,11 @@ def generate_content(image):
|
|
37 |
st.write("**🌟 What's in the picture: 🌟**")
|
38 |
st.write(caption)
|
39 |
|
40 |
-
#
|
41 |
-
keywords = extract_keywords(caption)
|
42 |
-
keywords_str = ", ".join(keywords)
|
43 |
-
|
44 |
-
# Create prompt for story, ensuring keywords are included
|
45 |
prompt = (
|
46 |
f"Write a funny, warm children's story for ages 3-10, 50–100 words, "
|
47 |
-
f"in third-person narrative, that describes this scene exactly: {caption}
|
48 |
-
f"
|
49 |
-
f"Mention the exact place, location, or venue within {caption}, such as a park, pool, or gym."
|
50 |
)
|
51 |
|
52 |
# Generate raw story
|
@@ -84,17 +71,6 @@ def generate_content(image):
|
|
84 |
return caption, story, temp_file_path
|
85 |
|
86 |
# Streamlit UI
|
87 |
-
st.markdown(
|
88 |
-
"""
|
89 |
-
<style>
|
90 |
-
.stApp {
|
91 |
-
background: radial-gradient(circle, #e6f3ff, #e6fff2);
|
92 |
-
}
|
93 |
-
</style>
|
94 |
-
""",
|
95 |
-
unsafe_allow_html=True
|
96 |
-
)
|
97 |
-
|
98 |
st.title("✨ Magic Story Maker ✨")
|
99 |
st.markdown("Upload a picture to make a funny story and hear it too! 📸")
|
100 |
|
|
|
19 |
|
20 |
captioner, storyer, tts = load_pipelines()
|
21 |
|
22 |
+
# Function part
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
# Function to generate content from an image
|
24 |
def generate_content(image):
|
25 |
pil_image = Image.open(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},location example like park,pool,gym"
|
|
|
37 |
)
|
38 |
|
39 |
# Generate raw story
|
|
|
71 |
return caption, story, temp_file_path
|
72 |
|
73 |
# Streamlit UI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
74 |
st.title("✨ Magic Story Maker ✨")
|
75 |
st.markdown("Upload a picture to make a funny story and hear it too! 📸")
|
76 |
|