Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py ββ Streamlit front-end for 3-10-year-olds π¦ππ΅
|
2 |
+
# Drop this file into your Hugging Face Space root.
|
3 |
+
import streamlit as st
|
4 |
+
from func import img2text, text2story, story2audio # β our back-end utilities
|
5 |
+
|
6 |
+
st.set_page_config(
|
7 |
+
page_title="Magic Story Maker",
|
8 |
+
page_icon="π§Έ",
|
9 |
+
layout="centered"
|
10 |
+
)
|
11 |
+
|
12 |
+
# π------------- UI HEADER -------------π
|
13 |
+
st.markdown(
|
14 |
+
"""
|
15 |
+
<h1 style='text-align:center; color:#ff914d;'>πΌοΈ β π β π</h1>
|
16 |
+
<h2 style='text-align:center; color:#ffcc00;'>Turn your picture into a talking story!</h2>
|
17 |
+
""",
|
18 |
+
unsafe_allow_html=True
|
19 |
+
)
|
20 |
+
|
21 |
+
uploaded = st.file_uploader(
|
22 |
+
"π **Choose a colourful picture (JPG / PNG)**",
|
23 |
+
type=["jpg", "jpeg", "png"],
|
24 |
+
accept_multiple_files=False
|
25 |
+
)
|
26 |
+
|
27 |
+
if uploaded:
|
28 |
+
st.image(uploaded, caption="Nice choice!", use_column_width=True)
|
29 |
+
|
30 |
+
with st.spinner("π Looking at your picture..."):
|
31 |
+
caption = img2text(uploaded) # β picture β caption
|
32 |
+
st.success("Here's what I see:")
|
33 |
+
st.markdown(f"> **_{caption}_**")
|
34 |
+
|
35 |
+
with st.spinner("πͺ Writing a fun story..."):
|
36 |
+
story = text2story(caption) # β‘ caption β story
|
37 |
+
st.success("Story ready! Read along below:")
|
38 |
+
st.markdown(
|
39 |
+
f"<div style='background:#fff7e6; padding:1rem; "
|
40 |
+
f"border-radius:10px; font-size:20px;'>{story}</div>",
|
41 |
+
unsafe_allow_html=True
|
42 |
+
)
|
43 |
+
|
44 |
+
with st.spinner("π€ Recording the story..."):
|
45 |
+
wav_path = story2audio(story) # β’ story β audio
|
46 |
+
st.audio(wav_path, format="audio/wav")
|
47 |
+
st.balloons()
|
48 |
+
|
49 |
+
else:
|
50 |
+
st.markdown(
|
51 |
+
"<p style='text-align:center; font-size:18px;'>"
|
52 |
+
"Upload a picture and let's make some magic!</p>",
|
53 |
+
unsafe_allow_html=True
|
54 |
+
)
|