LinkLinkWu commited on
Commit
985775e
Β·
verified Β·
1 Parent(s): 75cc814

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
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
+ )