czhaobt commited on
Commit
df4ad39
·
verified ·
1 Parent(s): 1911036

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -14
app.py CHANGED
@@ -57,31 +57,28 @@ st.header("Turn Your Image to Audio Story")
57
  uploaded_file = st.file_uploader("Select an Image...")
58
 
59
  if uploaded_file is not None:
60
- # 保存上传的文件到临时文件
61
- temp_file_path = "temp_image.jpg"
62
- bytes_data = uploaded_file.getvalue()
63
- with open(temp_file_path, "wb") as file:
64
- file.write(bytes_data)
 
65
  st.image(uploaded_file, caption="Uploaded Image",
66
- use_container_width=True)
67
 
68
- # Stage 1: Image to Text
69
  st.text('Processing img2text...')
70
  scenario = img2text(temp_file_path)
71
  if scenario:
72
  st.write(scenario)
73
 
74
- # 删除临时文件
75
- if os.path.exists(temp_file_path):
76
- os.remove(temp_file_path)
77
-
78
- # Stage 2: Text to Story
79
  st.text('Generating a story...')
80
  story = text2story(scenario)
81
  if story:
82
  st.write(story)
83
 
84
- # Stage 3: Story to Audio data
85
  st.text('Generating audio data...')
86
  audio_data = text2audio(story)
87
  if audio_data:
@@ -89,4 +86,7 @@ if uploaded_file is not None:
89
  if st.button("Play Audio"):
90
  st.audio(audio_data,
91
  format="audio/mpeg",
92
- start_time=0)
 
 
 
 
57
  uploaded_file = st.file_uploader("Select an Image...")
58
 
59
  if uploaded_file is not None:
60
+ print(uploaded_file)
61
+ # 使用临时文件处理上传的图像
62
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file:
63
+ temp_file.write(uploaded_file.getvalue())
64
+ temp_file_path = temp_file.name
65
+
66
  st.image(uploaded_file, caption="Uploaded Image",
67
+ use_container_width=True) # 修改为 use_container_width
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:
 
86
  if st.button("Play Audio"):
87
  st.audio(audio_data,
88
  format="audio/mpeg",
89
+ start_time=0)
90
+
91
+ # 删除临时文件
92
+ os.remove(temp_file_path)