Update app.py
Browse files
app.py
CHANGED
@@ -7,9 +7,6 @@ import torch
|
|
7 |
st.set_page_config(page_title="Image to Audio Story", page_icon="🦜")
|
8 |
|
9 |
def extract_image_caption(image_data):
|
10 |
-
"""
|
11 |
-
利用预训练模型从图像中提取描述性文字。
|
12 |
-
"""
|
13 |
img_obj = Image.open(image_data)
|
14 |
caption_pipeline = pipeline(
|
15 |
"image-to-text",
|
@@ -20,9 +17,6 @@ caption_text = caption_results[0]['generated_text']
|
|
20 |
return caption_text
|
21 |
|
22 |
def compose_story_from_caption(caption_detail):
|
23 |
-
"""
|
24 |
-
根据图像描述创作一篇充满创意的儿童故事。
|
25 |
-
"""
|
26 |
story_pipeline = pipeline(
|
27 |
"text-generation",
|
28 |
model="Qwen/Qwen2-1.5B",
|
@@ -43,9 +37,6 @@ story = story_text.strip()
|
|
43 |
return story
|
44 |
|
45 |
def convert_text_to_audio(text_content, audio_path="output.mp3"):
|
46 |
-
"""
|
47 |
-
将文本转换为音频文件。
|
48 |
-
"""
|
49 |
tts_engine = gTTS(text=text_content, lang="en")
|
50 |
tts_engine.save(audio_path)
|
51 |
return audio_path
|
|
|
7 |
st.set_page_config(page_title="Image to Audio Story", page_icon="🦜")
|
8 |
|
9 |
def extract_image_caption(image_data):
|
|
|
|
|
|
|
10 |
img_obj = Image.open(image_data)
|
11 |
caption_pipeline = pipeline(
|
12 |
"image-to-text",
|
|
|
17 |
return caption_text
|
18 |
|
19 |
def compose_story_from_caption(caption_detail):
|
|
|
|
|
|
|
20 |
story_pipeline = pipeline(
|
21 |
"text-generation",
|
22 |
model="Qwen/Qwen2-1.5B",
|
|
|
37 |
return story
|
38 |
|
39 |
def convert_text_to_audio(text_content, audio_path="output.mp3"):
|
|
|
|
|
|
|
40 |
tts_engine = gTTS(text=text_content, lang="en")
|
41 |
tts_engine.save(audio_path)
|
42 |
return audio_path
|