Bondya commited on
Commit
598ecb7
·
verified ·
1 Parent(s): 79766fb

Create app.py

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