Eason918 commited on
Commit
21b9d7f
·
verified ·
1 Parent(s): 1653bd5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -0
app.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #import part
2
+ import streamlit as st
3
+ from transformers import pipeline
4
+
5
+ # function part
6
+ # img2text
7
+ def img2text(url):
8
+ image_to_text_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
9
+ text = image_to_text_model(url)[0]["generated_text"]
10
+ return text
11
+
12
+ # text2story
13
+ def text2story(text):
14
+ story_text = "" # to be completed
15
+ return story_text
16
+
17
+ # text2audio
18
+ def text2audio(story_text):
19
+ audio_data = "" # to be completed
20
+ return audio_data
21
+ #main part
22
+ st.set_page_config(page_title="Your Image to Audio Story",
23
+ page_icon="🦜")
24
+ st.header("Turn Your Image to Audio Story")
25
+ uploaded_file = st.file_uploader("Select an Image...")
26
+
27
+ if uploaded_file is not None:
28
+ print(uploaded_file)
29
+ bytes_data = uploaded_file.getvalue()
30
+ with open(uploaded_file.name, "wb") as file:
31
+ file.write(bytes_data)
32
+ st.image(uploaded_file, caption="Uploaded Image",
33
+ use_column_width=True)
34
+ #Stage 1: Image to Text
35
+ st.text('Processing img2text...')
36
+ scenario = img2text(uploaded_file.name)
37
+ st.write(scenario)
38
+
39
+
40
+ #Stage 2: Text to Story
41
+ st.text('Generating a story...')
42
+ #story = text2story(scenario)
43
+ #st.write(story)
44
+
45
+
46
+ # Play button
47
+ if st.button("Play Audio"):
48
+ #st.audio(audio_data['audio'],
49
+ # format="audio/wav",
50
+ # start_time=0,
51
+ # sample_rate = audio_data['sampling_rate'])
52
+ st.audio("kids_playing_audio.wav")