MogensR commited on
Commit
cca0593
·
1 Parent(s): f5cc616

another fix

Browse files
Files changed (1) hide show
  1. ui.py +75 -47
ui.py CHANGED
@@ -5,13 +5,10 @@
5
  - Compatible with pipeline.process()
6
  - Aligned with torch==2.3.1+cu121, MatAnyone v1.0.0, SAM2 commit 3c76f73c1a7e7b4a2e8a0a9a3e5b92f7e6e3f2f5
7
 
8
- Changes (2025-09-16):
9
- - Aligned with updated pipeline.py and models/
10
- - Updated progress callback to pass percentages to pipeline.process
11
- - Added input path validation logging
12
- - Simplified SAM2 arguments to use pipeline defaults
13
- - Added MatAnyone version logging in GPU diagnostics
14
- - Enhanced temporary file cleanup
15
  """
16
 
17
  import io
@@ -176,6 +173,7 @@ def process_video_with_background_stoppable(
176
  ):
177
  import importlib
178
  try:
 
179
  STOP.stop = False
180
  yield gr.update(visible=False), gr.update(visible=True), None, "Starting…"
181
 
@@ -318,56 +316,84 @@ def process_video_with_background_stoppable(
318
  }
319
 
320
  def format_status():
321
- return (gpu_status + f"\n\nPROCESSING: {stage_status['current_stage']}\n\n" +
322
- f"PIPELINE STAGES:\n" +
323
- f"SAM2 Segmentation: {stage_status['sam2_status']}\n" +
324
- f"MatAnyone Matting: {stage_status['matany_status']}\n" +
325
- f"Video Compositing: {stage_status['composite_status']}\n" +
326
- f"Audio Muxing: {stage_status['audio_status']}\n" +
327
- (f"\n{stage_status['frame_progress']}" if stage_status['frame_progress'] else ""))
 
 
 
 
328
 
329
  processing_status = format_status()
330
  yield gr.update(visible=False), gr.update(visible=True), None, processing_status
331
 
332
- # Create progress callback to update UI status with detailed tracking
333
  def progress_callback(pct: float, msg: str):
334
- nonlocal stage_status
335
-
336
- # Update current stage and frame progress
337
- stage_status['current_stage'] = msg
338
 
339
- # Track specific stages
340
- if "SAM2" in msg or "segmentation" in msg.lower():
341
- if "complete" in msg.lower() or "Complete" in msg:
342
- stage_status['sam2_status'] = "Complete"
343
- else:
344
- stage_status['sam2_status'] = "Running..."
345
- elif "MatAnyone" in msg or "matting" in msg.lower():
346
- if "complete" in msg.lower() or "Complete" in msg:
347
- stage_status['matany_status'] = "Complete"
348
- elif "failed" in msg.lower() or "fallback" in msg.lower():
349
- stage_status['matany_status'] = "Failed -> Fallback"
350
- else:
351
- stage_status['matany_status'] = "Running..."
352
- elif "composit" in msg.lower():
353
- if "complete" in msg.lower() or "Complete" in msg:
354
- stage_status['composite_status'] = "Complete"
355
- else:
356
- stage_status['composite_status'] = "Running..."
357
- elif "audio" in msg.lower() or "mux" in msg.lower():
358
- if "complete" in msg.lower() or "Complete" in msg:
359
- stage_status['audio_status'] = "Complete"
360
- else:
361
- stage_status['audio_status'] = "Running..."
362
 
363
- # Extract frame progress
364
- if "/" in msg and any(word in msg.lower() for word in ["frame", "matting", "chunking"]):
365
- stage_status['frame_progress'] = msg
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
366
 
367
- updated_status = format_status()
368
- return gr.update(visible=False), gr.update(visible=True), None, updated_status
 
369
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
370
  try:
 
371
  out_path, diag = pipe.process(
372
  video_path=video_path,
373
  bg_image_path=bg_path,
@@ -456,8 +482,10 @@ def progress_callback(pct: float, msg: str):
456
  return
457
 
458
  if out_path:
 
459
  yield gr.update(visible=True), gr.update(visible=False), out_path, status_msg
460
  else:
 
461
  yield gr.update(visible=True), gr.update(visible=False), None, status_msg
462
 
463
  except Exception as e:
 
5
  - Compatible with pipeline.process()
6
  - Aligned with torch==2.3.1+cu121, MatAnyone v1.0.0, SAM2 commit 3c76f73c1a7e7b4a2e8a0a9a3e5b92f7e6e3f2f5
7
 
8
+ Changes (2025-09-17):
9
+ - Fixed progress callback with comprehensive exception handling
10
+ - Added debug logging around pipeline call to identify hanging issues
11
+ - Enhanced error recovery to prevent silent failures
 
 
 
12
  """
13
 
14
  import io
 
173
  ):
174
  import importlib
175
  try:
176
+ logger.info("=== UI CALLBACK STARTED ===")
177
  STOP.stop = False
178
  yield gr.update(visible=False), gr.update(visible=True), None, "Starting…"
179
 
 
316
  }
317
 
318
  def format_status():
319
+ try:
320
+ return (gpu_status + f"\n\nPROCESSING: {stage_status['current_stage']}\n\n" +
321
+ f"PIPELINE STAGES:\n" +
322
+ f"SAM2 Segmentation: {stage_status['sam2_status']}\n" +
323
+ f"MatAnyone Matting: {stage_status['matany_status']}\n" +
324
+ f"Video Compositing: {stage_status['composite_status']}\n" +
325
+ f"Audio Muxing: {stage_status['audio_status']}\n" +
326
+ (f"\n{stage_status['frame_progress']}" if stage_status['frame_progress'] else ""))
327
+ except Exception as e:
328
+ logger.error(f"Format status error: {e}")
329
+ return f"Processing: {stage_status.get('current_stage', 'Unknown')}"
330
 
331
  processing_status = format_status()
332
  yield gr.update(visible=False), gr.update(visible=True), None, processing_status
333
 
334
+ # Create progress callback with comprehensive exception handling
335
  def progress_callback(pct: float, msg: str):
336
+ try:
337
+ nonlocal stage_status
338
+ logger.debug(f"Progress callback called: {pct:.1%} - {msg}")
 
339
 
340
+ # Update current stage and frame progress
341
+ stage_status['current_stage'] = msg
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
342
 
343
+ # Track specific stages
344
+ if "SAM2" in msg or "segmentation" in msg.lower():
345
+ if "complete" in msg.lower() or "Complete" in msg:
346
+ stage_status['sam2_status'] = "Complete"
347
+ else:
348
+ stage_status['sam2_status'] = "Running..."
349
+ elif "MatAnyone" in msg or "matting" in msg.lower():
350
+ if "complete" in msg.lower() or "Complete" in msg:
351
+ stage_status['matany_status'] = "Complete"
352
+ elif "failed" in msg.lower() or "fallback" in msg.lower():
353
+ stage_status['matany_status'] = "Failed -> Fallback"
354
+ else:
355
+ stage_status['matany_status'] = "Running..."
356
+ elif "composit" in msg.lower():
357
+ if "complete" in msg.lower() or "Complete" in msg:
358
+ stage_status['composite_status'] = "Complete"
359
+ else:
360
+ stage_status['composite_status'] = "Running..."
361
+ elif "audio" in msg.lower() or "mux" in msg.lower():
362
+ if "complete" in msg.lower() or "Complete" in msg:
363
+ stage_status['audio_status'] = "Complete"
364
+ else:
365
+ stage_status['audio_status'] = "Running..."
366
 
367
+ # Extract frame progress
368
+ if "/" in msg and any(word in msg.lower() for word in ["frame", "matting", "chunking"]):
369
+ stage_status['frame_progress'] = msg
370
 
371
+ updated_status = format_status()
372
+ logger.debug(f"Progress callback returning status update")
373
+ return gr.update(visible=False), gr.update(visible=True), None, updated_status
374
+
375
+ except Exception as e:
376
+ logger.error(f"Progress callback error: {e}")
377
+ import traceback
378
+ logger.error(f"Progress callback traceback: {traceback.format_exc()}")
379
+
380
+ # Don't let progress callback errors crash the pipeline
381
+ # Return a simple status update instead
382
+ try:
383
+ simple_status = gpu_status + f"\n\nProcessing: {msg}"
384
+ return gr.update(visible=False), gr.update(visible=True), None, simple_status
385
+ except Exception as e2:
386
+ logger.error(f"Even simple progress update failed: {e2}")
387
+ # If even that fails, return nothing to avoid crashing
388
+ return None, None, None, None
389
+
390
+ # Add extensive debugging around the pipeline call
391
+ logger.info(f"=== ABOUT TO CALL PIPELINE.PROCESS ===")
392
+ logger.info(f"Arguments: video_path={video_path}, bg_path={bg_path}")
393
+ logger.info(f"Pipeline process function exists: {hasattr(pipe, 'process')}")
394
+
395
  try:
396
+ logger.info(f"=== CALLING pipe.process() NOW ===")
397
  out_path, diag = pipe.process(
398
  video_path=video_path,
399
  bg_image_path=bg_path,
 
482
  return
483
 
484
  if out_path:
485
+ logger.info(f"=== UI CALLBACK RETURNING SUCCESS: {out_path} ===")
486
  yield gr.update(visible=True), gr.update(visible=False), out_path, status_msg
487
  else:
488
+ logger.info(f"=== UI CALLBACK RETURNING FAILURE ===")
489
  yield gr.update(visible=True), gr.update(visible=False), None, status_msg
490
 
491
  except Exception as e: