Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# app.py
|
| 2 |
import io
|
| 3 |
import wave
|
| 4 |
import streamlit as st
|
|
@@ -88,41 +87,103 @@ def part3_text_to_speech_bytes(text: str, tts_pipe) -> bytes:
|
|
| 88 |
return buffer.read()
|
| 89 |
|
| 90 |
# βββ 3) STREAMLIT UI ββββββββββββββββββββββββββββ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
st.set_page_config(
|
| 92 |
-
page_title="
|
| 93 |
-
page_icon="
|
| 94 |
layout="centered"
|
| 95 |
)
|
| 96 |
-
st.title("πΌοΈ β‘οΈ π β‘οΈ ποΈ Image β Story β Speech")
|
| 97 |
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
-
# Show image
|
| 104 |
-
with st.spinner("
|
| 105 |
-
|
| 106 |
-
|
| 107 |
|
| 108 |
-
#
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
| 113 |
|
| 114 |
-
#
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
| 122 |
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
|
|
|
|
|
|
|
|
| 1 |
import io
|
| 2 |
import wave
|
| 3 |
import streamlit as st
|
|
|
|
| 87 |
return buffer.read()
|
| 88 |
|
| 89 |
# βββ 3) STREAMLIT UI ββββββββββββββββββββββββββββ
|
| 90 |
+
# Custom CSS for kid-friendly styling
|
| 91 |
+
st.markdown("""
|
| 92 |
+
<style>
|
| 93 |
+
.main {
|
| 94 |
+
background-color: #e6f3ff;
|
| 95 |
+
padding: 20px;
|
| 96 |
+
border-radius: 15px;
|
| 97 |
+
}
|
| 98 |
+
.stButton>button {
|
| 99 |
+
background-color: #ffcccb;
|
| 100 |
+
color: #333;
|
| 101 |
+
border-radius: 10px;
|
| 102 |
+
border: 2px solid #ff9999;
|
| 103 |
+
font-size: 18px;
|
| 104 |
+
font-weight: bold;
|
| 105 |
+
padding: 10px 20px;
|
| 106 |
+
transition: all 0.3s;
|
| 107 |
+
}
|
| 108 |
+
.stButton>button:hover {
|
| 109 |
+
background-color: #ff9999;
|
| 110 |
+
color: white;
|
| 111 |
+
transform: scale(1.05);
|
| 112 |
+
}
|
| 113 |
+
.stFileUploader {
|
| 114 |
+
background-color: #fff3cd;
|
| 115 |
+
border: 2px dashed #ffca28;
|
| 116 |
+
border-radius: 10px;
|
| 117 |
+
padding: 10px;
|
| 118 |
+
}
|
| 119 |
+
.stImage {
|
| 120 |
+
border: 3px solid #81c784;
|
| 121 |
+
border-radius: 10px;
|
| 122 |
+
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
| 123 |
+
}
|
| 124 |
+
.section-header {
|
| 125 |
+
background-color: #b3e5fc;
|
| 126 |
+
padding: 10px;
|
| 127 |
+
border-radius: 10px;
|
| 128 |
+
text-align: center;
|
| 129 |
+
font-size: 24px;
|
| 130 |
+
font-weight: bold;
|
| 131 |
+
color: #333;
|
| 132 |
+
margin-bottom: 10px;
|
| 133 |
+
}
|
| 134 |
+
.caption-box, .story-box {
|
| 135 |
+
background-color: #f0f4c3;
|
| 136 |
+
padding: 15px;
|
| 137 |
+
border-radius: 10px;
|
| 138 |
+
border: 2px solid #d4e157;
|
| 139 |
+
margin-bottom: 20px;
|
| 140 |
+
}
|
| 141 |
+
</style>
|
| 142 |
+
""", unsafe_allow_html=True)
|
| 143 |
+
|
| 144 |
st.set_page_config(
|
| 145 |
+
page_title="Picture to Story Magic",
|
| 146 |
+
page_icon="β¨",
|
| 147 |
layout="centered"
|
| 148 |
)
|
|
|
|
| 149 |
|
| 150 |
+
# Main title
|
| 151 |
+
st.markdown("<div class='section-header'>Picture to Story Magic! β¨</div>", unsafe_allow_html=True)
|
| 152 |
+
|
| 153 |
+
# Image upload section
|
| 154 |
+
with st.container():
|
| 155 |
+
st.markdown("<div class='section-header'>1οΈβ£ Pick a Fun Picture! πΌοΈ</div>", unsafe_allow_html=True)
|
| 156 |
+
uploaded = st.file_uploader("Choose a picture to start the magic! π", type=["jpg","jpeg","png"])
|
| 157 |
+
if not uploaded:
|
| 158 |
+
st.info("Upload a picture, and let's make a story! π")
|
| 159 |
+
st.stop()
|
| 160 |
|
| 161 |
+
# Show image
|
| 162 |
+
with st.spinner("Looking at your picture..."):
|
| 163 |
+
pil_img = Image.open(uploaded)
|
| 164 |
+
st.image(pil_img, use_container_width=True)
|
| 165 |
|
| 166 |
+
# Caption section
|
| 167 |
+
with st.container():
|
| 168 |
+
captioner = get_image_captioner()
|
| 169 |
+
with st.spinner("Figuring out what's in your picture..."):
|
| 170 |
+
caption = part1_image_to_text(pil_img, captioner)
|
| 171 |
+
st.markdown(f"<div class='caption-box'><b>What's in the Picture? π§</b><br>{caption}</div>", unsafe_allow_html=True)
|
| 172 |
|
| 173 |
+
# Story and audio section
|
| 174 |
+
with st.container():
|
| 175 |
+
st.markdown("<div class='section-header'>2οΈβ£ Make a Story and Hear It! π΅</div>", unsafe_allow_html=True)
|
| 176 |
+
if st.button("Create My Story! π"):
|
| 177 |
+
# Story
|
| 178 |
+
story_pipe = get_story_pipe()
|
| 179 |
+
with st.spinner("Writing a super cool story..."):
|
| 180 |
+
story = part2_text_to_story(caption, story_pipe)
|
| 181 |
+
st.markdown(f"<div class='story-box'><b>Your Cool Story! π</b><br>{story}</div>", unsafe_allow_html=True)
|
| 182 |
|
| 183 |
+
# TTS
|
| 184 |
+
tts_pipe = get_tts_pipe()
|
| 185 |
+
with st.spinner("Turning your story into sound..."):
|
| 186 |
+
audio_bytes = part3_text_to_speech_bytes(story, tts_pipe)
|
| 187 |
+
st.audio(audio_bytes, format="audio/wav")
|
| 188 |
+
st.success("Yay! Your story is ready! π")
|
| 189 |
+
st.balloons() # Fun animation
|