Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,8 @@ import streamlit as st
|
|
| 4 |
from transformers import pipeline
|
| 5 |
from PIL import Image
|
| 6 |
import numpy as np
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# βββ 1) MODEL LOADING (cached) ββββββββββββββββ
|
| 9 |
@st.cache_resource
|
|
@@ -104,7 +106,7 @@ st.markdown("""
|
|
| 104 |
}
|
| 105 |
.stButton>button {
|
| 106 |
background-color: #ffcccb;
|
| 107 |
-
color: #000000;
|
| 108 |
border-radius: 10px;
|
| 109 |
border: 2px solid #ff9999;
|
| 110 |
font-size: 18px;
|
|
@@ -198,12 +200,18 @@ with st.container():
|
|
| 198 |
st.markdown("<div class='section-header'>2οΈβ£ What's in the Picture? π§</div>", unsafe_allow_html=True)
|
| 199 |
captioner = get_image_captioner()
|
| 200 |
progress_bar = st.progress(0)
|
|
|
|
|
|
|
|
|
|
| 201 |
with st.spinner("Figuring out what's in your picture..."):
|
|
|
|
|
|
|
| 202 |
for i in range(100):
|
| 203 |
progress_bar.progress(i + 1)
|
| 204 |
-
|
| 205 |
-
|
| 206 |
progress_bar.empty()
|
|
|
|
| 207 |
st.markdown(f"<div class='caption-box'><b>Picture Description:</b><br>{caption}</div>", unsafe_allow_html=True)
|
| 208 |
|
| 209 |
# Story and audio section
|
|
@@ -212,21 +220,33 @@ with st.container():
|
|
| 212 |
# Story
|
| 213 |
story_pipe = get_story_pipe()
|
| 214 |
progress_bar = st.progress(0)
|
|
|
|
|
|
|
|
|
|
| 215 |
with st.spinner("Writing a super cool story..."):
|
|
|
|
|
|
|
| 216 |
for i in range(100):
|
| 217 |
progress_bar.progress(i + 1)
|
| 218 |
-
|
| 219 |
-
|
| 220 |
progress_bar.empty()
|
|
|
|
| 221 |
st.markdown(f"<div class='story-box'><b>Your Cool Story! π</b><br>{story}</div>", unsafe_allow_html=True)
|
| 222 |
|
| 223 |
# TTS
|
| 224 |
tts_pipe = get_tts_pipe()
|
| 225 |
progress_bar = st.progress(0)
|
|
|
|
|
|
|
|
|
|
| 226 |
with st.spinner("Turning your story into sound..."):
|
|
|
|
|
|
|
| 227 |
for i in range(100):
|
| 228 |
progress_bar.progress(i + 1)
|
| 229 |
-
|
| 230 |
-
|
| 231 |
progress_bar.empty()
|
|
|
|
| 232 |
st.audio(audio_bytes, format="audio/wav")
|
|
|
|
| 4 |
from transformers import pipeline
|
| 5 |
from PIL import Image
|
| 6 |
import numpy as np
|
| 7 |
+
import time
|
| 8 |
+
import threading
|
| 9 |
|
| 10 |
# βββ 1) MODEL LOADING (cached) ββββββββββββββββ
|
| 11 |
@st.cache_resource
|
|
|
|
| 106 |
}
|
| 107 |
.stButton>button {
|
| 108 |
background-color: #ffcccb;
|
| 109 |
+
button-color: #000000;
|
| 110 |
border-radius: 10px;
|
| 111 |
border: 2px solid #ff9999;
|
| 112 |
font-size: 18px;
|
|
|
|
| 200 |
st.markdown("<div class='section-header'>2οΈβ£ What's in the Picture? π§</div>", unsafe_allow_html=True)
|
| 201 |
captioner = get_image_captioner()
|
| 202 |
progress_bar = st.progress(0)
|
| 203 |
+
result = [None]
|
| 204 |
+
def run_caption():
|
| 205 |
+
result[0] = part1_image_to_text(pil_img, captioner)
|
| 206 |
with st.spinner("Figuring out what's in your picture..."):
|
| 207 |
+
thread = threading.Thread(target=run_caption)
|
| 208 |
+
thread.start()
|
| 209 |
for i in range(100):
|
| 210 |
progress_bar.progress(i + 1)
|
| 211 |
+
time.sleep(0.05) # Adjust for ~5 seconds total
|
| 212 |
+
thread.join()
|
| 213 |
progress_bar.empty()
|
| 214 |
+
caption = result[0]
|
| 215 |
st.markdown(f"<div class='caption-box'><b>Picture Description:</b><br>{caption}</div>", unsafe_allow_html=True)
|
| 216 |
|
| 217 |
# Story and audio section
|
|
|
|
| 220 |
# Story
|
| 221 |
story_pipe = get_story_pipe()
|
| 222 |
progress_bar = st.progress(0)
|
| 223 |
+
result = [None]
|
| 224 |
+
def run_story():
|
| 225 |
+
result[0] = part2_text_to_story(caption, story_pipe)
|
| 226 |
with st.spinner("Writing a super cool story..."):
|
| 227 |
+
thread = threading.Thread(target=run_story)
|
| 228 |
+
thread.start()
|
| 229 |
for i in range(100):
|
| 230 |
progress_bar.progress(i + 1)
|
| 231 |
+
time.sleep(0.07) # Adjust for ~7 seconds total
|
| 232 |
+
thread.join()
|
| 233 |
progress_bar.empty()
|
| 234 |
+
story = result[0]
|
| 235 |
st.markdown(f"<div class='story-box'><b>Your Cool Story! π</b><br>{story}</div>", unsafe_allow_html=True)
|
| 236 |
|
| 237 |
# TTS
|
| 238 |
tts_pipe = get_tts_pipe()
|
| 239 |
progress_bar = st.progress(0)
|
| 240 |
+
result = [None]
|
| 241 |
+
def run_tts():
|
| 242 |
+
result[0] = part3_text_to_speech_bytes(story, tts_pipe)
|
| 243 |
with st.spinner("Turning your story into sound..."):
|
| 244 |
+
thread = threading.Thread(target=run_tts)
|
| 245 |
+
thread.start()
|
| 246 |
for i in range(100):
|
| 247 |
progress_bar.progress(i + 1)
|
| 248 |
+
time.sleep(0.10) # Adjust for ~10 seconds total
|
| 249 |
+
thread.join()
|
| 250 |
progress_bar.empty()
|
| 251 |
+
audio_bytes = result[0]
|
| 252 |
st.audio(audio_bytes, format="audio/wav")
|