Skip to content

Commit e9f5d0c

Browse files
committed
Added AUDIO_SEPARATOR_MODEL_DIR env var to override model dir. Relaxed torch dependency again, with fix for demucs on torch 2.6. Improved inode utilization of test script.
1 parent 6177db4 commit e9f5d0c

6 files changed

Lines changed: 1035 additions & 713 deletions

File tree

audio_separator/separator/separator.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,24 @@ def __init__(
123123
package_version = self.get_package_distribution("audio-separator").version
124124
self.logger.info(f"Separator version {package_version} instantiating with output_dir: {output_dir}, output_format: {output_format}")
125125

126-
self.model_file_dir = model_file_dir
127-
128126
if output_dir is None:
129127
output_dir = os.getcwd()
130128
if not info_only:
131129
self.logger.info("Output directory not specified. Using current working directory.")
132130

133131
self.output_dir = output_dir
134132

133+
# Check for environment variable to override model_file_dir
134+
env_model_dir = os.environ.get("AUDIO_SEPARATOR_MODEL_DIR")
135+
if env_model_dir:
136+
self.model_file_dir = env_model_dir
137+
self.logger.info(f"Using model directory from AUDIO_SEPARATOR_MODEL_DIR env var: {self.model_file_dir}")
138+
if not os.path.exists(self.model_file_dir):
139+
raise FileNotFoundError(f"The specified model directory does not exist: {self.model_file_dir}")
140+
else:
141+
self.logger.info(f"Using model directory from model_file_dir parameter: {model_file_dir}")
142+
self.model_file_dir = model_file_dir
143+
135144
# Create the model directory if it does not exist
136145
os.makedirs(self.model_file_dir, exist_ok=True)
137146
os.makedirs(self.output_dir, exist_ok=True)

audio_separator/separator/uvr_lib_v5/demucs/states.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def load_model(path_or_package, strict=False):
4040
with warnings.catch_warnings():
4141
warnings.simplefilter("ignore")
4242
path = path_or_package
43-
package = torch.load(path, "cpu")
43+
package = torch.load(path, "cpu", weights_only=False)
4444
else:
4545
raise ValueError(f"Invalid type for {path_or_package}.")
4646

audio_separator/utils/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def main():
4141
output_format_help = "Output format for separated files, any common format (default: %(default)s). Example: --output_format=MP3"
4242
output_bitrate_help = "Output bitrate for separated files, any ffmpeg-compatible bitrate (default: %(default)s). Example: --output_bitrate=320k"
4343
output_dir_help = "Directory to write output files (default: <current dir>). Example: --output_dir=/app/separated"
44-
model_file_dir_help = "Model files directory (default: %(default)s). Example: --model_file_dir=/app/models"
44+
model_file_dir_help = "Model files directory (default: %(default)s or AUDIO_SEPARATOR_MODEL_DIR env var if set). Example: --model_file_dir=/app/models"
4545
download_model_only_help = "Download a single model file only, without performing separation."
4646

4747
io_params = parser.add_argument_group("Separation I/O Params")

0 commit comments

Comments
 (0)