Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,39 @@
|
|
| 1 |
import os
|
| 2 |
-
import joblib
|
| 3 |
-
import pandas as pd
|
| 4 |
-
import numpy as np
|
| 5 |
-
import torch
|
| 6 |
-
import torchaudio
|
| 7 |
-
import warnings
|
| 8 |
-
import gradio as gr
|
| 9 |
-
|
| 10 |
-
# --- STEP 1: THE ROBUST MONKEY PATCH ---
|
| 11 |
-
# This fixes both the 'use_auth_token' error and the 'custom.py' 404 crash
|
| 12 |
import huggingface_hub
|
|
|
|
|
|
|
|
|
|
| 13 |
orig_download = huggingface_hub.hf_hub_download
|
| 14 |
|
| 15 |
def patched_download(*args, **kwargs):
|
| 16 |
-
#
|
| 17 |
if 'use_auth_token' in kwargs:
|
| 18 |
kwargs['token'] = kwargs.pop('use_auth_token')
|
| 19 |
|
|
|
|
|
|
|
|
|
|
| 20 |
try:
|
| 21 |
return orig_download(*args, **kwargs)
|
| 22 |
except Exception as e:
|
| 23 |
-
#
|
| 24 |
-
#
|
| 25 |
-
fname = kwargs.get('filename') or (args[1] if len(args) > 1 else None)
|
| 26 |
if fname == "custom.py" and ("404" in str(e) or "Not Found" in str(e)):
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
raise e
|
| 29 |
|
| 30 |
huggingface_hub.hf_hub_download = patched_download
|
| 31 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
# Import SpeechBrain AFTER the patch
|
| 33 |
from speechbrain.inference.speaker import EncoderClassifier
|
| 34 |
|
|
|
|
| 1 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import huggingface_hub
|
| 3 |
+
from speechbrain.inference.classifiers import EncoderClassifier
|
| 4 |
+
|
| 5 |
+
# 1. Corrected Monkey Patch for SpeechBrain 1.0.0 + huggingface-hub 0.23+
|
| 6 |
orig_download = huggingface_hub.hf_hub_download
|
| 7 |
|
| 8 |
def patched_download(*args, **kwargs):
|
| 9 |
+
# Fix the 'use_auth_token' vs 'token' renaming issue
|
| 10 |
if 'use_auth_token' in kwargs:
|
| 11 |
kwargs['token'] = kwargs.pop('use_auth_token')
|
| 12 |
|
| 13 |
+
# Get the requested filename
|
| 14 |
+
fname = kwargs.get('filename') or (args[1] if len(args) > 1 else None)
|
| 15 |
+
|
| 16 |
try:
|
| 17 |
return orig_download(*args, **kwargs)
|
| 18 |
except Exception as e:
|
| 19 |
+
# If 'custom.py' is missing (404), return a dummy file path instead of None
|
| 20 |
+
# to prevent the 'NoneType' crash in pathlib.
|
|
|
|
| 21 |
if fname == "custom.py" and ("404" in str(e) or "Not Found" in str(e)):
|
| 22 |
+
dummy_path = os.path.abspath("dummy_custom.py")
|
| 23 |
+
if not os.path.exists(dummy_path):
|
| 24 |
+
with open(dummy_path, "w") as f:
|
| 25 |
+
f.write("# Dummy file for SpeechBrain compatibility\n")
|
| 26 |
+
return dummy_path
|
| 27 |
raise e
|
| 28 |
|
| 29 |
huggingface_hub.hf_hub_download = patched_download
|
| 30 |
|
| 31 |
+
# 2. Load the model
|
| 32 |
+
print("Loading SpeechBrain ECAPA feature extractor...")
|
| 33 |
+
feature_extractor = EncoderClassifier.from_hparams(
|
| 34 |
+
source="speechbrain/spkrec-ecapa-voxceleb",
|
| 35 |
+
savedir="pretrained_models/spkrec-ecapa-voxceleb"
|
| 36 |
+
)
|
| 37 |
# Import SpeechBrain AFTER the patch
|
| 38 |
from speechbrain.inference.speaker import EncoderClassifier
|
| 39 |
|