Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,31 @@
|
|
1 |
# Program title: Storytelling App
|
2 |
|
3 |
-
#
|
4 |
-
from transformers import pipeline
|
5 |
import streamlit as st
|
|
|
6 |
|
7 |
# function part
|
8 |
-
# img2text
|
9 |
def img2text(url):
|
10 |
image_to_text_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
11 |
text = image_to_text_model(url)[0]["generated_text"]
|
12 |
return text
|
13 |
|
14 |
-
# text2story
|
15 |
def text2story(text):
|
16 |
-
|
17 |
-
story_text =
|
18 |
return story_text
|
19 |
|
20 |
-
# text2audio
|
21 |
def text2audio(story_text):
|
22 |
-
|
23 |
-
|
24 |
-
return
|
|
|
25 |
|
26 |
def main():
|
27 |
-
st.set_page_config(page_title="Your Image to Audio Story",
|
28 |
-
page_icon="🦜")
|
29 |
st.header("Turn Your Image to Audio Story")
|
30 |
uploaded_file = st.file_uploader("Select an Image...")
|
31 |
|
@@ -34,8 +34,8 @@ def main():
|
|
34 |
bytes_data = uploaded_file.getvalue()
|
35 |
with open(uploaded_file.name, "wb") as file:
|
36 |
file.write(bytes_data)
|
37 |
-
st.image(uploaded_file, caption="Uploaded Image",
|
38 |
-
|
39 |
|
40 |
#Stage 1: Image to Text
|
41 |
st.text('Processing img2text...')
|
@@ -53,10 +53,11 @@ def main():
|
|
53 |
|
54 |
# Play button
|
55 |
if st.button("Play Audio"):
|
56 |
-
st.audio(audio_data['audio'],
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
60 |
|
61 |
if __name__ == "__main__":
|
62 |
main()
|
|
|
1 |
# Program title: Storytelling App
|
2 |
|
3 |
+
# import part
|
|
|
4 |
import streamlit as st
|
5 |
+
from transformers import pipeline
|
6 |
|
7 |
# function part
|
8 |
+
# img2text
|
9 |
def img2text(url):
|
10 |
image_to_text_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
|
11 |
text = image_to_text_model(url)[0]["generated_text"]
|
12 |
return text
|
13 |
|
14 |
+
# text2story
|
15 |
def text2story(text):
|
16 |
+
pipe = pipeline("text-generation", model="pranavpsv/genre-story-generator-v2")
|
17 |
+
story_text = pipe(text)[0]['generated_text']
|
18 |
return story_text
|
19 |
|
20 |
+
# text2audio
|
21 |
def text2audio(story_text):
|
22 |
+
pipe = pipeline("text-to-audio", model="Matthijs/mms-tts-eng")
|
23 |
+
audio_data = pipe(story_text)
|
24 |
+
return audio_data
|
25 |
+
|
26 |
|
27 |
def main():
|
28 |
+
st.set_page_config(page_title="Your Image to Audio Story", page_icon="🦜")
|
|
|
29 |
st.header("Turn Your Image to Audio Story")
|
30 |
uploaded_file = st.file_uploader("Select an Image...")
|
31 |
|
|
|
34 |
bytes_data = uploaded_file.getvalue()
|
35 |
with open(uploaded_file.name, "wb") as file:
|
36 |
file.write(bytes_data)
|
37 |
+
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
38 |
+
|
39 |
|
40 |
#Stage 1: Image to Text
|
41 |
st.text('Processing img2text...')
|
|
|
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 |
|
62 |
if __name__ == "__main__":
|
63 |
main()
|