Spaces:
Build error
Build error
Leo Liu commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,9 +23,15 @@ def text2audio(story_text):
|
|
| 23 |
|
| 24 |
|
| 25 |
def main():
|
| 26 |
-
st.set_page_config(page_title="
|
| 27 |
-
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
if uploaded_file is not None:
|
| 31 |
print(uploaded_file)
|
|
@@ -36,25 +42,32 @@ def main():
|
|
| 36 |
|
| 37 |
|
| 38 |
#Stage 1: Image to Text
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
| 42 |
|
| 43 |
#Stage 2: Text to Story
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
|
| 48 |
#Stage 3: Story to Audio data
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
| 51 |
|
| 52 |
-
|
| 53 |
-
|
| 54 |
st.audio(audio_data['audio'],
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
if __name__ == "__main__":
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
def main():
|
| 26 |
+
st.set_page_config(page_title="Magic Story Box", page_icon="🧚")
|
| 27 |
+
# 新版标题区
|
| 28 |
+
st.markdown("""
|
| 29 |
+
<div class="header">
|
| 30 |
+
<h1>🪄 Magic Picture Story Box 🎧</h1>
|
| 31 |
+
<h4 style="color:#4ECDC4;">Upload any photo → Get a fairy tale!</h4>
|
| 32 |
+
</div>
|
| 33 |
+
""", unsafe_allow_html=True)
|
| 34 |
+
uploaded_file = st.file_uploader("🌈 Choose your magic picture...", type=["jpg", "png"])
|
| 35 |
|
| 36 |
if uploaded_file is not None:
|
| 37 |
print(uploaded_file)
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
#Stage 1: Image to Text
|
| 45 |
+
with status_container.status("🔮 **Step 1/3**: Decoding picture magic...", expanded=True) as status:
|
| 46 |
+
progress_bar.progress(33)
|
| 47 |
+
scenario = img2text(uploaded_file.name)
|
| 48 |
+
status.update(label="✅ Picture decoded!", state="complete")
|
| 49 |
+
st.write(f"**What I see:** {scenario}")
|
| 50 |
|
| 51 |
#Stage 2: Text to Story
|
| 52 |
+
with status_container.status("📚 **Step 2/3**: Writing your fairy tale...", expanded=True) as status:
|
| 53 |
+
progress_bar.progress(66)
|
| 54 |
+
story = text2story(scenario)
|
| 55 |
+
status.update(label="✅ Story created!", state="complete")
|
| 56 |
+
st.write(f"**Your Story:**\n{story}")
|
| 57 |
|
| 58 |
#Stage 3: Story to Audio data
|
| 59 |
+
with status_container.status("🎵 **Step 3/3**: Adding magic music...", expanded=True) as status:
|
| 60 |
+
progress_bar.progress(100)
|
| 61 |
+
audio_data = text2audio(story)
|
| 62 |
+
status.update(label="✅ All ready!", state="complete")
|
| 63 |
|
| 64 |
+
|
| 65 |
+
# 自动播放(移除按钮)
|
| 66 |
st.audio(audio_data['audio'],
|
| 67 |
+
format="audio/wav",
|
| 68 |
+
start_time=0,
|
| 69 |
+
sample_rate=audio_data['sampling_rate'],
|
| 70 |
+
autoplay=True) # 新增自动播放参数
|
| 71 |
|
| 72 |
|
| 73 |
if __name__ == "__main__":
|