Leo Liu commited on
Commit
6adb3a5
·
verified ·
1 Parent(s): 76b5990

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -16
app.py CHANGED
@@ -23,9 +23,15 @@ def text2audio(story_text):
23
 
24
 
25
  def main():
26
- st.set_page_config(page_title="Your Image to Audio Story", page_icon="🦜")
27
- st.header("Turn Your Image to Audio Story")
28
- uploaded_file = st.file_uploader("Select an Image...")
 
 
 
 
 
 
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
- st.text('🔍 Analyzing image...')
40
- scenario = img2text(uploaded_file.name)
41
- st.write(scenario)
 
 
42
 
43
  #Stage 2: Text to Story
44
- st.text('📖 Generating story...')
45
- story = text2story(scenario)
46
- st.write(story)
 
 
47
 
48
  #Stage 3: Story to Audio data
49
- st.text('🎧 Converting to audio...')
50
- audio_data =text2audio(story)
 
 
51
 
52
- # Play button
53
- if st.button("Play Audio Story"):
54
  st.audio(audio_data['audio'],
55
- format="audio/wav",
56
- start_time=0,
57
- sample_rate = audio_data['sampling_rate'])
 
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__":