Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -86,6 +86,13 @@ st.markdown("""
|
|
86 |
margin-bottom: 20px;
|
87 |
}
|
88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
.stButton > button {
|
90 |
background-color: #6adb9d;
|
91 |
color: white;
|
@@ -128,6 +135,18 @@ st.markdown("""
|
|
128 |
display: inline-block;
|
129 |
}
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
.story-text {
|
132 |
font-size: 1.3rem;
|
133 |
line-height: 1.6;
|
@@ -149,37 +168,6 @@ st.markdown("""
|
|
149 |
background: #ffcc66;
|
150 |
}
|
151 |
|
152 |
-
/* Loading animation */
|
153 |
-
.loading {
|
154 |
-
display: flex;
|
155 |
-
justify-content: center;
|
156 |
-
margin: 15px 0;
|
157 |
-
}
|
158 |
-
|
159 |
-
.loading div {
|
160 |
-
width: 20px;
|
161 |
-
height: 20px;
|
162 |
-
background-color: #ff6b6b;
|
163 |
-
border-radius: 50%;
|
164 |
-
margin: 0 5px;
|
165 |
-
animation: bounce 0.8s infinite alternate;
|
166 |
-
}
|
167 |
-
|
168 |
-
.loading div:nth-child(2) {
|
169 |
-
animation-delay: 0.2s;
|
170 |
-
background-color: #ffcc66;
|
171 |
-
}
|
172 |
-
|
173 |
-
.loading div:nth-child(3) {
|
174 |
-
animation-delay: 0.4s;
|
175 |
-
background-color: #7678ed;
|
176 |
-
}
|
177 |
-
|
178 |
-
@keyframes bounce {
|
179 |
-
from { transform: translateY(0); }
|
180 |
-
to { transform: translateY(-15px); }
|
181 |
-
}
|
182 |
-
|
183 |
/* Fun floating animation for welcome screen */
|
184 |
@keyframes float {
|
185 |
0% { transform: translateY(0); }
|
@@ -191,42 +179,6 @@ st.markdown("""
|
|
191 |
animation: float 3s infinite ease-in-out;
|
192 |
}
|
193 |
|
194 |
-
/* Title styling with icons */
|
195 |
-
.app-title {
|
196 |
-
display: flex;
|
197 |
-
align-items: center;
|
198 |
-
justify-content: center;
|
199 |
-
gap: 10px;
|
200 |
-
}
|
201 |
-
|
202 |
-
.app-title img {
|
203 |
-
height: 40px;
|
204 |
-
}
|
205 |
-
|
206 |
-
/* Speech bubble styling */
|
207 |
-
.speech-bubble {
|
208 |
-
position: relative;
|
209 |
-
background: #ffffff;
|
210 |
-
border-radius: 20px;
|
211 |
-
padding: 15px;
|
212 |
-
margin: 20px 0;
|
213 |
-
border: 3px solid #ff9e7d;
|
214 |
-
}
|
215 |
-
|
216 |
-
.speech-bubble:after {
|
217 |
-
content: '';
|
218 |
-
position: absolute;
|
219 |
-
bottom: 0;
|
220 |
-
left: 30px;
|
221 |
-
width: 0;
|
222 |
-
height: 0;
|
223 |
-
border: 15px solid transparent;
|
224 |
-
border-top-color: #ffffff;
|
225 |
-
border-bottom: 0;
|
226 |
-
margin-left: -15px;
|
227 |
-
margin-bottom: -15px;
|
228 |
-
}
|
229 |
-
|
230 |
/* Fun emoji decorations */
|
231 |
.emoji-decoration {
|
232 |
font-size: 2rem;
|
@@ -260,58 +212,35 @@ if uploaded_file is not None:
|
|
260 |
|
261 |
# Stage 1: Image to Text
|
262 |
st.markdown("<div class='step-title'>π Finding the magic in your picture...</div>", unsafe_allow_html=True)
|
263 |
-
|
264 |
-
# Add loading animation
|
265 |
-
st.markdown("""
|
266 |
-
<div class="loading">
|
267 |
-
<div></div>
|
268 |
-
<div></div>
|
269 |
-
<div></div>
|
270 |
-
</div>
|
271 |
-
""", unsafe_allow_html=True)
|
272 |
-
|
273 |
scenario = img2text(uploaded_file.name)
|
274 |
-
|
|
|
275 |
|
276 |
# Stage 2: Text to Story
|
277 |
st.markdown("<div class='step-title'>π Creating a magical story...</div>", unsafe_allow_html=True)
|
278 |
-
|
279 |
-
# Add loading animation
|
280 |
-
st.markdown("""
|
281 |
-
<div class="loading">
|
282 |
-
<div></div>
|
283 |
-
<div></div>
|
284 |
-
<div></div>
|
285 |
-
</div>
|
286 |
-
""", unsafe_allow_html=True)
|
287 |
-
|
288 |
story = text2story(scenario)
|
289 |
-
|
|
|
290 |
|
291 |
# Stage 3: Story to Audio data
|
292 |
st.markdown("<div class='step-title'>π Let's hear the story!</div>", unsafe_allow_html=True)
|
293 |
-
|
294 |
-
# Add loading animation
|
295 |
-
st.markdown("""
|
296 |
-
<div class="loading">
|
297 |
-
<div></div>
|
298 |
-
<div></div>
|
299 |
-
<div></div>
|
300 |
-
</div>
|
301 |
-
""", unsafe_allow_html=True)
|
302 |
-
|
303 |
audio_data = text2audio(story)
|
304 |
|
305 |
-
# Play button
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
|
|
|
|
|
|
|
|
|
|
315 |
|
316 |
# Cleanup: Remove the temporary file
|
317 |
if os.path.exists(uploaded_file.name):
|
|
|
86 |
margin-bottom: 20px;
|
87 |
}
|
88 |
|
89 |
+
/* Align play button to the right */
|
90 |
+
.play-button-container {
|
91 |
+
display: flex;
|
92 |
+
justify-content: flex-end;
|
93 |
+
margin: 15px 0;
|
94 |
+
}
|
95 |
+
|
96 |
.stButton > button {
|
97 |
background-color: #6adb9d;
|
98 |
color: white;
|
|
|
135 |
display: inline-block;
|
136 |
}
|
137 |
|
138 |
+
/* Green response box aligned to the right */
|
139 |
+
.response-box {
|
140 |
+
background: rgba(106, 219, 157, 0.9);
|
141 |
+
padding: 15px;
|
142 |
+
border-radius: 20px;
|
143 |
+
margin: 15px 0;
|
144 |
+
border: 3px solid #489d73;
|
145 |
+
max-width: 85%;
|
146 |
+
margin-left: auto; /* This pushes the box to the right */
|
147 |
+
box-shadow: 3px 3px 10px rgba(0,0,0,0.1);
|
148 |
+
}
|
149 |
+
|
150 |
.story-text {
|
151 |
font-size: 1.3rem;
|
152 |
line-height: 1.6;
|
|
|
168 |
background: #ffcc66;
|
169 |
}
|
170 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
/* Fun floating animation for welcome screen */
|
172 |
@keyframes float {
|
173 |
0% { transform: translateY(0); }
|
|
|
179 |
animation: float 3s infinite ease-in-out;
|
180 |
}
|
181 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
/* Fun emoji decorations */
|
183 |
.emoji-decoration {
|
184 |
font-size: 2rem;
|
|
|
212 |
|
213 |
# Stage 1: Image to Text
|
214 |
st.markdown("<div class='step-title'>π Finding the magic in your picture...</div>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
215 |
scenario = img2text(uploaded_file.name)
|
216 |
+
# Display result in green box aligned to the right
|
217 |
+
st.markdown(f"<div class='response-box'><p class='story-text'>{scenario}</p></div>", unsafe_allow_html=True)
|
218 |
|
219 |
# Stage 2: Text to Story
|
220 |
st.markdown("<div class='step-title'>π Creating a magical story...</div>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
story = text2story(scenario)
|
222 |
+
# Display result in green box aligned to the right
|
223 |
+
st.markdown(f"<div class='response-box'><p class='story-text'>{story}</p></div>", unsafe_allow_html=True)
|
224 |
|
225 |
# Stage 3: Story to Audio data
|
226 |
st.markdown("<div class='step-title'>π Let's hear the story!</div>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
227 |
audio_data = text2audio(story)
|
228 |
|
229 |
+
# Play button container for right alignment
|
230 |
+
st.markdown("<div class='play-button-container'>", unsafe_allow_html=True)
|
231 |
+
# Using columns to align button to the right
|
232 |
+
col1, col2 = st.columns([3, 1])
|
233 |
+
with col2:
|
234 |
+
# Play button with kid-friendly design
|
235 |
+
if st.button("π Play My Story!"):
|
236 |
+
if audio_data:
|
237 |
+
st.audio(audio_data['audio'],
|
238 |
+
format="audio/wav",
|
239 |
+
start_time=0,
|
240 |
+
sample_rate=audio_data['sampling_rate'])
|
241 |
+
else:
|
242 |
+
st.error("Oops! The magical voice got lost!")
|
243 |
+
st.markdown("</div>", unsafe_allow_html=True)
|
244 |
|
245 |
# Cleanup: Remove the temporary file
|
246 |
if os.path.exists(uploaded_file.name):
|