Update app.py
Browse files
app.py
CHANGED
@@ -28,7 +28,8 @@ def generate_content(image):
|
|
28 |
|
29 |
# Generate a caption based on the image content
|
30 |
caption = captioner(pil_image)[0]["generated_text"]
|
31 |
-
st.write("
|
|
|
32 |
|
33 |
# Create a prompt for generating a children's story
|
34 |
prompt = (
|
@@ -50,7 +51,8 @@ def generate_content(image):
|
|
50 |
# Trim the generated story to a maximum of 100 words
|
51 |
words = raw.split()
|
52 |
story = " ".join(words[:100])
|
53 |
-
st.write("
|
|
|
54 |
|
55 |
# Split the story into chunks of 200 characters for text-to-speech processing
|
56 |
chunks = textwrap.wrap(story, width=200)
|
@@ -66,26 +68,26 @@ def generate_content(image):
|
|
66 |
return caption, story, temp_file_path
|
67 |
|
68 |
# Streamlit UI for the application
|
69 |
-
st.title("
|
70 |
-
st.markdown(""
|
71 |
-
Upload an image below to generate a caption, a funny children's story,
|
72 |
-
and an audio narration based on the image. The story will be tailored
|
73 |
-
for children aged 3-10.
|
74 |
-
""")
|
75 |
|
76 |
# File uploader for image input
|
77 |
-
uploaded_image = st.file_uploader("Choose
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
|
|
|
|
|
|
87 |
caption, story, audio_path = generate_content(uploaded_image)
|
88 |
-
|
89 |
st.audio(audio_path, format="audio/wav")
|
90 |
-
|
91 |
-
|
|
|
|
28 |
|
29 |
# Generate a caption based on the image content
|
30 |
caption = captioner(pil_image)[0]["generated_text"]
|
31 |
+
st.write("**๐ What's in the picture: ๐**")
|
32 |
+
st.write(caption)
|
33 |
|
34 |
# Create a prompt for generating a children's story
|
35 |
prompt = (
|
|
|
51 |
# Trim the generated story to a maximum of 100 words
|
52 |
words = raw.split()
|
53 |
story = " ".join(words[:100])
|
54 |
+
st.write("**๐ Your funny story: ๐**")
|
55 |
+
st.write(story)
|
56 |
|
57 |
# Split the story into chunks of 200 characters for text-to-speech processing
|
58 |
chunks = textwrap.wrap(story, width=200)
|
|
|
68 |
return caption, story, temp_file_path
|
69 |
|
70 |
# Streamlit UI for the application
|
71 |
+
st.title("โจ Magic Story Maker โจ")
|
72 |
+
st.markdown("Upload a picture to make a funny story and hear it too! ๐ธ")
|
|
|
|
|
|
|
|
|
73 |
|
74 |
# File uploader for image input
|
75 |
+
uploaded_image = st.file_uploader("Choose your picture", type=["jpg", "jpeg", "png"], help="Pick a photo to start the magic!")
|
76 |
|
77 |
+
# Placeholder image URL (replace with an actual URL of a child-friendly image)
|
78 |
+
placeholder_url = "https://example.com/placeholder_image.jpg"
|
79 |
+
|
80 |
+
if uploaded_image is None:
|
81 |
+
st.image(placeholder_url, caption="Upload your picture here! ๐ท", use_column_width=True)
|
82 |
+
else:
|
83 |
+
st.image(uploaded_image, caption="Your Picture ๐", use_column_width=True)
|
84 |
+
|
85 |
+
if st.button("โจ Make My Story! โจ", help="Click to create your magic story"):
|
86 |
+
if uploaded_image is not None:
|
87 |
+
with st.spinner("๐ฎ Creating your magical story..."):
|
88 |
caption, story, audio_path = generate_content(uploaded_image)
|
89 |
+
st.success("๐ Your story is ready! ๐")
|
90 |
st.audio(audio_path, format="audio/wav")
|
91 |
+
os.remove(audio_path)
|
92 |
+
else:
|
93 |
+
st.warning("Please upload a picture first! ๐ธ")
|