shingguy1 commited on
Commit
3520514
Β·
verified Β·
1 Parent(s): 19b4c5e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -31
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="Image→Story→Speech",
93
- page_icon="πŸ–ΌοΈπŸŽ€",
94
  layout="centered"
95
  )
96
- st.title("πŸ–ΌοΈ ➑️ πŸ“– ➑️ πŸŽ™οΈ Image β†’ Story β†’ Speech")
97
 
98
- uploaded = st.file_uploader("1️⃣ Upload an image", type=["jpg","jpeg","png"])
99
- if not uploaded:
100
- st.info("Please upload an image to begin.")
101
- st.stop()
 
 
 
 
 
 
102
 
103
- # Show image
104
- with st.spinner("Rendering image..."):
105
- pil_img = Image.open(uploaded)
106
- st.image(pil_img, use_container_width=True)
107
 
108
- # Generate caption
109
- captioner = get_image_captioner()
110
- with st.spinner("Generating caption..."):
111
- caption = part1_image_to_text(pil_img, captioner)
112
- st.markdown(f"**Caption:** {caption}")
 
113
 
114
- # Generate story & play audio
115
- if st.button("πŸ“ Generate Story & Play Audio"):
116
- # Story
117
- story_pipe = get_story_pipe()
118
- with st.spinner("Generating story..."):
119
- story = part2_text_to_story(caption, story_pipe)
120
- st.markdown("**Story:**")
121
- st.write(story)
 
122
 
123
- # TTS
124
- tts_pipe = get_tts_pipe()
125
- with st.spinner("Synthesizing speech..."):
126
- audio_bytes = part3_text_to_speech_bytes(story, tts_pipe)
127
- st.audio(audio_bytes, format="audio/wav")
128
- st.success("All done!")
 
 
 
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