Dominic0406 commited on
Commit
71ac8b2
1 Parent(s): 9d4a85b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -13
app.py CHANGED
@@ -1,6 +1,11 @@
1
  import streamlit as st
2
  from transformers import pipeline
3
 
 
 
 
 
 
4
  st.set_page_config(page_title="Your Image to Audio Story",
5
  page_icon="🦜")
6
  st.header("Turn Your Image to Audio Story")
@@ -14,29 +19,34 @@ if uploaded_file is not None:
14
  st.image(uploaded_file, caption="Uploaded Image",
15
  use_column_width=True)
16
 
17
- #Stage 1: Image to Text
18
- def img2text(imgname):
19
  pipe = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
20
  scenario = pipe(imgname)
21
- return scenario
22
- st.text('Processing img2text...')
23
- scenario = img2text(uploaded_file.name)
24
- st.write(scenario)
25
 
26
- #Stage 2: Text to Story
27
  def txt2story(txtname):
28
  pipe = pipeline("text-generation", model="openai-community/gpt2")
29
  story = pipe(txtname)
30
- return story
31
- st.text('Generating a story...')
32
- story = txt2story(scenario)
33
- st.write(story)
34
 
35
- #Stage 3: Story to Audio data
36
  def text2audio(textname):
37
  pipe = pipeline("text-to-speech", model="facebook/mms-tts-eng")
38
  audio_data = pipe(textname)
39
- return audio_data
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  st.text('Generating audio data...')
41
  audio_data =text2audio(story)
42
 
 
1
  import streamlit as st
2
  from transformers import pipeline
3
 
4
+
5
+
6
+
7
+
8
+
9
  st.set_page_config(page_title="Your Image to Audio Story",
10
  page_icon="🦜")
11
  st.header("Turn Your Image to Audio Story")
 
19
  st.image(uploaded_file, caption="Uploaded Image",
20
  use_column_width=True)
21
 
22
+ #Define function:
23
+ def img2txt(imgname):
24
  pipe = pipeline("image-to-text", model="nlpconnect/vit-gpt2-image-captioning")
25
  scenario = pipe(imgname)
26
+ return scenario[0]['generated_text']
 
 
 
27
 
 
28
  def txt2story(txtname):
29
  pipe = pipeline("text-generation", model="openai-community/gpt2")
30
  story = pipe(txtname)
31
+ return story[0]["generated_text"]
 
 
 
32
 
 
33
  def text2audio(textname):
34
  pipe = pipeline("text-to-speech", model="facebook/mms-tts-eng")
35
  audio_data = pipe(textname)
36
+ return audio_data
37
+
38
+ #Stage 1: Image to Text
39
+ st.text('Processing img2text...')
40
+ scenario = img2txt(uploaded_file.name)
41
+ st.write(scenario)
42
+
43
+ #Stage 2: Text to Story
44
+
45
+ st.text('Generating a story...')
46
+ story = txt2story(scenario)
47
+ st.write(story)
48
+
49
+ #Stage 3: Story to Audio data
50
  st.text('Generating audio data...')
51
  audio_data =text2audio(story)
52