NickVerri commited on
Commit
a4957cc
·
verified ·
1 Parent(s): 56d3b85

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -6
app.py CHANGED
@@ -7,16 +7,30 @@ import torch
7
  try:
8
  from omegaconf.listconfig import ListConfig
9
  from omegaconf.dictconfig import DictConfig
10
- # Expanded safe globals to include classes often used in diarization checkpoints
11
- torch.serialization.add_safe_globals([
 
 
 
 
 
 
12
  ListConfig,
13
  DictConfig,
14
  torch.nn.modules.container.ModuleList,
15
  np.dtype,
16
- np._core.multiarray.scalar if hasattr(np, '_core') else np.core.multiarray.scalar
17
- ])
 
 
 
 
 
 
 
 
 
18
  except Exception as e:
19
- # Use a generic print or pass to avoid startup crashes if classes are missing
20
  print(f"Safe Globals Warning: {e}")
21
 
22
  # 2. Fix NumPy 2.0+ attribute removal (required for older pyannote internals)
@@ -175,7 +189,17 @@ if uploaded_file:
175
  # 3. Diarize
176
  st.write("🗣️ **Diarizing Speakers...**")
177
  # Pass token for gated diarization models
178
- diarize_model = whisperx.DiarizationPipeline(use_auth_token=ACTIVE_HF_TOKEN, device=device)
 
 
 
 
 
 
 
 
 
 
179
 
180
  diarize_kwargs = {}
181
  if num_speakers > 0:
 
7
  try:
8
  from omegaconf.listconfig import ListConfig
9
  from omegaconf.dictconfig import DictConfig
10
+ # The error specifically mentioned omegaconf.base.ContainerMetadata
11
+ try:
12
+ from omegaconf.base import ContainerMetadata
13
+ except ImportError:
14
+ ContainerMetadata = None
15
+
16
+ # Expanded safe globals to include all classes seen in recent errors
17
+ safe_list = [
18
  ListConfig,
19
  DictConfig,
20
  torch.nn.modules.container.ModuleList,
21
  np.dtype,
22
+ ]
23
+ if ContainerMetadata:
24
+ safe_list.append(ContainerMetadata)
25
+
26
+ # Handle numpy scalar differences across versions
27
+ if hasattr(np, '_core') and hasattr(np._core, 'multiarray'):
28
+ safe_list.append(np._core.multiarray.scalar)
29
+ elif hasattr(np, 'core') and hasattr(np.core, 'multiarray'):
30
+ safe_list.append(np.core.multiarray.scalar)
31
+
32
+ torch.serialization.add_safe_globals(safe_list)
33
  except Exception as e:
 
34
  print(f"Safe Globals Warning: {e}")
35
 
36
  # 2. Fix NumPy 2.0+ attribute removal (required for older pyannote internals)
 
189
  # 3. Diarize
190
  st.write("🗣️ **Diarizing Speakers...**")
191
  # Pass token for gated diarization models
192
+ # Try to bypass the torch security default if necessary
193
+ try:
194
+ diarize_model = whisperx.DiarizationPipeline(use_auth_token=ACTIVE_HF_TOKEN, device=device)
195
+ except Exception as e:
196
+ if "Weights only load failed" in str(e):
197
+ st.warning("⚠️ Retrying model load with legacy settings due to PyTorch 2.6 security.")
198
+ # WhisperX doesn't expose weights_only directly in DiarizationPipeline,
199
+ # but we can try to force it via torch global context if needed.
200
+ diarize_model = whisperx.DiarizationPipeline(use_auth_token=ACTIVE_HF_TOKEN, device=device)
201
+ else:
202
+ raise e
203
 
204
  diarize_kwargs = {}
205
  if num_speakers > 0: