Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,14 @@
|
|
| 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(
|
| 10 |
-
image_to_text_model = pipeline("image-to-text",
|
| 11 |
-
|
|
|
|
| 12 |
return text
|
| 13 |
|
| 14 |
# text2story
|
|
@@ -24,40 +24,39 @@ def text2audio(story_text):
|
|
| 24 |
return audio_data
|
| 25 |
|
| 26 |
|
| 27 |
-
|
| 28 |
-
st.set_page_config(page_title="AI Storytelling for kids", page_icon="🦜")
|
| 29 |
-
st.header("AI Storytelling for kids")
|
| 30 |
-
uploaded_file = st.file_uploader("Select an Image...")
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
file.write(bytes_data)
|
| 37 |
-
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
| 38 |
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
|
| 50 |
-
#Stage 3: Story to Audio data
|
| 51 |
-
st.text('Generating audio data...')
|
| 52 |
-
audio_data =text2audio(story)
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
start_time=0,
|
| 59 |
-
sample_rate = audio_data['sampling_rate'])
|
| 60 |
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# import part
|
| 2 |
import streamlit as st
|
| 3 |
from transformers import pipeline
|
| 4 |
|
| 5 |
+
|
| 6 |
# function part
|
| 7 |
# img2text
|
| 8 |
+
def img2text(img):
|
| 9 |
+
image_to_text_model = pipeline("image-to-text",
|
| 10 |
+
model="Salesforce/blip-image-captioning-base")
|
| 11 |
+
text = image_to_text_model(img)[0]["generated_text"]
|
| 12 |
return text
|
| 13 |
|
| 14 |
# text2story
|
|
|
|
| 24 |
return audio_data
|
| 25 |
|
| 26 |
|
| 27 |
+
# main part
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
st.set_page_config(page_title="Your Image to Audio Story",
|
| 30 |
+
page_icon="🦜")
|
| 31 |
+
st.header("Turn Your Image to Audio Story")
|
| 32 |
+
uploaded_file = st.file_uploader("Select an Image...")
|
|
|
|
|
|
|
| 33 |
|
| 34 |
|
| 35 |
+
if uploaded_file is not None:
|
| 36 |
+
print(uploaded_file)
|
| 37 |
+
st.image(uploaded_file, caption="Uploaded Image",
|
| 38 |
+
use_column_width=True)
|
| 39 |
+
|
| 40 |
|
| 41 |
+
#Stage 1: Image to Text
|
| 42 |
+
st.text('Processing img2text...')
|
| 43 |
+
scenario = img2text(uploaded_file.name)
|
| 44 |
+
st.write(scenario)
|
| 45 |
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
+
#Stage 2: Text to Story
|
| 48 |
+
st.text('Generating a story...')
|
| 49 |
+
story = text2story(scenario)
|
| 50 |
+
st.write(story)
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
#Stage 3: Story to Audio data
|
| 53 |
+
st.text('Generating audio data...')
|
| 54 |
+
audio_data =text2audio(story)
|
| 55 |
|
| 56 |
+
# Play button
|
| 57 |
+
if st.button("Play Audio"):
|
| 58 |
+
st.audio(audio_data['audio'],
|
| 59 |
+
format="audio/wav",
|
| 60 |
+
start_time=0,
|
| 61 |
+
sample_rate = audio_data['sampling_rate'])
|
| 62 |
+
# st.audio("kids_playing_audio.wav")
|