solved path issues

This commit is contained in:
Jaikinator
2023-06-30 18:41:43 +02:00
parent 11fce3abef
commit cd35ad8903
+23 -26
View File
@@ -1,4 +1,3 @@
from pyannote.audio import Pipeline from pyannote.audio import Pipeline
from whisper import Whisper, load_model from whisper import Whisper, load_model
import os import os
@@ -6,15 +5,18 @@ import glob
from warnings import warn from warnings import warn
import yaml import yaml
WHISPER_DEFAULT_PATH = os.path.relpath(os.path.join(os.path.dirname(__file__), CACHE_DIR = os.getenv(
"models", "whisper")) "AUTOT_CACHE",
os.path.expanduser("~/.cache/torch/models"),
)
PYANNOTE_DEFAULT_PATH = os.path.relpath(os.path.join(os.path.dirname(__file__), WHISPER_DEFAULT_PATH = os.path.join(CACHE_DIR, "whisper")
"models", "pyannote",
"speaker_diarization", "config.yaml"))
PYANNOTE_DEFAULT_PATH = os.path.join(CACHE_DIR, "pyannote")
def config_diarization_yaml(file, path_to_segmentation = None, path_to_embedding = None): PYANNOTE_DEFAULT_CONFIG = os.path.join(PYANNOTE_DEFAULT_PATH, "config.yaml")
def config_diarization_yaml(file, path_to_segmentation = None):
""" """
Configure diarization pipeline from yaml file to use the model offline Configure diarization pipeline from yaml file to use the model offline
and avoid manuel file manipulation. and avoid manuel file manipulation.
@@ -28,30 +30,25 @@ def config_diarization_yaml(file, path_to_segmentation = None, path_to_embedding
if path_to_segmentation: if path_to_segmentation:
yml["pipeline"]["params"]["segmentation"] = path_to_segmentation yml["pipeline"]["params"]["segmentation"] = path_to_segmentation
else: else:
yml["pipeline"]["params"]["segmentation"] = os.path.relpath(os.path.join( yml["pipeline"]["params"]["segmentation"] = os.path.join(PYANNOTE_DEFAULT_PATH, "pytorch_model.bin")
os.path.dirname(__file__),
"models", "pyannote",
"segmentation",
"pytorch_model.bin"))
if path_to_embedding: # if path_to_embedding:
yml["pipeline"]["params"]["embedding"] = path_to_embedding # yml["pipeline"]["params"]["embedding"] = path_to_embedding
else: # else:
yml["pipeline"]["params"]["embedding"] = os.path.relpath( # yml["pipeline"]["params"]["embedding"] = os.path.relpath(
os.path.join( # os.path.join(
os.path.dirname(__file__), # os.path.dirname(__file__),
"models", "pyannote", # "models", "pyannote",
"speechbrain", # "speechbrain",
"spkrec-ecapa-voxceleb", # "spkrec-ecapa-voxceleb",
"embedding_model.ckpt")) # "embedding_model.ckpt"))
if not os.path.exists(yml["pipeline"]["params"]["segmentation"]): if not os.path.exists(yml["pipeline"]["params"]["segmentation"]):
raise FileNotFoundError(f"Segmentation model not found at {yml['pipeline']['params']['segmentation']}") raise FileNotFoundError(f"Segmentation model not found at {yml['pipeline']['params']['segmentation']}")
if not os.path.exists(yml["pipeline"]["params"]["embedding"]): # if not os.path.exists(yml["pipeline"]["params"]["embedding"]):
raise FileNotFoundError(f"Embedding model not found at {yml['pipeline']['params']['embedding']}") # raise FileNotFoundError(f"Embedding model not found at {yml['pipeline']['params']['embedding']}")
with open(file, "w") as stream: with open(file, "w") as stream:
yaml.dump(yml, stream) yaml.dump(yml, stream)
stream.close() stream.close()