WRX020510 commited on
Commit
82363f6
·
verified ·
1 Parent(s): 8f5e377

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #Import part
2
+ from transformers import pipeline
3
+ import streamlit as st
4
+
5
+ # Use function for the implementation
6
+
7
+ # function part
8
+ # img2text
9
+ def img2text(img):
10
+ image_to_text_model = pipeline("image-to-text",
11
+ model="Salesforce/blip-image-captioning-base")
12
+ text = image_to_text_model(img)[0]["generated_text"]
13
+ return text
14
+
15
+ # text2story
16
+ def text2story(text):
17
+ story_text = "" # to be completed
18
+ return story_text
19
+
20
+ # text2audio
21
+ def text2audio(story_text):
22
+ audio_data = "" # to be completed
23
+ return audio_data
24
+
25
+ # program main part
26
+
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
+
32
+ if uploaded_file is not None:
33
+ print(uploaded_file)
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
+ 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
+ #Stage 2: Text to Story
47
+ st.text('Generating a story...')
48
+ #story = text2story(scenario)
49
+ #st.write(story)
50
+
51
+ #Stage 3: Story to Audio data
52
+ #st.text('Generating audio data...')
53
+ #audio_data =text2audio(story)
54
+
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")
63
+