-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.py
More file actions
288 lines (239 loc) · 8.86 KB
/
Copy pathcli.py
File metadata and controls
288 lines (239 loc) · 8.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#!/usr/bin/env python3
"""
UVR Headless Runner - Unified CLI Entry Point
==============================================
Provides a single `uvr` command that dispatches to the appropriate runner.
Usage:
uvr mdx -m "UVR-MDX-NET Inst HQ 3" -i song.wav -o output/
uvr demucs -m htdemucs -i song.wav -o output/
uvr vr -m "UVR-De-Echo-Normal" -i song.wav -o output/
uvr list [mdx|demucs|vr|all]
uvr download <model-name> --arch <mdx|demucs|vr>
uvr info
uvr help
This module is the entry point registered as `uvr` in pyproject.toml:
[tool.poetry.scripts]
uvr = "cli:main"
"""
import os
import sys
VERSION = "1.1.0"
def _run_runner(module_name, suppress_errors=False):
"""
Import and run a runner module's main() function.
Handles ImportError gracefully (e.g. missing dependencies).
"""
try:
import importlib
mod = importlib.import_module(module_name)
return mod.main()
except ImportError as e:
if suppress_errors:
print(f" (unavailable: {e})")
return 1
print(f"Error: Missing dependency — {e}")
print("Run: pip install -r requirements.txt")
return 1
except SystemExit as e:
# argparse --help raises SystemExit(0), let it through
return e.code if e.code else 0
except Exception as e:
if suppress_errors:
print(f" (error: {e})")
return 1
raise
def print_banner():
"""Print the UVR banner."""
print()
print("╔═══════════════════════════════════════════════════════════════╗")
print("║ UVR Headless Runner - Audio Source Separation CLI ║")
print(f"║ Version {VERSION} ║")
print("╚═══════════════════════════════════════════════════════════════╝")
print()
def print_usage():
"""Print usage information."""
print_banner()
print("Usage: uvr <command> [options]")
print()
print("Commands:")
print(" mdx Run MDX-Net/Roformer/SCNet separation")
print(" demucs Run Demucs separation")
print(" vr Run VR Architecture separation")
print(" list List available models")
print(" download Download a model")
print(" info Show system information")
print(" help Show this help message")
print()
print("Examples:")
print(' uvr mdx -m "UVR-MDX-NET Inst HQ 3" -i song.wav -o output/')
print(' uvr demucs -m htdemucs -i song.wav -o output/')
print(' uvr vr -m "UVR-De-Echo-Normal" -i song.wav -o output/')
print(' uvr list mdx')
print(' uvr download "htdemucs_ft" --arch demucs')
print()
print("For command-specific help:")
print(" uvr mdx --help")
print(" uvr demucs --help")
print(" uvr vr --help")
def print_info():
"""Print system information."""
print_banner()
print("System Information:")
print("===================")
# Python version
print(f"Python: {sys.version.split()[0]}")
# PyTorch version and CUDA
try:
import torch
print(f"PyTorch: {torch.__version__}")
cuda_available = torch.cuda.is_available()
print(f"CUDA Available: {'Yes' if cuda_available else 'No'}")
if cuda_available:
print(f"CUDA Version: {torch.version.cuda}")
print(f"GPU Device: {torch.cuda.get_device_name(0)}")
print(f"GPU Count: {torch.cuda.device_count()}")
except ImportError:
print("PyTorch: Not installed")
# DirectML
try:
import torch_directml
print(f"DirectML: Available")
except ImportError:
print(f"DirectML: Not available")
# MPS (Apple Silicon)
try:
import torch
if hasattr(torch.backends, 'mps') and torch.backends.mps.is_available():
print("MPS (Apple Silicon): Available")
except (ImportError, AttributeError):
pass
# Model directory
models_dir = os.environ.get('UVR_MODELS_DIR', os.path.join(os.path.expanduser('~'), '.uvr_models'))
print(f"\nModel Directory: {models_dir}")
# Check model counts
if os.path.isdir(models_dir):
print("\nInstalled Models:")
mdx_dir = os.path.join(models_dir, 'MDX_Net_Models')
if os.path.isdir(mdx_dir):
count = len([f for f in os.listdir(mdx_dir)
if f.endswith(('.onnx', '.ckpt'))])
print(f" MDX-Net: {count} models")
demucs_dir = os.path.join(models_dir, 'Demucs_Models')
if os.path.isdir(demucs_dir):
count = 0
for root, dirs, files in os.walk(demucs_dir):
count += len([f for f in files if f.endswith(('.th', '.yaml'))])
print(f" Demucs: {count} files")
vr_dir = os.path.join(models_dir, 'VR_Models')
if os.path.isdir(vr_dir):
count = len([f for f in os.listdir(vr_dir)
if f.endswith('.pth')])
print(f" VR: {count} models")
else:
print(f"\nModel directory not found. Models will be downloaded on first use.")
# Proxy status
try:
from model_downloader import is_proxy_configured
print(f"\nProxy: {'Configured' if is_proxy_configured() else 'Not configured'}")
except ImportError:
pass
print()
def cmd_list(args):
"""Handle 'uvr list' subcommand."""
arch = args[0] if args else "all"
if arch == "mdx":
sys.argv = ["uvr-mdx", "--list"]
return _run_runner("mdx_headless_runner")
elif arch == "demucs":
sys.argv = ["uvr-demucs", "--list"]
return _run_runner("demucs_headless_runner")
elif arch == "vr":
sys.argv = ["uvr-vr", "--list"]
return _run_runner("vr_headless_runner")
elif arch == "all":
print("=== MDX-Net Models ===")
sys.argv = ["uvr-mdx", "--list"]
_run_runner("mdx_headless_runner", suppress_errors=True)
print()
print("=== Demucs Models ===")
sys.argv = ["uvr-demucs", "--list"]
_run_runner("demucs_headless_runner", suppress_errors=True)
print()
print("=== VR Models ===")
sys.argv = ["uvr-vr", "--list"]
_run_runner("vr_headless_runner", suppress_errors=True)
return 0
else:
print(f"Unknown architecture: {arch}")
print("Valid options: mdx, demucs, vr, all")
return 1
def cmd_download(args):
"""Handle 'uvr download' subcommand."""
if not args:
print("Error: Model name required")
print('Usage: uvr download <model-name> --arch <mdx|demucs|vr>')
return 1
model_name = args[0]
rest_args = args[1:]
# Parse --arch flag
arch = None
i = 0
while i < len(rest_args):
if rest_args[i] in ("--arch", "-a") and i + 1 < len(rest_args):
arch = rest_args[i + 1]
i += 2
else:
i += 1
if not arch:
print("Error: Architecture required")
print('Usage: uvr download <model-name> --arch <mdx|demucs|vr>')
return 1
if arch == "mdx":
sys.argv = ["uvr-mdx", "--download", model_name]
return _run_runner("mdx_headless_runner")
elif arch == "demucs":
sys.argv = ["uvr-demucs", "--download", model_name]
return _run_runner("demucs_headless_runner")
elif arch == "vr":
sys.argv = ["uvr-vr", "--download", model_name]
return _run_runner("vr_headless_runner")
else:
print(f"Unknown architecture: {arch}")
print("Valid options: mdx, demucs, vr")
return 1
def main():
"""Unified CLI entry point — dispatches to the appropriate runner."""
if len(sys.argv) < 2:
print_usage()
return 0
command = sys.argv[1]
remaining_args = sys.argv[2:]
if command == "mdx":
sys.argv = ["uvr-mdx"] + remaining_args
return _run_runner("mdx_headless_runner")
elif command == "demucs":
sys.argv = ["uvr-demucs"] + remaining_args
return _run_runner("demucs_headless_runner")
elif command == "vr":
sys.argv = ["uvr-vr"] + remaining_args
return _run_runner("vr_headless_runner")
elif command == "list":
return cmd_list(remaining_args)
elif command == "download":
return cmd_download(remaining_args)
elif command == "info":
print_info()
return 0
elif command in ("help", "--help", "-h"):
print_usage()
return 0
elif command in ("version", "--version", "-v"):
print(f"uvr-headless-runner {VERSION}")
return 0
else:
print(f"Error: Unknown command '{command}'")
print()
print_usage()
return 1
if __name__ == "__main__":
sys.exit(main() or 0)