Update app.py
Browse files
app.py
CHANGED
@@ -9,8 +9,8 @@ import tempfile
|
|
9 |
# —––––––– Requirements —–––––––
|
10 |
# streamlit>=1.20
|
11 |
# pillow>=9.0
|
12 |
-
# transformers>=4.30
|
13 |
# torch>=2.0.0
|
|
|
14 |
# sentencepiece>=0.1.97
|
15 |
# gTTS>=2.3.1
|
16 |
|
@@ -48,9 +48,8 @@ captioner, storyteller = load_pipelines()
|
|
48 |
# —––––––– Main App —–––––––
|
49 |
uploaded = st.file_uploader("Upload an image:", type=["jpg", "png", "jpeg"])
|
50 |
if uploaded:
|
51 |
-
#
|
52 |
img = Image.open(uploaded).convert("RGB")
|
53 |
-
img.thumbnail((2048, 2048), Image.ANTIALIAS)
|
54 |
st.image(img, use_container_width=True)
|
55 |
|
56 |
# Generate caption
|
@@ -62,7 +61,7 @@ if uploaded:
|
|
62 |
st.stop()
|
63 |
st.success(f"**Caption:** {caption}")
|
64 |
|
65 |
-
#
|
66 |
prompt = (
|
67 |
f"Image description: {caption}\n"
|
68 |
"Write a coherent, 50-100 word children’s story that flows naturally."
|
@@ -79,6 +78,7 @@ if uploaded:
|
|
79 |
if len(words) > 100:
|
80 |
story = " ".join(words[:100]) + ("" if story.endswith('.') else ".")
|
81 |
|
|
|
82 |
st.subheader("📚 Your Magical Story")
|
83 |
st.write(story)
|
84 |
|
@@ -95,3 +95,4 @@ if uploaded:
|
|
95 |
# Footer
|
96 |
st.markdown("---\n*Made with ❤️ by your friendly story wizard*")
|
97 |
|
|
|
|
9 |
# —––––––– Requirements —–––––––
|
10 |
# streamlit>=1.20
|
11 |
# pillow>=9.0
|
|
|
12 |
# torch>=2.0.0
|
13 |
+
# transformers>=4.30
|
14 |
# sentencepiece>=0.1.97
|
15 |
# gTTS>=2.3.1
|
16 |
|
|
|
48 |
# —––––––– Main App —–––––––
|
49 |
uploaded = st.file_uploader("Upload an image:", type=["jpg", "png", "jpeg"])
|
50 |
if uploaded:
|
51 |
+
# Load and display the image
|
52 |
img = Image.open(uploaded).convert("RGB")
|
|
|
53 |
st.image(img, use_container_width=True)
|
54 |
|
55 |
# Generate caption
|
|
|
61 |
st.stop()
|
62 |
st.success(f"**Caption:** {caption}")
|
63 |
|
64 |
+
# Build prompt and generate story
|
65 |
prompt = (
|
66 |
f"Image description: {caption}\n"
|
67 |
"Write a coherent, 50-100 word children’s story that flows naturally."
|
|
|
78 |
if len(words) > 100:
|
79 |
story = " ".join(words[:100]) + ("" if story.endswith('.') else ".")
|
80 |
|
81 |
+
# Display story
|
82 |
st.subheader("📚 Your Magical Story")
|
83 |
st.write(story)
|
84 |
|
|
|
95 |
# Footer
|
96 |
st.markdown("---\n*Made with ❤️ by your friendly story wizard*")
|
97 |
|
98 |
+
|