Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,6 @@ def img2text(url):
|
|
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']
|
@@ -22,15 +21,11 @@ def text2story(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()
|
29 |
-
# 将音频数据写入字节流
|
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",
|
|
|
14 |
|
15 |
# text2story
|
16 |
def text2story(text):
|
|
|
17 |
story_pipeline = pipeline("text-generation", model="agentica-org/DeepScaleR-1.5B-Preview")
|
18 |
result = story_pipeline(text, max_length=200, num_return_sequences=1)
|
19 |
story_text = result[0]['generated_text']
|
|
|
21 |
|
22 |
# text2audio
|
23 |
def text2audio(story_text):
|
|
|
24 |
tts = gTTS(text=story_text, lang='en')
|
|
|
25 |
audio_file = io.BytesIO()
|
|
|
26 |
tts.write_to_fp(audio_file)
|
|
|
27 |
audio_file.seek(0)
|
28 |
+
return {'audio': audio_file, 'sampling_rate': 16000}
|
29 |
|
30 |
# main part
|
31 |
st.set_page_config(page_title="Your Image to Audio Story",
|