Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
import logging
|
3 |
import gradio as gr
|
4 |
|
@@ -108,9 +109,19 @@ def rename_stems(input_file, output_dir, stems, output_format):
|
|
108 |
renamed_stems.append(new_path)
|
109 |
return renamed_stems
|
110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
def roformer_separator(audio, model_key, seg_size, overlap, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress()):
|
112 |
"""Separate audio using Roformer model."""
|
113 |
model = ROFORMER_MODELS[model_key]
|
|
|
114 |
separator = Separator(
|
115 |
log_level=logging.WARNING,
|
116 |
model_file_dir=model_dir,
|
@@ -138,6 +149,7 @@ def roformer_separator(audio, model_key, seg_size, overlap, model_dir, out_dir,
|
|
138 |
|
139 |
def mdx23c_separator(audio, model, seg_size, overlap, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress()):
|
140 |
"""Separate audio using MDX23C model."""
|
|
|
141 |
separator = Separator(
|
142 |
log_level=logging.WARNING,
|
143 |
model_file_dir=model_dir,
|
@@ -165,6 +177,7 @@ def mdx23c_separator(audio, model, seg_size, overlap, model_dir, out_dir, out_fo
|
|
165 |
|
166 |
def mdx_separator(audio, model, hop_length, seg_size, overlap, denoise, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress()):
|
167 |
"""Separate audio using MDX-NET model."""
|
|
|
168 |
separator = Separator(
|
169 |
log_level=logging.WARNING,
|
170 |
model_file_dir=model_dir,
|
@@ -194,6 +207,7 @@ def mdx_separator(audio, model, hop_length, seg_size, overlap, denoise, model_di
|
|
194 |
|
195 |
def vr_separator(audio, model, window_size, aggression, tta, post_process, post_process_threshold, high_end_process, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress()):
|
196 |
"""Separate audio using VR ARCH model."""
|
|
|
197 |
separator = Separator(
|
198 |
log_level=logging.WARNING,
|
199 |
model_file_dir=model_dir,
|
@@ -225,6 +239,7 @@ def vr_separator(audio, model, window_size, aggression, tta, post_process, post_
|
|
225 |
|
226 |
def demucs_separator(audio, model, seg_size, shifts, overlap, segments_enabled, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress()):
|
227 |
"""Separate audio using Demucs model."""
|
|
|
228 |
separator = Separator(
|
229 |
log_level=logging.WARNING,
|
230 |
model_file_dir=model_dir,
|
@@ -267,7 +282,7 @@ with gr.Blocks(
|
|
267 |
with gr.Group():
|
268 |
model_file_dir = gr.Textbox(value="/tmp/audio-separator-models/", label="Directory for storing model files", placeholder="/tmp/audio-separator-models/", interactive=False)
|
269 |
with gr.Row():
|
270 |
-
output_dir = gr.Textbox(value="output", label="File output directory", placeholder="output", interactive=
|
271 |
output_format = gr.Dropdown(value="wav", choices=["wav", "flac", "mp3"], label="Output Format")
|
272 |
with gr.Row():
|
273 |
norm_threshold = gr.Slider(value=0.9, step=0.1, minimum=0, maximum=1, label="Normalization", info="max peak amplitude to normalize input and output audio.")
|
|
|
1 |
import os
|
2 |
+
import shutil
|
3 |
import logging
|
4 |
import gradio as gr
|
5 |
|
|
|
109 |
renamed_stems.append(new_path)
|
110 |
return renamed_stems
|
111 |
|
112 |
+
def prepare_output_dir(input_file, output_dir):
|
113 |
+
"""Create a directory for the output files and clean it if it already exists."""
|
114 |
+
base_name = os.path.splitext(os.path.basename(input_file))[0]
|
115 |
+
out_dir = os.path.join(output_dir, base_name)
|
116 |
+
if os.path.exists(out_dir):
|
117 |
+
shutil.rmtree(out_dir)
|
118 |
+
os.makedirs(out_dir)
|
119 |
+
return out_dir
|
120 |
+
|
121 |
def roformer_separator(audio, model_key, seg_size, overlap, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress()):
|
122 |
"""Separate audio using Roformer model."""
|
123 |
model = ROFORMER_MODELS[model_key]
|
124 |
+
out_dir = prepare_output_dir(audio, out_dir)
|
125 |
separator = Separator(
|
126 |
log_level=logging.WARNING,
|
127 |
model_file_dir=model_dir,
|
|
|
149 |
|
150 |
def mdx23c_separator(audio, model, seg_size, overlap, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress()):
|
151 |
"""Separate audio using MDX23C model."""
|
152 |
+
out_dir = prepare_output_dir(audio, out_dir)
|
153 |
separator = Separator(
|
154 |
log_level=logging.WARNING,
|
155 |
model_file_dir=model_dir,
|
|
|
177 |
|
178 |
def mdx_separator(audio, model, hop_length, seg_size, overlap, denoise, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress()):
|
179 |
"""Separate audio using MDX-NET model."""
|
180 |
+
out_dir = prepare_output_dir(audio, out_dir)
|
181 |
separator = Separator(
|
182 |
log_level=logging.WARNING,
|
183 |
model_file_dir=model_dir,
|
|
|
207 |
|
208 |
def vr_separator(audio, model, window_size, aggression, tta, post_process, post_process_threshold, high_end_process, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress()):
|
209 |
"""Separate audio using VR ARCH model."""
|
210 |
+
out_dir = prepare_output_dir(audio, out_dir)
|
211 |
separator = Separator(
|
212 |
log_level=logging.WARNING,
|
213 |
model_file_dir=model_dir,
|
|
|
239 |
|
240 |
def demucs_separator(audio, model, seg_size, shifts, overlap, segments_enabled, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress()):
|
241 |
"""Separate audio using Demucs model."""
|
242 |
+
out_dir = prepare_output_dir(audio, out_dir)
|
243 |
separator = Separator(
|
244 |
log_level=logging.WARNING,
|
245 |
model_file_dir=model_dir,
|
|
|
282 |
with gr.Group():
|
283 |
model_file_dir = gr.Textbox(value="/tmp/audio-separator-models/", label="Directory for storing model files", placeholder="/tmp/audio-separator-models/", interactive=False)
|
284 |
with gr.Row():
|
285 |
+
output_dir = gr.Textbox(value="output", label="File output directory", placeholder="output", interactive=False)
|
286 |
output_format = gr.Dropdown(value="wav", choices=["wav", "flac", "mp3"], label="Output Format")
|
287 |
with gr.Row():
|
288 |
norm_threshold = gr.Slider(value=0.9, step=0.1, minimum=0, maximum=1, label="Normalization", info="max peak amplitude to normalize input and output audio.")
|