Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
import streamlit as st
|
3 |
from transformers import pipeline
|
4 |
from gtts import gTTS
|
5 |
-
import
|
6 |
|
7 |
# function part
|
8 |
# img2text
|
@@ -14,22 +14,20 @@ def img2text(url):
|
|
14 |
|
15 |
# text2story
|
16 |
def text2story(text):
|
17 |
-
|
18 |
-
result = story_pipeline(text, max_length=200)
|
19 |
-
story_text = result[0]['generated_text']
|
20 |
return story_text
|
21 |
|
22 |
# text2audio
|
23 |
def text2audio(story_text):
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
return audio_file
|
29 |
|
30 |
# main part
|
31 |
st.set_page_config(page_title="Your Image to Audio Story",
|
32 |
-
page_icon="🦜")
|
33 |
st.header("Turn Your Image to Audio Story")
|
34 |
|
35 |
# Upload image
|
@@ -45,19 +43,19 @@ if uploaded_file is not None:
|
|
45 |
st.image(uploaded_file, caption="Uploaded Image",
|
46 |
use_column_width=True)
|
47 |
|
48 |
-
#
|
49 |
st.text('Processing img2text...')
|
50 |
scenario = img2text(uploaded_file.name)
|
51 |
st.write(scenario)
|
52 |
|
53 |
-
#
|
54 |
st.text('Generating a story...')
|
55 |
story = text2story(scenario)
|
56 |
st.write(story)
|
57 |
|
58 |
-
#
|
59 |
st.text('Generating audio data...')
|
60 |
-
audio_data =
|
61 |
|
62 |
# Play button
|
63 |
if st.button("Play Audio"):
|
|
|
2 |
import streamlit as st
|
3 |
from transformers import pipeline
|
4 |
from gtts import gTTS
|
5 |
+
import os
|
6 |
|
7 |
# function part
|
8 |
# img2text
|
|
|
14 |
|
15 |
# text2story
|
16 |
def text2story(text):
|
17 |
+
story_text = "pipeline("text-generation", model="perplexity-ai/r1-1776", trust_remote_code=True)" # to be completed
|
|
|
|
|
18 |
return story_text
|
19 |
|
20 |
# text2audio
|
21 |
def text2audio(story_text):
|
22 |
+
# Convert text to audio using gTTS
|
23 |
+
tts = gTTS(story_text, lang="en")
|
24 |
+
audio_file = "story_audio.wav"
|
25 |
+
tts.save(audio_file)
|
26 |
return audio_file
|
27 |
|
28 |
# main part
|
29 |
st.set_page_config(page_title="Your Image to Audio Story",
|
30 |
+
page_icon="🦜") # prepare configuration
|
31 |
st.header("Turn Your Image to Audio Story")
|
32 |
|
33 |
# Upload image
|
|
|
43 |
st.image(uploaded_file, caption="Uploaded Image",
|
44 |
use_column_width=True)
|
45 |
|
46 |
+
#Stage 1: Image to Text
|
47 |
st.text('Processing img2text...')
|
48 |
scenario = img2text(uploaded_file.name)
|
49 |
st.write(scenario)
|
50 |
|
51 |
+
#Stage 2: Text to Story
|
52 |
st.text('Generating a story...')
|
53 |
story = text2story(scenario)
|
54 |
st.write(story)
|
55 |
|
56 |
+
#Stage 3: Story to Audio data
|
57 |
st.text('Generating audio data...')
|
58 |
+
audio_data =text2audio(story)
|
59 |
|
60 |
# Play button
|
61 |
if st.button("Play Audio"):
|