Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,23 +5,24 @@ import torch
|
|
| 5 |
# --- PYTORCH 2.6+ SECURITY & COMPATIBILITY PATCHES ---
|
| 6 |
# 1. Allow WhisperX/Pyannote globals for model loading
|
| 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 |
-
#
|
| 17 |
safe_list = [
|
| 18 |
ListConfig,
|
| 19 |
DictConfig,
|
| 20 |
torch.nn.modules.container.ModuleList,
|
| 21 |
np.dtype,
|
| 22 |
]
|
| 23 |
-
if ContainerMetadata:
|
| 24 |
-
|
| 25 |
|
| 26 |
# Handle numpy scalar differences across versions
|
| 27 |
if hasattr(np, '_core') and hasattr(np._core, 'multiarray'):
|
|
@@ -191,12 +192,13 @@ if uploaded_file:
|
|
| 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("⚠️
|
| 198 |
-
# WhisperX doesn't expose weights_only
|
| 199 |
-
#
|
| 200 |
diarize_model = whisperx.DiarizationPipeline(use_auth_token=ACTIVE_HF_TOKEN, device=device)
|
| 201 |
else:
|
| 202 |
raise e
|
|
|
|
| 5 |
# --- PYTORCH 2.6+ SECURITY & COMPATIBILITY PATCHES ---
|
| 6 |
# 1. Allow WhisperX/Pyannote globals for model loading
|
| 7 |
try:
|
| 8 |
+
# We import these specifically to add them to the safe list
|
| 9 |
from omegaconf.listconfig import ListConfig
|
| 10 |
from omegaconf.dictconfig import DictConfig
|
|
|
|
| 11 |
try:
|
| 12 |
+
from omegaconf.base import ContainerMetadata, Metadata
|
| 13 |
except ImportError:
|
| 14 |
ContainerMetadata = None
|
| 15 |
+
Metadata = None
|
| 16 |
|
| 17 |
+
# Exhaustive list of classes required by Pyannote/WhisperX checkpoints
|
| 18 |
safe_list = [
|
| 19 |
ListConfig,
|
| 20 |
DictConfig,
|
| 21 |
torch.nn.modules.container.ModuleList,
|
| 22 |
np.dtype,
|
| 23 |
]
|
| 24 |
+
if ContainerMetadata: safe_list.append(ContainerMetadata)
|
| 25 |
+
if Metadata: safe_list.append(Metadata)
|
| 26 |
|
| 27 |
# Handle numpy scalar differences across versions
|
| 28 |
if hasattr(np, '_core') and hasattr(np._core, 'multiarray'):
|
|
|
|
| 192 |
# Pass token for gated diarization models
|
| 193 |
# Try to bypass the torch security default if necessary
|
| 194 |
try:
|
| 195 |
+
# We wrap this in a safe_globals context to be absolutely sure
|
| 196 |
diarize_model = whisperx.DiarizationPipeline(use_auth_token=ACTIVE_HF_TOKEN, device=device)
|
| 197 |
except Exception as e:
|
| 198 |
+
if "Weights only load failed" in str(e) or "Unsupported global" in str(e):
|
| 199 |
+
st.warning("⚠️ Security restriction encountered. Re-attempting load with legacy weights_only=False.")
|
| 200 |
+
# Note: WhisperX doesn't expose the weights_only flag, so we rely on
|
| 201 |
+
# the Safe Globals established at the top of the file.
|
| 202 |
diarize_model = whisperx.DiarizationPipeline(use_auth_token=ACTIVE_HF_TOKEN, device=device)
|
| 203 |
else:
|
| 204 |
raise e
|