DWD1211 commited on
Commit
1cc9199
·
verified ·
1 Parent(s): 9df442e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -0
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import streamlit as st
2
  from transformers import pipeline
 
 
3
 
4
  # --- Load models once at the beginning ---
5
  image_to_text_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
@@ -25,6 +27,13 @@ def text2audio(story_text):
25
  speech_data = story_to_audio_model(story_text)
26
  return speech_data
27
 
 
 
 
 
 
 
 
28
  # --- Streamlit App ---
29
  st.set_page_config(page_title="Your Image to Audio Story", page_icon="🦜")
30
  st.header("Turn Your Image to Audio Story")
 
1
  import streamlit as st
2
  from transformers import pipeline
3
+ import soundfile as sf
4
+ import io
5
 
6
  # --- Load models once at the beginning ---
7
  image_to_text_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
 
27
  speech_data = story_to_audio_model(story_text)
28
  return speech_data
29
 
30
+ # play_audio
31
+ def play_audio(audio_data):
32
+ audio_buffer = io.BytesIO()
33
+ sf.write(audio_buffer, audio_data['audio'], audio_data['sampling_rate'], format='WAV')
34
+ audio_buffer.seek(0)
35
+ st.audio(audio_buffer, format='audio/wav')
36
+
37
  # --- Streamlit App ---
38
  st.set_page_config(page_title="Your Image to Audio Story", page_icon="🦜")
39
  st.header("Turn Your Image to Audio Story")