Update core/app.py
Browse files- core/app.py +37 -5
core/app.py
CHANGED
|
@@ -69,6 +69,7 @@ def patched_get_type(schema):
|
|
| 69 |
TWO_STAGE_AVAILABLE = False
|
| 70 |
CHROMA_PRESETS = {'standard': {}}
|
| 71 |
|
|
|
|
| 72 |
class VideoProcessor:
|
| 73 |
"""
|
| 74 |
Main video processing orchestrator - coordinates all specialized components
|
|
@@ -127,11 +128,34 @@ def load_models(self, progress_callback: Optional[Callable] = None) -> str:
|
|
| 127 |
if progress_callback:
|
| 128 |
progress_callback(0.0, f"Starting model loading on {self.device_manager.get_optimal_device()}")
|
| 129 |
|
| 130 |
-
#
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
if self.cancel_event.is_set():
|
| 137 |
return "Model loading cancelled"
|
|
@@ -408,14 +432,17 @@ def cleanup_resources(self):
|
|
| 408 |
self.model_loader.cleanup()
|
| 409 |
logger.info("Resources cleaned up")
|
| 410 |
|
|
|
|
| 411 |
# Global processor instance for application
|
| 412 |
processor = VideoProcessor()
|
| 413 |
|
|
|
|
| 414 |
# Backward compatibility functions for existing UI
|
| 415 |
def load_models_with_validation(progress_callback: Optional[Callable] = None) -> str:
|
| 416 |
"""Load models with validation - backward compatibility wrapper"""
|
| 417 |
return processor.load_models(progress_callback)
|
| 418 |
|
|
|
|
| 419 |
def process_video_fixed(
|
| 420 |
video_path: str,
|
| 421 |
background_choice: str,
|
|
@@ -433,17 +460,21 @@ def process_video_fixed(
|
|
| 433 |
preview_mask, preview_greenscreen
|
| 434 |
)
|
| 435 |
|
|
|
|
| 436 |
def get_model_status() -> Dict[str, Any]:
|
| 437 |
"""Get model status - backward compatibility wrapper"""
|
| 438 |
return processor.get_status()
|
| 439 |
|
|
|
|
| 440 |
def get_cache_status() -> Dict[str, Any]:
|
| 441 |
"""Get cache status - backward compatibility wrapper"""
|
| 442 |
return processor.get_status()
|
| 443 |
|
|
|
|
| 444 |
# For backward compatibility
|
| 445 |
PROCESS_CANCELLED = processor.cancel_event
|
| 446 |
|
|
|
|
| 447 |
def main():
|
| 448 |
"""Main application entry point"""
|
| 449 |
try:
|
|
@@ -472,5 +503,6 @@ def main():
|
|
| 472 |
# Cleanup on exit
|
| 473 |
processor.cleanup_resources()
|
| 474 |
|
|
|
|
| 475 |
if __name__ == "__main__":
|
| 476 |
main()
|
|
|
|
| 69 |
TWO_STAGE_AVAILABLE = False
|
| 70 |
CHROMA_PRESETS = {'standard': {}}
|
| 71 |
|
| 72 |
+
|
| 73 |
class VideoProcessor:
|
| 74 |
"""
|
| 75 |
Main video processing orchestrator - coordinates all specialized components
|
|
|
|
| 128 |
if progress_callback:
|
| 129 |
progress_callback(0.0, f"Starting model loading on {self.device_manager.get_optimal_device()}")
|
| 130 |
|
| 131 |
+
# Add detailed debugging for the IndexError
|
| 132 |
+
try:
|
| 133 |
+
# Load models using load_all_models which returns tuple of (LoadedModel, LoadedModel)
|
| 134 |
+
sam2_result, matanyone_result = self.model_loader.load_all_models(
|
| 135 |
+
progress_callback=progress_callback,
|
| 136 |
+
cancel_event=self.cancel_event
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
except IndexError as e:
|
| 140 |
+
import traceback
|
| 141 |
+
logger.error(f"IndexError in load_all_models: {e}")
|
| 142 |
+
logger.error(f"Full traceback:\n{traceback.format_exc()}")
|
| 143 |
+
|
| 144 |
+
# Get more context about where exactly the error happened
|
| 145 |
+
tb = traceback.extract_tb(e.__traceback__)
|
| 146 |
+
for frame in tb:
|
| 147 |
+
logger.error(f" File: {frame.filename}, Line: {frame.lineno}, Function: {frame.name}")
|
| 148 |
+
logger.error(f" Code: {frame.line}")
|
| 149 |
+
|
| 150 |
+
# Re-raise with more context
|
| 151 |
+
raise ModelLoadingError(f"Model loading failed with IndexError at line {tb[-1].lineno}: {e}")
|
| 152 |
+
|
| 153 |
+
except Exception as e:
|
| 154 |
+
import traceback
|
| 155 |
+
logger.error(f"Unexpected error in load_all_models: {e}")
|
| 156 |
+
logger.error(f"Error type: {type(e).__name__}")
|
| 157 |
+
logger.error(f"Full traceback:\n{traceback.format_exc()}")
|
| 158 |
+
raise
|
| 159 |
|
| 160 |
if self.cancel_event.is_set():
|
| 161 |
return "Model loading cancelled"
|
|
|
|
| 432 |
self.model_loader.cleanup()
|
| 433 |
logger.info("Resources cleaned up")
|
| 434 |
|
| 435 |
+
|
| 436 |
# Global processor instance for application
|
| 437 |
processor = VideoProcessor()
|
| 438 |
|
| 439 |
+
|
| 440 |
# Backward compatibility functions for existing UI
|
| 441 |
def load_models_with_validation(progress_callback: Optional[Callable] = None) -> str:
|
| 442 |
"""Load models with validation - backward compatibility wrapper"""
|
| 443 |
return processor.load_models(progress_callback)
|
| 444 |
|
| 445 |
+
|
| 446 |
def process_video_fixed(
|
| 447 |
video_path: str,
|
| 448 |
background_choice: str,
|
|
|
|
| 460 |
preview_mask, preview_greenscreen
|
| 461 |
)
|
| 462 |
|
| 463 |
+
|
| 464 |
def get_model_status() -> Dict[str, Any]:
|
| 465 |
"""Get model status - backward compatibility wrapper"""
|
| 466 |
return processor.get_status()
|
| 467 |
|
| 468 |
+
|
| 469 |
def get_cache_status() -> Dict[str, Any]:
|
| 470 |
"""Get cache status - backward compatibility wrapper"""
|
| 471 |
return processor.get_status()
|
| 472 |
|
| 473 |
+
|
| 474 |
# For backward compatibility
|
| 475 |
PROCESS_CANCELLED = processor.cancel_event
|
| 476 |
|
| 477 |
+
|
| 478 |
def main():
|
| 479 |
"""Main application entry point"""
|
| 480 |
try:
|
|
|
|
| 503 |
# Cleanup on exit
|
| 504 |
processor.cleanup_resources()
|
| 505 |
|
| 506 |
+
|
| 507 |
if __name__ == "__main__":
|
| 508 |
main()
|