Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -6,597 +6,7 @@ import spaces
|
|
6 |
import gradio as gr
|
7 |
from audio_separator.separator import Separator
|
8 |
|
9 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
10 |
-
use_autocast = device == "cuda"
|
11 |
|
12 |
-
#=========================#
|
13 |
-
# Roformer Models #
|
14 |
-
#=========================#
|
15 |
-
roformer_models = {
|
16 |
-
'BS-Roformer-Viperx-1297': 'model_bs_roformer_ep_317_sdr_12.9755.ckpt',
|
17 |
-
'BS-Roformer-Viperx-1296': 'model_bs_roformer_ep_368_sdr_12.9628.ckpt',
|
18 |
-
'BS-Roformer-Viperx-1053': 'model_bs_roformer_ep_937_sdr_10.5309.ckpt',
|
19 |
-
'Mel-Roformer-Viperx-1143': 'model_mel_band_roformer_ep_3005_sdr_11.4360.ckpt',
|
20 |
-
'BS-Roformer-De-Reverb': 'deverb_bs_roformer_8_384dim_10depth.ckpt',
|
21 |
-
'Mel-Roformer-Crowd-Aufr33-Viperx': 'mel_band_roformer_crowd_aufr33_viperx_sdr_8.7144.ckpt',
|
22 |
-
'Mel-Roformer-Denoise-Aufr33': 'denoise_mel_band_roformer_aufr33_sdr_27.9959.ckpt',
|
23 |
-
'Mel-Roformer-Denoise-Aufr33-Aggr' : 'denoise_mel_band_roformer_aufr33_aggr_sdr_27.9768.ckpt',
|
24 |
-
'Mel-Roformer-Karaoke-Aufr33-Viperx': 'mel_band_roformer_karaoke_aufr33_viperx_sdr_10.1956.ckpt',
|
25 |
-
'MelBand Roformer Kim | Inst V1 by Unwa' : 'melband_roformer_inst_v1.ckpt',
|
26 |
-
'MelBand Roformer Kim | Inst V2 by Unwa' : 'melband_roformer_inst_v2.ckpt',
|
27 |
-
'MelBand Roformer Kim | InstVoc Duality V1 by Unwa' : 'melband_roformer_instvoc_duality_v1.ckpt',
|
28 |
-
'MelBand Roformer Kim | InstVoc Duality V2 by Unwa' : 'melband_roformer_instvox_duality_v2.ckpt',
|
29 |
-
}
|
30 |
-
|
31 |
-
#=========================#
|
32 |
-
# MDX23C Models #
|
33 |
-
#=========================#
|
34 |
-
mdx23c_models = [
|
35 |
-
'MDX23C_D1581.ckpt',
|
36 |
-
'MDX23C-8KFFT-InstVoc_HQ.ckpt',
|
37 |
-
'MDX23C-8KFFT-InstVoc_HQ_2.ckpt',
|
38 |
-
]
|
39 |
-
|
40 |
-
#=========================#
|
41 |
-
# MDXN-NET Models #
|
42 |
-
#=========================#
|
43 |
-
mdxnet_models = [
|
44 |
-
'UVR-MDX-NET-Inst_full_292.onnx',
|
45 |
-
'UVR-MDX-NET_Inst_187_beta.onnx',
|
46 |
-
'UVR-MDX-NET_Inst_82_beta.onnx',
|
47 |
-
'UVR-MDX-NET_Inst_90_beta.onnx',
|
48 |
-
'UVR-MDX-NET_Main_340.onnx',
|
49 |
-
'UVR-MDX-NET_Main_390.onnx',
|
50 |
-
'UVR-MDX-NET_Main_406.onnx',
|
51 |
-
'UVR-MDX-NET_Main_427.onnx',
|
52 |
-
'UVR-MDX-NET_Main_438.onnx',
|
53 |
-
'UVR-MDX-NET-Inst_HQ_1.onnx',
|
54 |
-
'UVR-MDX-NET-Inst_HQ_2.onnx',
|
55 |
-
'UVR-MDX-NET-Inst_HQ_3.onnx',
|
56 |
-
'UVR-MDX-NET-Inst_HQ_4.onnx',
|
57 |
-
'UVR-MDX-NET-Inst_HQ_5.onnx',
|
58 |
-
'UVR_MDXNET_Main.onnx',
|
59 |
-
'UVR-MDX-NET-Inst_Main.onnx',
|
60 |
-
'UVR_MDXNET_1_9703.onnx',
|
61 |
-
'UVR_MDXNET_2_9682.onnx',
|
62 |
-
'UVR_MDXNET_3_9662.onnx',
|
63 |
-
'UVR-MDX-NET-Inst_1.onnx',
|
64 |
-
'UVR-MDX-NET-Inst_2.onnx',
|
65 |
-
'UVR-MDX-NET-Inst_3.onnx',
|
66 |
-
'UVR_MDXNET_KARA.onnx',
|
67 |
-
'UVR_MDXNET_KARA_2.onnx',
|
68 |
-
'UVR_MDXNET_9482.onnx',
|
69 |
-
'UVR-MDX-NET-Voc_FT.onnx',
|
70 |
-
'Kim_Vocal_1.onnx',
|
71 |
-
'Kim_Vocal_2.onnx',
|
72 |
-
'Kim_Inst.onnx',
|
73 |
-
'Reverb_HQ_By_FoxJoy.onnx',
|
74 |
-
'UVR-MDX-NET_Crowd_HQ_1.onnx',
|
75 |
-
'kuielab_a_vocals.onnx',
|
76 |
-
'kuielab_a_other.onnx',
|
77 |
-
'kuielab_a_bass.onnx',
|
78 |
-
'kuielab_a_drums.onnx',
|
79 |
-
'kuielab_b_vocals.onnx',
|
80 |
-
'kuielab_b_other.onnx',
|
81 |
-
'kuielab_b_bass.onnx',
|
82 |
-
'kuielab_b_drums.onnx',
|
83 |
-
]
|
84 |
-
|
85 |
-
#========================#
|
86 |
-
# VR-ARCH Models #
|
87 |
-
#========================#
|
88 |
-
vrarch_models = [
|
89 |
-
'1_HP-UVR.pth',
|
90 |
-
'2_HP-UVR.pth',
|
91 |
-
'3_HP-Vocal-UVR.pth',
|
92 |
-
'4_HP-Vocal-UVR.pth',
|
93 |
-
'5_HP-Karaoke-UVR.pth',
|
94 |
-
'6_HP-Karaoke-UVR.pth',
|
95 |
-
'7_HP2-UVR.pth',
|
96 |
-
'8_HP2-UVR.pth',
|
97 |
-
'9_HP2-UVR.pth',
|
98 |
-
'10_SP-UVR-2B-32000-1.pth',
|
99 |
-
'11_SP-UVR-2B-32000-2.pth',
|
100 |
-
'12_SP-UVR-3B-44100.pth',
|
101 |
-
'13_SP-UVR-4B-44100-1.pth',
|
102 |
-
'14_SP-UVR-4B-44100-2.pth',
|
103 |
-
'15_SP-UVR-MID-44100-1.pth',
|
104 |
-
'16_SP-UVR-MID-44100-2.pth',
|
105 |
-
'17_HP-Wind_Inst-UVR.pth',
|
106 |
-
'UVR-De-Echo-Aggressive.pth',
|
107 |
-
'UVR-De-Echo-Normal.pth',
|
108 |
-
'UVR-DeEcho-DeReverb.pth',
|
109 |
-
'UVR-DeNoise-Lite.pth',
|
110 |
-
'UVR-DeNoise.pth',
|
111 |
-
'UVR-BVE-4B_SN-44100-1.pth',
|
112 |
-
'MGM_HIGHEND_v4.pth',
|
113 |
-
'MGM_LOWEND_A_v4.pth',
|
114 |
-
'MGM_LOWEND_B_v4.pth',
|
115 |
-
'MGM_MAIN_v4.pth',
|
116 |
-
]
|
117 |
-
|
118 |
-
#=======================#
|
119 |
-
# DEMUCS Models #
|
120 |
-
#=======================#
|
121 |
-
demucs_models = [
|
122 |
-
'htdemucs_ft.yaml',
|
123 |
-
'htdemucs_6s.yaml',
|
124 |
-
'htdemucs.yaml',
|
125 |
-
'hdemucs_mmi.yaml',
|
126 |
-
]
|
127 |
-
|
128 |
-
output_format = [
|
129 |
-
'wav',
|
130 |
-
'flac',
|
131 |
-
'mp3',
|
132 |
-
'ogg',
|
133 |
-
'opus',
|
134 |
-
'm4a',
|
135 |
-
'aiff',
|
136 |
-
'ac3'
|
137 |
-
]
|
138 |
-
|
139 |
-
found_files = []
|
140 |
-
logs = []
|
141 |
-
out_dir = "./outputs"
|
142 |
-
models_dir = "./models"
|
143 |
-
extensions = (".wav", ".flac", ".mp3", ".ogg", ".opus", ".m4a", ".aiff", ".ac3")
|
144 |
-
|
145 |
-
def download_audio(url, output_dir="ytdl"):
|
146 |
-
|
147 |
-
os.makedirs(output_dir, exist_ok=True)
|
148 |
-
|
149 |
-
ydl_opts = {
|
150 |
-
'format': 'bestaudio/best',
|
151 |
-
'postprocessors': [{
|
152 |
-
'key': 'FFmpegExtractAudio',
|
153 |
-
'preferredcodec': 'wav',
|
154 |
-
'preferredquality': '32',
|
155 |
-
}],
|
156 |
-
'outtmpl': os.path.join(output_dir, '%(title)s.%(ext)s'),
|
157 |
-
'postprocessor_args': [
|
158 |
-
'-acodec', 'pcm_f32le'
|
159 |
-
],
|
160 |
-
}
|
161 |
-
|
162 |
-
try:
|
163 |
-
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
164 |
-
info = ydl.extract_info(url, download=False)
|
165 |
-
video_title = info['title']
|
166 |
-
|
167 |
-
ydl.download([url])
|
168 |
-
|
169 |
-
file_path = os.path.join(output_dir, f"{video_title}.wav")
|
170 |
-
|
171 |
-
if os.path.exists(file_path):
|
172 |
-
return os.path.abspath(file_path)
|
173 |
-
else:
|
174 |
-
raise Exception("Something went wrong")
|
175 |
-
|
176 |
-
except Exception as e:
|
177 |
-
raise Exception(f"Error extracting audio with yt-dlp: {str(e)}")
|
178 |
-
|
179 |
-
@spaces.GPU(duration=60)
|
180 |
-
def roformer_separator(audio, model_key, out_format, segment_size, override_seg_size, overlap, batch_size, norm_thresh, amp_thresh, progress=gr.Progress(track_tqdm=True)):
|
181 |
-
base_name = os.path.splitext(os.path.basename(audio))[0]
|
182 |
-
roformer_model = roformer_models[model_key]
|
183 |
-
try:
|
184 |
-
separator = Separator(
|
185 |
-
log_level=logging.WARNING,
|
186 |
-
model_file_dir=models_dir,
|
187 |
-
output_dir=out_dir,
|
188 |
-
output_format=out_format,
|
189 |
-
use_autocast=use_autocast,
|
190 |
-
normalization_threshold=norm_thresh,
|
191 |
-
amplification_threshold=amp_thresh,
|
192 |
-
mdxc_params={
|
193 |
-
"segment_size": segment_size,
|
194 |
-
"override_model_segment_size": override_seg_size,
|
195 |
-
"batch_size": batch_size,
|
196 |
-
"overlap": overlap,
|
197 |
-
}
|
198 |
-
)
|
199 |
-
|
200 |
-
progress(0.2, desc="Loading model...")
|
201 |
-
separator.load_model(model_filename=roformer_model)
|
202 |
-
|
203 |
-
progress(0.7, desc="Separating audio...")
|
204 |
-
separation = separator.separate(audio, f"{base_name}_(Stem1)", f"{base_name}_(Stem2)")
|
205 |
-
|
206 |
-
stems = [os.path.join(out_dir, file_name) for file_name in separation]
|
207 |
-
return stems[1], stems[0]
|
208 |
-
except Exception as e:
|
209 |
-
raise RuntimeError(f"Roformer separation failed: {e}") from e
|
210 |
-
|
211 |
-
@spaces.GPU(duration=60)
|
212 |
-
def mdxc_separator(audio, model, out_format, segment_size, override_seg_size, overlap, batch_size, norm_thresh, amp_thresh, progress=gr.Progress(track_tqdm=True)):
|
213 |
-
base_name = os.path.splitext(os.path.basename(audio))[0]
|
214 |
-
try:
|
215 |
-
separator = Separator(
|
216 |
-
log_level=logging.WARNING,
|
217 |
-
model_file_dir=models_dir,
|
218 |
-
output_dir=out_dir,
|
219 |
-
output_format=out_format,
|
220 |
-
use_autocast=use_autocast,
|
221 |
-
normalization_threshold=norm_thresh,
|
222 |
-
amplification_threshold=amp_thresh,
|
223 |
-
mdxc_params={
|
224 |
-
"segment_size": segment_size,
|
225 |
-
"override_model_segment_size": override_seg_size,
|
226 |
-
"batch_size": batch_size,
|
227 |
-
"overlap": overlap,
|
228 |
-
}
|
229 |
-
)
|
230 |
-
|
231 |
-
progress(0.2, desc="Loading model...")
|
232 |
-
separator.load_model(model_filename=model)
|
233 |
-
|
234 |
-
progress(0.7, desc="Separating audio...")
|
235 |
-
separation = separator.separate(audio, f"{base_name}_(Stem1)", f"{base_name}_(Stem2)")
|
236 |
-
|
237 |
-
stems = [os.path.join(out_dir, file_name) for file_name in separation]
|
238 |
-
return stems[1], stems[0]
|
239 |
-
except Exception as e:
|
240 |
-
raise RuntimeError(f"MDX23C separation failed: {e}") from e
|
241 |
-
|
242 |
-
@spaces.GPU(duration=60)
|
243 |
-
def mdxnet_separator(audio, model, out_format, hop_length, segment_size, denoise, overlap, batch_size, norm_thresh, amp_thresh, progress=gr.Progress(track_tqdm=True)):
|
244 |
-
base_name = os.path.splitext(os.path.basename(audio))[0]
|
245 |
-
try:
|
246 |
-
separator = Separator(
|
247 |
-
log_level=logging.WARNING,
|
248 |
-
model_file_dir=models_dir,
|
249 |
-
output_dir=out_dir,
|
250 |
-
output_format=out_format,
|
251 |
-
use_autocast=use_autocast,
|
252 |
-
normalization_threshold=norm_thresh,
|
253 |
-
amplification_threshold=amp_thresh,
|
254 |
-
mdx_params={
|
255 |
-
"hop_length": hop_length,
|
256 |
-
"segment_size": segment_size,
|
257 |
-
"overlap": overlap,
|
258 |
-
"batch_size": batch_size,
|
259 |
-
"enable_denoise": denoise,
|
260 |
-
}
|
261 |
-
)
|
262 |
-
|
263 |
-
progress(0.2, desc="Loading model...")
|
264 |
-
separator.load_model(model_filename=model)
|
265 |
-
|
266 |
-
progress(0.7, desc="Separating audio...")
|
267 |
-
separation = separator.separate(audio, f"{base_name}_(Stem1)", f"{base_name}_(Stem2)")
|
268 |
-
|
269 |
-
stems = [os.path.join(out_dir, file_name) for file_name in separation]
|
270 |
-
return stems[0], stems[1]
|
271 |
-
except Exception as e:
|
272 |
-
raise RuntimeError(f"MDX-NET separation failed: {e}") from e
|
273 |
-
|
274 |
-
@spaces.GPU(duration=60)
|
275 |
-
def vrarch_separator(audio, model, out_format, window_size, aggression, tta, post_process, post_process_threshold, high_end_process, batch_size, norm_thresh, amp_thresh, progress=gr.Progress(track_tqdm=True)):
|
276 |
-
base_name = os.path.splitext(os.path.basename(audio))[0]
|
277 |
-
try:
|
278 |
-
separator = Separator(
|
279 |
-
log_level=logging.WARNING,
|
280 |
-
model_file_dir=models_dir,
|
281 |
-
output_dir=out_dir,
|
282 |
-
output_format=out_format,
|
283 |
-
use_autocast=use_autocast,
|
284 |
-
normalization_threshold=norm_thresh,
|
285 |
-
amplification_threshold=amp_thresh,
|
286 |
-
vr_params={
|
287 |
-
"batch_size": batch_size,
|
288 |
-
"window_size": window_size,
|
289 |
-
"aggression": aggression,
|
290 |
-
"enable_tta": tta,
|
291 |
-
"enable_post_process": post_process,
|
292 |
-
"post_process_threshold": post_process_threshold,
|
293 |
-
"high_end_process": high_end_process,
|
294 |
-
}
|
295 |
-
)
|
296 |
-
|
297 |
-
progress(0.2, desc="Loading model...")
|
298 |
-
separator.load_model(model_filename=model)
|
299 |
-
|
300 |
-
progress(0.7, desc="Separating audio...")
|
301 |
-
separation = separator.separate(audio, f"{base_name}_(Stem1)", f"{base_name}_(Stem2)")
|
302 |
-
|
303 |
-
stems = [os.path.join(out_dir, file_name) for file_name in separation]
|
304 |
-
return stems[0], stems[1]
|
305 |
-
except Exception as e:
|
306 |
-
raise RuntimeError(f"VR ARCH separation failed: {e}") from e
|
307 |
-
|
308 |
-
@spaces.GPU(duration=60)
|
309 |
-
def demucs_separator(audio, model, out_format, shifts, segment_size, segments_enabled, overlap, batch_size, norm_thresh, amp_thresh, progress=gr.Progress(track_tqdm=True)):
|
310 |
-
base_name = os.path.splitext(os.path.basename(audio))[0]
|
311 |
-
try:
|
312 |
-
separator = Separator(
|
313 |
-
log_level=logging.WARNING,
|
314 |
-
model_file_dir=models_dir,
|
315 |
-
output_dir=out_dir,
|
316 |
-
output_format=out_format,
|
317 |
-
use_autocast=use_autocast,
|
318 |
-
normalization_threshold=norm_thresh,
|
319 |
-
amplification_threshold=amp_thresh,
|
320 |
-
demucs_params={
|
321 |
-
"batch_size": batch_size,
|
322 |
-
"segment_size": segment_size,
|
323 |
-
"shifts": shifts,
|
324 |
-
"overlap": overlap,
|
325 |
-
"segments_enabled": segments_enabled,
|
326 |
-
}
|
327 |
-
)
|
328 |
-
|
329 |
-
progress(0.2, desc="Loading model...")
|
330 |
-
separator.load_model(model_filename=model)
|
331 |
-
|
332 |
-
progress(0.7, desc="Separating audio...")
|
333 |
-
separation = separator.separate(audio)
|
334 |
-
|
335 |
-
stems = [os.path.join(out_dir, file_name) for file_name in separation]
|
336 |
-
|
337 |
-
if model == "htdemucs_6s.yaml":
|
338 |
-
return stems[0], stems[1], stems[2], stems[3], stems[4], stems[5]
|
339 |
-
else:
|
340 |
-
return stems[0], stems[1], stems[2], stems[3], None, None
|
341 |
-
except Exception as e:
|
342 |
-
raise RuntimeError(f"Demucs separation failed: {e}") from e
|
343 |
-
|
344 |
-
def update_stems(model):
|
345 |
-
if model == "htdemucs_6s.yaml":
|
346 |
-
return gr.update(visible=True)
|
347 |
-
else:
|
348 |
-
return gr.update(visible=False)
|
349 |
-
|
350 |
-
@spaces.GPU(duration=60)
|
351 |
-
def roformer_batch(path_input, path_output, model_key, out_format, segment_size, override_seg_size, overlap, batch_size, norm_thresh, amp_thresh):
|
352 |
-
found_files.clear()
|
353 |
-
logs.clear()
|
354 |
-
roformer_model = roformer_models[model_key]
|
355 |
-
|
356 |
-
for audio_files in os.listdir(path_input):
|
357 |
-
if audio_files.endswith(extensions):
|
358 |
-
found_files.append(audio_files)
|
359 |
-
total_files = len(found_files)
|
360 |
-
|
361 |
-
if total_files == 0:
|
362 |
-
logs.append("No valid audio files.")
|
363 |
-
yield "\n".join(logs)
|
364 |
-
else:
|
365 |
-
logs.append(f"{total_files} audio files found")
|
366 |
-
found_files.sort()
|
367 |
-
|
368 |
-
for audio_files in found_files:
|
369 |
-
file_path = os.path.join(path_input, audio_files)
|
370 |
-
base_name = os.path.splitext(os.path.basename(file_path))[0]
|
371 |
-
try:
|
372 |
-
separator = Separator(
|
373 |
-
log_level=logging.WARNING,
|
374 |
-
model_file_dir=models_dir,
|
375 |
-
output_dir=path_output,
|
376 |
-
output_format=out_format,
|
377 |
-
use_autocast=use_autocast,
|
378 |
-
normalization_threshold=norm_thresh,
|
379 |
-
amplification_threshold=amp_thresh,
|
380 |
-
mdxc_params={
|
381 |
-
"segment_size": segment_size,
|
382 |
-
"override_model_segment_size": override_seg_size,
|
383 |
-
"batch_size": batch_size,
|
384 |
-
"overlap": overlap,
|
385 |
-
}
|
386 |
-
)
|
387 |
-
|
388 |
-
logs.append("Loading model...")
|
389 |
-
yield "\n".join(logs)
|
390 |
-
separator.load_model(model_filename=roformer_model)
|
391 |
-
|
392 |
-
logs.append(f"Separating file: {audio_files}")
|
393 |
-
yield "\n".join(logs)
|
394 |
-
separator.separate(file_path, f"{base_name}_(Stem1)", f"{base_name}_(Stem2)")
|
395 |
-
logs.append(f"File: {audio_files} separated!")
|
396 |
-
yield "\n".join(logs)
|
397 |
-
except Exception as e:
|
398 |
-
raise RuntimeError(f"Roformer batch separation failed: {e}") from e
|
399 |
-
|
400 |
-
@spaces.GPU(duration=60)
|
401 |
-
def mdx23c_batch(path_input, path_output, model, out_format, segment_size, override_seg_size, overlap, batch_size, norm_thresh, amp_thresh):
|
402 |
-
found_files.clear()
|
403 |
-
logs.clear()
|
404 |
-
|
405 |
-
for audio_files in os.listdir(path_input):
|
406 |
-
if audio_files.endswith(extensions):
|
407 |
-
found_files.append(audio_files)
|
408 |
-
total_files = len(found_files)
|
409 |
-
|
410 |
-
if total_files == 0:
|
411 |
-
logs.append("No valid audio files.")
|
412 |
-
yield "\n".join(logs)
|
413 |
-
else:
|
414 |
-
logs.append(f"{total_files} audio files found")
|
415 |
-
found_files.sort()
|
416 |
-
|
417 |
-
for audio_files in found_files:
|
418 |
-
file_path = os.path.join(path_input, audio_files)
|
419 |
-
base_name = os.path.splitext(os.path.basename(file_path))[0]
|
420 |
-
try:
|
421 |
-
separator = Separator(
|
422 |
-
log_level=logging.WARNING,
|
423 |
-
model_file_dir=models_dir,
|
424 |
-
output_dir=path_output,
|
425 |
-
output_format=out_format,
|
426 |
-
use_autocast=use_autocast,
|
427 |
-
normalization_threshold=norm_thresh,
|
428 |
-
amplification_threshold=amp_thresh,
|
429 |
-
mdxc_params={
|
430 |
-
"segment_size": segment_size,
|
431 |
-
"override_model_segment_size": override_seg_size,
|
432 |
-
"batch_size": batch_size,
|
433 |
-
"overlap": overlap,
|
434 |
-
}
|
435 |
-
)
|
436 |
-
|
437 |
-
logs.append("Loading model...")
|
438 |
-
yield "\n".join(logs)
|
439 |
-
separator.load_model(model_filename=model)
|
440 |
-
|
441 |
-
logs.append(f"Separating file: {audio_files}")
|
442 |
-
yield "\n".join(logs)
|
443 |
-
separator.separate(file_path, f"{base_name}_(Stem1)", f"{base_name}_(Stem2)")
|
444 |
-
logs.append(f"File: {audio_files} separated!")
|
445 |
-
yield "\n".join(logs)
|
446 |
-
except Exception as e:
|
447 |
-
raise RuntimeError(f"Roformer batch separation failed: {e}") from e
|
448 |
-
|
449 |
-
@spaces.GPU(duration=60)
|
450 |
-
def mdxnet_batch(path_input, path_output, model, out_format, hop_length, segment_size, denoise, overlap, batch_size, norm_thresh, amp_thresh):
|
451 |
-
found_files.clear()
|
452 |
-
logs.clear()
|
453 |
-
|
454 |
-
for audio_files in os.listdir(path_input):
|
455 |
-
if audio_files.endswith(extensions):
|
456 |
-
found_files.append(audio_files)
|
457 |
-
total_files = len(found_files)
|
458 |
-
|
459 |
-
if total_files == 0:
|
460 |
-
logs.append("No valid audio files.")
|
461 |
-
yield "\n".join(logs)
|
462 |
-
else:
|
463 |
-
logs.append(f"{total_files} audio files found")
|
464 |
-
found_files.sort()
|
465 |
-
|
466 |
-
for audio_files in found_files:
|
467 |
-
file_path = os.path.join(path_input, audio_files)
|
468 |
-
base_name = os.path.splitext(os.path.basename(file_path))[0]
|
469 |
-
try:
|
470 |
-
separator = Separator(
|
471 |
-
log_level=logging.WARNING,
|
472 |
-
model_file_dir=models_dir,
|
473 |
-
output_dir=path_output,
|
474 |
-
output_format=out_format,
|
475 |
-
use_autocast=use_autocast,
|
476 |
-
normalization_threshold=norm_thresh,
|
477 |
-
amplification_threshold=amp_thresh,
|
478 |
-
mdx_params={
|
479 |
-
"hop_length": hop_length,
|
480 |
-
"segment_size": segment_size,
|
481 |
-
"overlap": overlap,
|
482 |
-
"batch_size": batch_size,
|
483 |
-
"enable_denoise": denoise,
|
484 |
-
}
|
485 |
-
)
|
486 |
-
|
487 |
-
logs.append("Loading model...")
|
488 |
-
yield "\n".join(logs)
|
489 |
-
separator.load_model(model_filename=model)
|
490 |
-
|
491 |
-
logs.append(f"Separating file: {audio_files}")
|
492 |
-
yield "\n".join(logs)
|
493 |
-
separator.separate(file_path, f"{base_name}_(Stem1)", f"{base_name}_(Stem2)")
|
494 |
-
logs.append(f"File: {audio_files} separated!")
|
495 |
-
yield "\n".join(logs)
|
496 |
-
except Exception as e:
|
497 |
-
raise RuntimeError(f"Roformer batch separation failed: {e}") from e
|
498 |
-
|
499 |
-
@spaces.GPU(duration=60)
|
500 |
-
def vrarch_batch(path_input, path_output, model, out_format, window_size, aggression, tta, post_process, post_process_threshold, high_end_process, batch_size, norm_thresh, amp_thresh):
|
501 |
-
found_files.clear()
|
502 |
-
logs.clear()
|
503 |
-
|
504 |
-
for audio_files in os.listdir(path_input):
|
505 |
-
if audio_files.endswith(extensions):
|
506 |
-
found_files.append(audio_files)
|
507 |
-
total_files = len(found_files)
|
508 |
-
|
509 |
-
if total_files == 0:
|
510 |
-
logs.append("No valid audio files.")
|
511 |
-
yield "\n".join(logs)
|
512 |
-
else:
|
513 |
-
logs.append(f"{total_files} audio files found")
|
514 |
-
found_files.sort()
|
515 |
-
|
516 |
-
for audio_files in found_files:
|
517 |
-
file_path = os.path.join(path_input, audio_files)
|
518 |
-
base_name = os.path.splitext(os.path.basename(file_path))[0]
|
519 |
-
try:
|
520 |
-
separator = Separator(
|
521 |
-
log_level=logging.WARNING,
|
522 |
-
model_file_dir=models_dir,
|
523 |
-
output_dir=path_output,
|
524 |
-
output_format=out_format,
|
525 |
-
use_autocast=use_autocast,
|
526 |
-
normalization_threshold=norm_thresh,
|
527 |
-
amplification_threshold=amp_thresh,
|
528 |
-
vr_params={
|
529 |
-
"batch_size": batch_size,
|
530 |
-
"window_size": window_size,
|
531 |
-
"aggression": aggression,
|
532 |
-
"enable_tta": tta,
|
533 |
-
"enable_post_process": post_process,
|
534 |
-
"post_process_threshold": post_process_threshold,
|
535 |
-
"high_end_process": high_end_process,
|
536 |
-
}
|
537 |
-
)
|
538 |
-
|
539 |
-
logs.append("Loading model...")
|
540 |
-
yield "\n".join(logs)
|
541 |
-
separator.load_model(model_filename=model)
|
542 |
-
|
543 |
-
logs.append(f"Separating file: {audio_files}")
|
544 |
-
yield "\n".join(logs)
|
545 |
-
separator.separate(file_path, f"{base_name}_(Stem1)", f"{base_name}_(Stem2)")
|
546 |
-
logs.append(f"File: {audio_files} separated!")
|
547 |
-
yield "\n".join(logs)
|
548 |
-
except Exception as e:
|
549 |
-
raise RuntimeError(f"Roformer batch separation failed: {e}") from e
|
550 |
-
|
551 |
-
@spaces.GPU(duration=60)
|
552 |
-
def demucs_batch(path_input, path_output, model, out_format, shifts, segment_size, segments_enabled, overlap, batch_size, norm_thresh, amp_thresh):
|
553 |
-
found_files.clear()
|
554 |
-
logs.clear()
|
555 |
-
|
556 |
-
for audio_files in os.listdir(path_input):
|
557 |
-
if audio_files.endswith(extensions):
|
558 |
-
found_files.append(audio_files)
|
559 |
-
total_files = len(found_files)
|
560 |
-
|
561 |
-
if total_files == 0:
|
562 |
-
logs.append("No valid audio files.")
|
563 |
-
yield "\n".join(logs)
|
564 |
-
else:
|
565 |
-
logs.append(f"{total_files} audio files found")
|
566 |
-
found_files.sort()
|
567 |
-
|
568 |
-
for audio_files in found_files:
|
569 |
-
file_path = os.path.join(path_input, audio_files)
|
570 |
-
try:
|
571 |
-
separator = Separator(
|
572 |
-
log_level=logging.WARNING,
|
573 |
-
model_file_dir=models_dir,
|
574 |
-
output_dir=path_output,
|
575 |
-
output_format=out_format,
|
576 |
-
use_autocast=use_autocast,
|
577 |
-
normalization_threshold=norm_thresh,
|
578 |
-
amplification_threshold=amp_thresh,
|
579 |
-
demucs_params={
|
580 |
-
"batch_size": batch_size,
|
581 |
-
"segment_size": segment_size,
|
582 |
-
"shifts": shifts,
|
583 |
-
"overlap": overlap,
|
584 |
-
"segments_enabled": segments_enabled,
|
585 |
-
}
|
586 |
-
)
|
587 |
-
|
588 |
-
logs.append("Loading model...")
|
589 |
-
yield "\n".join(logs)
|
590 |
-
separator.load_model(model_filename=model)
|
591 |
-
|
592 |
-
logs.append(f"Separating file: {audio_files}")
|
593 |
-
yield "\n".join(logs)
|
594 |
-
separator.separate(file_path)
|
595 |
-
logs.append(f"File: {audio_files} separated!")
|
596 |
-
yield "\n".join(logs)
|
597 |
-
except Exception as e:
|
598 |
-
raise RuntimeError(f"Roformer batch separation failed: {e}") from e
|
599 |
-
|
600 |
with gr.Blocks(theme ="hev832/applio", title = "🎵 Audio Separator UI 🎵") as app:
|
601 |
with gr.Row():
|
602 |
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