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,15 +14,19 @@ def img2text(url):
|
|
14 |
|
15 |
# text2story
|
16 |
def text2story(text):
|
17 |
-
|
|
|
18 |
return story_text
|
19 |
|
20 |
# text2audio
|
21 |
def text2audio(story_text):
|
22 |
-
#
|
23 |
-
tts = gTTS(story_text, lang=
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
26 |
return audio_file
|
27 |
|
28 |
# main part
|
@@ -55,12 +59,10 @@ if uploaded_file is not None:
|
|
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"):
|
62 |
-
st.audio(audio_data
|
63 |
format="audio/wav",
|
64 |
-
start_time=0
|
65 |
-
sample_rate = audio_data['sampling_rate'])
|
66 |
-
st.audio("kids_playing_audio.wav")
|
|
|
2 |
import streamlit as st
|
3 |
from transformers import pipeline
|
4 |
from gtts import gTTS
|
5 |
+
import io
|
6 |
|
7 |
# function part
|
8 |
# img2text
|
|
|
14 |
|
15 |
# text2story
|
16 |
def text2story(text):
|
17 |
+
story_pipeline = pipeline("text-generation", model="perplexity-ai/r1-1776", trust_remote_code=True)
|
18 |
+
story_text = story_pipeline(text, max_length=200)[0]['generated_text']
|
19 |
return story_text
|
20 |
|
21 |
# text2audio
|
22 |
def text2audio(story_text):
|
23 |
+
# 使用 gTTS 将文本转换为音频
|
24 |
+
tts = gTTS(text=story_text, lang='en')
|
25 |
+
# 创建一个内存中的字节流
|
26 |
+
audio_file = io.BytesIO()
|
27 |
+
# 将音频保存到字节流中
|
28 |
+
tts.write_to_fp(audio_file)
|
29 |
+
audio_file.seek(0)
|
30 |
return audio_file
|
31 |
|
32 |
# main part
|
|
|
59 |
|
60 |
#Stage 3: Story to Audio data
|
61 |
st.text('Generating audio data...')
|
62 |
+
audio_data = text2audio(story)
|
63 |
|
64 |
# Play button
|
65 |
if st.button("Play Audio"):
|
66 |
+
st.audio(audio_data,
|
67 |
format="audio/wav",
|
68 |
+
start_time=0)
|
|
|
|