MogensR commited on
Commit
5ddbef0
Β·
verified Β·
1 Parent(s): c9f07e1

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +41 -44
streamlit_app.py CHANGED
@@ -235,57 +235,54 @@ def main():
235
  with col2:
236
  st.header("2. Background Settings")
237
  bg_type = handle_background_selection()
238
-
239
  st.header("3. Process & Download")
240
- if st.button(
241
- "πŸš€ Process Video",
242
- type="primary",
243
- disabled=not st.session_state.uploaded_video or st.session_state.processing,
244
- use_container_width=True
245
- ):
246
- with st.spinner("Processing video (this may take a few minutes)..."):
 
 
247
  st.session_state.processing = True
248
-
249
- try:
250
- # Prepare background based on type
251
- background = None
252
- if bg_type == "image" and 'bg_image' in st.session_state and st.session_state.bg_image is not None:
253
- background = st.session_state.bg_image
254
- elif bg_type == "color" and 'bg_color' in st.session_state:
255
- background = st.session_state.bg_color
256
-
257
- # Process the video
258
- output_path = process_video(
259
- st.session_state.uploaded_video,
260
- background,
261
- bg_type=bg_type
262
- )
263
-
264
- if output_path and os.path.exists(output_path):
265
- # Store the path to the processed video
266
- st.session_state.processed_video_path = output_path
267
- st.success("βœ… Video processing complete!")
268
- else:
269
- st.error("❌ Failed to process video. Please check the logs for details.")
270
-
271
- except Exception as e:
272
- st.error(f"❌ An error occurred: {str(e)}")
273
- logger.exception("Video processing failed")
274
-
275
- finally:
276
- st.session_state.processing = False
277
-
278
- # Show processed video if available
279
  if 'processed_video_path' in st.session_state and st.session_state.processed_video_path:
280
  st.markdown("### Processed Video")
281
-
282
  try:
283
- # Display the video directly from the file
284
  with open(st.session_state.processed_video_path, 'rb') as f:
285
  video_bytes = f.read()
286
  st.video(video_bytes)
287
-
288
- # Download button
289
  st.download_button(
290
  label="πŸ’Ύ Download Processed Video",
291
  data=video_bytes,
@@ -298,4 +295,4 @@ def main():
298
  logger.error(f"Error displaying video: {str(e)}", exc_info=True)
299
 
300
  if __name__ == "__main__":
301
- main()
 
235
  with col2:
236
  st.header("2. Background Settings")
237
  bg_type = handle_background_selection()
238
+
239
  st.header("3. Process & Download")
240
+ # ------- FORM WRAP START --------
241
+ with st.form("process_form"):
242
+ submitted = st.form_submit_button(
243
+ "πŸš€ Process Video",
244
+ disabled=not st.session_state.uploaded_video or st.session_state.processing
245
+ )
246
+
247
+ process_status = st.empty()
248
+ if submitted and not st.session_state.processing:
249
  st.session_state.processing = True
250
+ with st.spinner("Processing video (this may take a few minutes)..."):
251
+ try:
252
+ # Prepare background based on type
253
+ background = None
254
+ if bg_type == "image" and 'bg_image' in st.session_state and st.session_state.bg_image is not None:
255
+ background = st.session_state.bg_image
256
+ elif bg_type == "color" and 'bg_color' in st.session_state:
257
+ background = st.session_state.bg_color
258
+
259
+ # Process the video
260
+ output_path = process_video(
261
+ st.session_state.uploaded_video,
262
+ background,
263
+ bg_type=bg_type
264
+ )
265
+
266
+ if output_path and os.path.exists(output_path):
267
+ st.session_state.processed_video_path = output_path
268
+ process_status.success("βœ… Video processing complete!")
269
+ else:
270
+ process_status.error("❌ Failed to process video. Please check the logs for details.")
271
+
272
+ except Exception as e:
273
+ process_status.error(f"❌ An error occurred: {str(e)}")
274
+ logger.exception("Video processing failed")
275
+ finally:
276
+ st.session_state.processing = False
277
+ # ------- FORM WRAP END --------
278
+
279
+ # Show processed video if available (outside form, stable)
 
280
  if 'processed_video_path' in st.session_state and st.session_state.processed_video_path:
281
  st.markdown("### Processed Video")
 
282
  try:
 
283
  with open(st.session_state.processed_video_path, 'rb') as f:
284
  video_bytes = f.read()
285
  st.video(video_bytes)
 
 
286
  st.download_button(
287
  label="πŸ’Ύ Download Processed Video",
288
  data=video_bytes,
 
295
  logger.error(f"Error displaying video: {str(e)}", exc_info=True)
296
 
297
  if __name__ == "__main__":
298
+ main()