Fixed cache default value, moved ValuError t othe right place, added to docstring.

This commit is contained in:
Marko Henning
2024-04-23 16:29:48 +02:00
parent 7d8da3b81c
commit 55a77b861c
+9 -9
View File
@@ -187,7 +187,7 @@ class Diariser:
def load_model(cls,
model: str = PYANNOTE_DEFAULT_CONFIG,
use_auth_token: str = None,
cache_token: bool = True,
cache_token: bool = False,
cache_dir: Union[Path, str] = PYANNOTE_DEFAULT_PATH,
hparams_file: Union[str, Path] = None,
device: str = None,
@@ -196,11 +196,12 @@ class Diariser:
"""
Loads a pretrained model from pyannote.audio,
either from a local cache or online repository.
either from a local cache or some online repository.
Args:
model: Path or identifier for the pyannote model.
default: /models/pyannote/speaker_diarization/config.yaml
default: '/home/[user]/.cache/torch/models/pyannote/config.yaml'
or one of 'jaikinator/scraibe', 'pyannote/speaker-diarization-3.1'
token: Optional HUGGINGFACE_TOKEN for authenticated access.
cache_token: Whether to cache the token locally for future use.
cache_dir: Directory for caching models.
@@ -262,7 +263,7 @@ class Diariser:
if cache_token and use_auth_token is not None:
cls._save_token(use_auth_token)
if not os.path.exists(model) and use_auth_token is None:
if use_auth_token is None:
use_auth_token = cls._get_token()
else:
raise FileNotFoundError(f'No local model or directory found at {model}.')
@@ -271,6 +272,10 @@ class Diariser:
use_auth_token=use_auth_token,
cache_dir=cache_dir,
hparams_file=hparams_file,)
if _model is None:
raise ValueError('Unable to load model either from local cache' \
'or from huggingface.co models. Please check your token' \
'or your local model path')
# try to move the model to the device
if device is None:
@@ -278,11 +283,6 @@ class Diariser:
_model = _model.to(torch_device(device)) # torch_device is renamed from torch.device to avoid name conflict
if _model is None:
raise ValueError('Unable to load model either from local cache' \
'or from huggingface.co models. Please check your token' \
'or your local model path')
return cls(_model)
@staticmethod