Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -22,31 +22,41 @@ def text2audio(story_text):
|
|
22 |
|
23 |
|
24 |
#main part
|
25 |
-
|
26 |
-
st.set_page_config(page_title="Your Image to Audio Story",
|
27 |
-
|
28 |
-
st.header("Turn Your Image to Audio Story")
|
29 |
-
uploaded_file = st.file_uploader("Select an Image...")
|
30 |
-
|
31 |
-
if uploaded_file is not None:
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
|
24 |
#main part
|
25 |
+
def main():
|
26 |
+
st.set_page_config(page_title="Your Image to Audio Story",
|
27 |
+
page_icon="🦜")
|
28 |
+
st.header("Turn Your Image to Audio Story")
|
29 |
+
uploaded_file = st.file_uploader("Select an Image...")
|
30 |
+
|
31 |
+
if uploaded_file is not None:
|
32 |
+
print(uploaded_file)
|
33 |
+
bytes_data = uploaded_file.getvalue()
|
34 |
+
with open(uploaded_file.name, "wb") as file:
|
35 |
+
file.write(bytes_data)
|
36 |
+
|
37 |
+
st.image(uploaded_file, caption="Uploaded Image",
|
38 |
+
use_column_width=True)
|
39 |
+
|
40 |
+
#Stage 1: Image to Text
|
41 |
+
st.text('Processing img2text...')
|
42 |
+
scenario = img2text(uploaded_file.name)
|
43 |
+
st.write(scenario)
|
44 |
+
|
45 |
+
#Stage 2: Text to Story
|
46 |
+
st.text('Generating a story...')
|
47 |
+
story = text2story(scenario)
|
48 |
+
st.write(story)
|
49 |
+
|
50 |
+
#Stage 3: Story to Audio data
|
51 |
+
st.text('Generating audio data...')
|
52 |
+
audio_data =text2audio(story)
|
53 |
+
|
54 |
+
# Play button
|
55 |
+
if st.button("Play Audio"):
|
56 |
+
st.audio(audio_data['audio'],
|
57 |
+
format="audio/wav",
|
58 |
+
start_time=0,
|
59 |
+
sample_rate = audio_data['sampling_rate'])
|
60 |
+
|
61 |
+
if __name__ == "__main__":
|
62 |
+
main()
|