Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,15 +14,15 @@ def img2text(url):
|
|
14 |
|
15 |
# text2story
|
16 |
def text2story(text):
|
17 |
-
|
18 |
-
|
19 |
result = story_pipeline(text, max_length=200, num_return_sequences=1)
|
20 |
story_text = result[0]['generated_text']
|
21 |
return story_text
|
22 |
|
23 |
# text2audio
|
24 |
def text2audio(story_text):
|
25 |
-
# 使用 gTTS
|
26 |
tts = gTTS(text=story_text, lang='en')
|
27 |
# 创建一个内存中的字节流对象,用于存储音频数据
|
28 |
audio_file = io.BytesIO()
|
@@ -30,7 +30,7 @@ def text2audio(story_text):
|
|
30 |
tts.write_to_fp(audio_file)
|
31 |
# 将文件指针移动到文件开头,以便后续读取
|
32 |
audio_file.seek(0)
|
33 |
-
return audio_file
|
34 |
|
35 |
# main part
|
36 |
st.set_page_config(page_title="Your Image to Audio Story",
|
@@ -63,4 +63,7 @@ if uploaded_file is not None:
|
|
63 |
|
64 |
# Play button
|
65 |
if st.button("Play Audio"):
|
66 |
-
st.audio(audio_data,
|
|
|
|
|
|
|
|
14 |
|
15 |
# text2story
|
16 |
def text2story(text):
|
17 |
+
# 使用 Hugging Face 的 text-generation 模型生成故事
|
18 |
+
story_pipeline = pipeline("text-generation", model="agentica-org/DeepScaleR-1.5B-Preview")
|
19 |
result = story_pipeline(text, max_length=200, num_return_sequences=1)
|
20 |
story_text = result[0]['generated_text']
|
21 |
return story_text
|
22 |
|
23 |
# text2audio
|
24 |
def text2audio(story_text):
|
25 |
+
# 使用 gTTS 将文本转换为音频
|
26 |
tts = gTTS(text=story_text, lang='en')
|
27 |
# 创建一个内存中的字节流对象,用于存储音频数据
|
28 |
audio_file = io.BytesIO()
|
|
|
30 |
tts.write_to_fp(audio_file)
|
31 |
# 将文件指针移动到文件开头,以便后续读取
|
32 |
audio_file.seek(0)
|
33 |
+
return {'audio': audio_file, 'sampling_rate': 16000} # 返回音频数据和采样率
|
34 |
|
35 |
# main part
|
36 |
st.set_page_config(page_title="Your Image to Audio Story",
|
|
|
63 |
|
64 |
# Play button
|
65 |
if st.button("Play Audio"):
|
66 |
+
st.audio(audio_data['audio'],
|
67 |
+
format="audio/wav",
|
68 |
+
start_time=0,
|
69 |
+
sample_rate=audio_data['sampling_rate'])
|