frankai98 commited on
Commit
388bd64
·
verified ·
1 Parent(s): 18d18eb

Create app.py

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