CR7CAD commited on
Commit
aafcb03
·
verified ·
1 Parent(s): e2fd02f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import part
2
+ import streamlit as st
3
+ from transformers import pipeline
4
+
5
+
6
+ # function part
7
+ # img2text
8
+ def img2text(url):
9
+ image_to_text_model = pipeline("image-to-text", model="Salesforce/blip-image-captioning-base")
10
+ text = image_to_text_model(url)[0]["generated_text"]
11
+ return text # key output
12
+
13
+ # text2story
14
+ def text2story(text):
15
+ story_text = "" # to be completed
16
+ return story_text
17
+
18
+ # text2audio
19
+ def text2audio(story_text):
20
+ audio_data = "" # to be completed
21
+ return audio_data
22
+
23
+
24
+ # main part, also where the project code begins if you want to add/revise sth
25
+ st.set_page_config(page_title="Your Image to Audio Story",
26
+ page_icon="🦜")
27
+ st.header("Turn Your Image to Audio Story")
28
+ uploaded_file = st.file_uploader("Select an Image...")
29
+
30
+
31
+ if uploaded_file is not None: # if user didn't upload an image, this would be skipped, codes below will not be executed, then rerun the codes and if the file(image) is uploaded, the part would be executed
32
+ # some kind of looping, not for or while loop
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
+
38
+ st.image(uploaded_file, caption="Uploaded Image",
39
+ use_column_width=True)
40
+
41
+
42
+ #Stage 1: Image to Text
43
+ st.text('Processing img2text...')
44
+ scenario = img2text(uploaded_file.name)
45
+ st.write(scenario)
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")