Paul Ke commited on
Commit
35cfe03
Β·
verified Β·
1 Parent(s): e16b690

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +14 -40
streamlit_app.py CHANGED
@@ -164,46 +164,15 @@ if st.session_state["videos"]:
164
  except Exception as e:
165
  st.write("Couldn't show video")
166
 
167
- try:
168
- video_file = open(st.session_state["videos"], "rb")
169
- st.download_button(
170
- "**Download Video πŸ“**",
171
- data=video_file,
172
- file_name=f"{st.session_state['videos'].lower().translate(str.maketrans('', '', string.punctuation)).replace(' ', '_')}.mp4",
173
- mime="video/mp4",
174
- type="primary",
175
- )
176
- except Exception as e:
177
- st.error("Failed downloading the video", icon="πŸ˜”")
178
-
179
- # URL input for video
180
- video_url = video_path
181
-
182
  # Analysis prompt
183
  analysis_prompt = st.sidebar.text_area("Enter analysis")
184
 
185
  if st.button('Generate the story'):
186
- if not video_url:
187
- st.sidebar.warning('PLEASE ENTER A VALID URL')
188
- else:
189
- # Download the video
190
- with st.spinner("Retrieving video..."):
191
- temp_video_path = os.path.join(tempfile.gettempdir(), 'video.mp4')
192
- success, message = download_video(video_url, temp_video_path)
193
-
194
- if not success:
195
- st.sidebar.error(f"Error downloading video: {message}")
196
- else:
197
- st.sidebar.success(message)
198
-
199
- # Display the video
200
- st.sidebar.divider()
201
- st.sidebar.video(temp_video_path, format="video/mp4", start_time=0, loop=True, autoplay=True)
202
-
203
  try:
204
  with st.spinner("Generating the story of the video"):
205
  # Upload and process the video
206
- processed_video = upload_file(temp_video_path)
207
  while processed_video.state.name == "PROCESSING":
208
  time.sleep(1)
209
  processed_video = get_file(processed_video.name)
@@ -216,10 +185,15 @@ if st.button('Generate the story'):
216
 
217
  except Exception as error:
218
  st.sidebar.error(f"An error occurred: {error}")
219
- finally:
220
- # Delete the downloaded video
221
- try:
222
- os.remove(temp_video_path)
223
- # st.sidebar.info("Downloaded video deleted.")
224
- except Exception as e:
225
- st.sidebar.warning(f"Failed to delete video: {e}")
 
 
 
 
 
 
164
  except Exception as e:
165
  st.write("Couldn't show video")
166
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
167
  # Analysis prompt
168
  analysis_prompt = st.sidebar.text_area("Enter analysis")
169
 
170
  if st.button('Generate the story'):
171
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  try:
173
  with st.spinner("Generating the story of the video"):
174
  # Upload and process the video
175
+ processed_video = upload_file(st.session_state["videos"], "rb")
176
  while processed_video.state.name == "PROCESSING":
177
  time.sleep(1)
178
  processed_video = get_file(processed_video.name)
 
185
 
186
  except Exception as error:
187
  st.sidebar.error(f"An error occurred: {error}")
188
+
189
+ try:
190
+ video_file = open(st.session_state["videos"], "rb")
191
+ st.download_button(
192
+ "**Download Video πŸ“**",
193
+ data=video_file,
194
+ file_name=f"{st.session_state['videos'].lower().translate(str.maketrans('', '', string.punctuation)).replace(' ', '_')}.mp4",
195
+ mime="video/mp4",
196
+ type="primary",
197
+ )
198
+ except Exception as e:
199
+ st.error("Failed downloading the video", icon="πŸ˜”")