MogensR commited on
Commit
de2187f
·
1 Parent(s): f393f4f

Update core/app.py

Browse files
Files changed (1) hide show
  1. core/app.py +12 -29
core/app.py CHANGED
@@ -80,29 +80,8 @@ def __init__(self):
80
  self.device_manager = DeviceManager()
81
  self.memory_manager = MemoryManager(self.device_manager.get_optimal_device())
82
 
83
- # Initialize ModelLoader - check what parameters it actually accepts
84
- try:
85
- # Try the expected signature first
86
- self.model_loader = ModelLoader(
87
- cache_dir=None, # Will use default cache directory
88
- device=self.device_manager.get_optimal_device() # Pass device string, not manager object
89
- )
90
- logger.info("ModelLoader initialized with cache_dir and device parameters")
91
- except TypeError as e:
92
- logger.warning(f"ModelLoader doesn't accept expected parameters: {e}")
93
- # Try alternative signatures
94
- try:
95
- # Maybe it expects the old signature with DeviceManager and MemoryManager?
96
- self.model_loader = ModelLoader(self.device_manager, self.memory_manager)
97
- logger.info("ModelLoader initialized with DeviceManager and MemoryManager")
98
- except TypeError:
99
- # Fall back to no parameters
100
- try:
101
- self.model_loader = ModelLoader()
102
- logger.info("ModelLoader initialized with no parameters")
103
- except Exception as e2:
104
- logger.error(f"Failed to initialize ModelLoader: {e2}")
105
- raise
106
 
107
  self.audio_processor = AudioProcessor()
108
  self.progress_tracker = None
@@ -148,19 +127,23 @@ def load_models(self, progress_callback: Optional[Callable] = None) -> str:
148
  if progress_callback:
149
  progress_callback(0.0, f"Starting model loading on {self.device_manager.get_optimal_device()}")
150
 
151
- # Load models using the specialized loader
152
- # load_models() returns a boolean indicating success
153
- success = self.model_loader.load_models(force_reload=False)
 
 
154
 
155
  if self.cancel_event.is_set():
156
  return "Model loading cancelled"
157
 
 
 
 
158
  if not success:
159
  return "Model loading failed - check logs for details"
160
 
161
- # Get the actual model instances using the getter methods
162
- sam2_predictor = self.model_loader.get_sam2()
163
- matanyone_model = self.model_loader.get_matanyone()
164
 
165
  # Initialize core processor with correct parameters
166
  self.core_processor = CoreVideoProcessor(
 
80
  self.device_manager = DeviceManager()
81
  self.memory_manager = MemoryManager(self.device_manager.get_optimal_device())
82
 
83
+ # Initialize ModelLoader with DeviceManager and MemoryManager (as per actual implementation)
84
+ self.model_loader = ModelLoader(self.device_manager, self.memory_manager)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
  self.audio_processor = AudioProcessor()
87
  self.progress_tracker = None
 
127
  if progress_callback:
128
  progress_callback(0.0, f"Starting model loading on {self.device_manager.get_optimal_device()}")
129
 
130
+ # Load models using load_all_models which returns tuple of (sam2, matanyone)
131
+ sam2_predictor, matanyone_model = self.model_loader.load_all_models(
132
+ progress_callback=progress_callback,
133
+ cancel_event=self.cancel_event
134
+ )
135
 
136
  if self.cancel_event.is_set():
137
  return "Model loading cancelled"
138
 
139
+ # Check if models loaded successfully
140
+ success = sam2_predictor is not None and matanyone_model is not None
141
+
142
  if not success:
143
  return "Model loading failed - check logs for details"
144
 
145
+ # The models are already stored in model_loader, but also keep local references
146
+ # for backward compatibility
 
147
 
148
  # Initialize core processor with correct parameters
149
  self.core_processor = CoreVideoProcessor(