Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ from gtts import gTTS
|
|
4 |
import io
|
5 |
import os
|
6 |
import langdetect
|
|
|
7 |
|
8 |
# function part
|
9 |
# img2text
|
@@ -64,21 +65,21 @@ if uploaded_file is not None:
|
|
64 |
temp_file_path = temp_file.name
|
65 |
|
66 |
st.image(uploaded_file, caption="Uploaded Image",
|
67 |
-
use_container_width=True)
|
68 |
|
69 |
-
#Stage 1: Image to Text
|
70 |
st.text('Processing img2text...')
|
71 |
scenario = img2text(temp_file_path)
|
72 |
if scenario:
|
73 |
st.write(scenario)
|
74 |
|
75 |
-
#Stage 2: Text to Story
|
76 |
st.text('Generating a story...')
|
77 |
story = text2story(scenario)
|
78 |
if story:
|
79 |
st.write(story)
|
80 |
|
81 |
-
#Stage 3: Story to Audio data
|
82 |
st.text('Generating audio data...')
|
83 |
audio_data = text2audio(story)
|
84 |
if audio_data:
|
@@ -88,6 +89,8 @@ if uploaded_file is not None:
|
|
88 |
format="audio/mpeg",
|
89 |
start_time=0)
|
90 |
|
91 |
-
#
|
92 |
-
|
93 |
-
|
|
|
|
|
|
4 |
import io
|
5 |
import os
|
6 |
import langdetect
|
7 |
+
import tempfile # 添加这一行导入 tempfile 模块
|
8 |
|
9 |
# function part
|
10 |
# img2text
|
|
|
65 |
temp_file_path = temp_file.name
|
66 |
|
67 |
st.image(uploaded_file, caption="Uploaded Image",
|
68 |
+
use_container_width=True)
|
69 |
|
70 |
+
# Stage 1: Image to Text
|
71 |
st.text('Processing img2text...')
|
72 |
scenario = img2text(temp_file_path)
|
73 |
if scenario:
|
74 |
st.write(scenario)
|
75 |
|
76 |
+
# Stage 2: Text to Story
|
77 |
st.text('Generating a story...')
|
78 |
story = text2story(scenario)
|
79 |
if story:
|
80 |
st.write(story)
|
81 |
|
82 |
+
# Stage 3: Story to Audio data
|
83 |
st.text('Generating audio data...')
|
84 |
audio_data = text2audio(story)
|
85 |
if audio_data:
|
|
|
89 |
format="audio/mpeg",
|
90 |
start_time=0)
|
91 |
|
92 |
+
# 删除临时文件并进行异常处理
|
93 |
+
try:
|
94 |
+
os.remove(temp_file_path)
|
95 |
+
except Exception as e:
|
96 |
+
st.error(f"删除临时文件出错: {e}")
|