Politrees commited on
Commit
61615af
·
verified ·
1 Parent(s): 47d46a5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +122 -128
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import os
2
- import tempfile
3
  import gradio as gr
4
 
5
  from audio_separator.separator import Separator
@@ -111,145 +110,140 @@ def rename_stems(input_file, output_dir, stems, output_format):
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
- with tempfile.TemporaryDirectory() as tmp_dir:
115
- separator = Separator(
116
- model_file_dir=model_dir,
117
- output_dir=tmp_dir,
118
- output_format=out_format,
119
- normalization_threshold=norm_thresh,
120
- amplification_threshold=amp_thresh,
121
- mdxc_params={
122
- "batch_size": 1,
123
- "segment_size": seg_size,
124
- "overlap": overlap,
125
- }
126
- )
127
-
128
- progress(0.2, desc="Model loaded")
129
- separator.load_model(model_filename=model)
130
-
131
- progress(0.7, desc="Audio separated")
132
- separation = separator.separate(audio)
133
-
134
- progress(0.9, desc="Stems renamed")
135
- stems = rename_stems(audio, out_dir, separation, out_format)
136
-
137
- return stems[0], stems[1]
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
- with tempfile.TemporaryDirectory() as tmp_dir:
142
- separator = Separator(
143
- model_file_dir=model_dir,
144
- output_dir=tmp_dir,
145
- output_format=out_format,
146
- normalization_threshold=norm_thresh,
147
- amplification_threshold=amp_thresh,
148
- mdxc_params={
149
- "batch_size": 1,
150
- "segment_size": seg_size,
151
- "overlap": overlap,
152
- }
153
- )
154
-
155
- progress(0.2, desc="Model loaded")
156
- separator.load_model(model_filename=model)
157
-
158
- progress(0.7, desc="Audio separated")
159
- separation = separator.separate(audio)
160
-
161
- progress(0.9, desc="Stems renamed")
162
- stems = rename_stems(audio, out_dir, separation, out_format)
163
-
164
- return stems[0], stems[1]
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
- with tempfile.TemporaryDirectory() as tmp_dir:
169
- separator = Separator(
170
- model_file_dir=model_dir,
171
- output_dir=tmp_dir,
172
- output_format=out_format,
173
- normalization_threshold=norm_thresh,
174
- amplification_threshold=amp_thresh,
175
- mdx_params={
176
- "batch_size": 1,
177
- "hop_length": hop_length,
178
- "segment_size": seg_size,
179
- "overlap": overlap,
180
- "enable_denoise": denoise,
181
- }
182
- )
183
-
184
- progress(0.2, desc="Model loaded")
185
- separator.load_model(model_filename=model)
186
-
187
- progress(0.7, desc="Audio separated")
188
- separation = separator.separate(audio)
189
-
190
- progress(0.9, desc="Stems renamed")
191
- stems = rename_stems(audio, out_dir, separation, out_format)
192
-
193
- return stems[0], stems[1]
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
- with tempfile.TemporaryDirectory() as tmp_dir:
198
- separator = Separator(
199
- model_file_dir=model_dir,
200
- output_dir=tmp_dir,
201
- output_format=out_format,
202
- normalization_threshold=norm_thresh,
203
- amplification_threshold=amp_thresh,
204
- vr_params={
205
- "batch_size": 1,
206
- "window_size": window_size,
207
- "aggression": aggression,
208
- "enable_tta": tta,
209
- "enable_post_process": post_process,
210
- "post_process_threshold": post_process_threshold,
211
- "high_end_process": high_end_process,
212
- }
213
- )
214
-
215
- progress(0.2, desc="Model loaded")
216
- separator.load_model(model_filename=model)
217
-
218
- progress(0.7, desc="Audio separated")
219
- separation = separator.separate(audio)
220
-
221
- progress(0.9, desc="Stems renamed")
222
- stems = rename_stems(audio, out_dir, separation, out_format)
223
-
224
- return stems[0], stems[1]
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
- with tempfile.TemporaryDirectory() as tmp_dir:
229
- separator = Separator(
230
- model_file_dir=model_dir,
231
- output_dir=tmp_dir,
232
- output_format=out_format,
233
- normalization_threshold=norm_thresh,
234
- amplification_threshold=amp_thresh,
235
- demucs_params={
236
- "segment_size": seg_size,
237
- "shifts": shifts,
238
- "overlap": overlap,
239
- "segments_enabled": segments_enabled,
240
- }
241
- )
242
-
243
- progress(0.2, desc="Model loaded")
244
- separator.load_model(model_filename=model)
245
-
246
- progress(0.7, desc="Audio separated")
247
- separation = separator.separate(audio)
248
-
249
- progress(0.9, desc="Stems renamed")
250
- stems = rename_stems(audio, out_dir, separation, out_format)
251
-
252
- return stems[0], stems[1], stems[2], stems[3]
253
 
254
  with gr.Blocks(title="🎵 PolUVR - Politrees 🎵", css="footer{display:none !important}") as app:
255
  gr.Markdown("<h1> Audio-Separator by Politrees </h1>")
 
1
  import os
 
2
  import gradio as gr
3
 
4
  from audio_separator.separator import Separator
 
110
  def roformer_separator(audio, model_key, seg_size, overlap, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress()):
111
  """Separate audio using Roformer model."""
112
  model = ROFORMER_MODELS[model_key]
113
+ separator = Separator(
114
+ model_file_dir=model_dir,
115
+ output_dir=out_dir,
116
+ output_format=out_format,
117
+ normalization_threshold=norm_thresh,
118
+ amplification_threshold=amp_thresh,
119
+ mdxc_params={
120
+ "batch_size": 1,
121
+ "segment_size": seg_size,
122
+ "overlap": overlap,
123
+ }
124
+ )
125
+
126
+ progress(0.2, desc="Model loaded")
127
+ separator.load_model(model_filename=model)
128
+
129
+ progress(0.7, desc="Audio separated")
130
+ separation = separator.separate(audio)
131
+
132
+ progress(0.9, desc="Stems renamed")
133
+ stems = rename_stems(audio, out_dir, separation, out_format)
134
+
135
+ return stems[0], stems[1]
 
136
 
137
  def mdx23c_separator(audio, model, seg_size, overlap, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress()):
138
  """Separate audio using MDX23C model."""
139
+ separator = Separator(
140
+ model_file_dir=model_dir,
141
+ output_dir=out_dir,
142
+ output_format=out_format,
143
+ normalization_threshold=norm_thresh,
144
+ amplification_threshold=amp_thresh,
145
+ mdxc_params={
146
+ "batch_size": 1,
147
+ "segment_size": seg_size,
148
+ "overlap": overlap,
149
+ }
150
+ )
151
+
152
+ progress(0.2, desc="Model loaded")
153
+ separator.load_model(model_filename=model)
154
+
155
+ progress(0.7, desc="Audio separated")
156
+ separation = separator.separate(audio)
157
+
158
+ progress(0.9, desc="Stems renamed")
159
+ stems = rename_stems(audio, out_dir, separation, out_format)
160
+
161
+ return stems[0], stems[1]
 
162
 
163
  def mdx_separator(audio, model, hop_length, seg_size, overlap, denoise, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress()):
164
  """Separate audio using MDX-NET model."""
165
+ separator = Separator(
166
+ model_file_dir=model_dir,
167
+ output_dir=out_dir,
168
+ output_format=out_format,
169
+ normalization_threshold=norm_thresh,
170
+ amplification_threshold=amp_thresh,
171
+ mdx_params={
172
+ "batch_size": 1,
173
+ "hop_length": hop_length,
174
+ "segment_size": seg_size,
175
+ "overlap": overlap,
176
+ "enable_denoise": denoise,
177
+ }
178
+ )
179
+
180
+ progress(0.2, desc="Model loaded")
181
+ separator.load_model(model_filename=model)
182
+
183
+ progress(0.7, desc="Audio separated")
184
+ separation = separator.separate(audio)
185
+
186
+ progress(0.9, desc="Stems renamed")
187
+ stems = rename_stems(audio, out_dir, separation, out_format)
188
+
189
+ return stems[0], stems[1]
 
190
 
191
  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()):
192
  """Separate audio using VR ARCH model."""
193
+ separator = Separator(
194
+ model_file_dir=model_dir,
195
+ output_dir=out_dir,
196
+ output_format=out_format,
197
+ normalization_threshold=norm_thresh,
198
+ amplification_threshold=amp_thresh,
199
+ vr_params={
200
+ "batch_size": 1,
201
+ "window_size": window_size,
202
+ "aggression": aggression,
203
+ "enable_tta": tta,
204
+ "enable_post_process": post_process,
205
+ "post_process_threshold": post_process_threshold,
206
+ "high_end_process": high_end_process,
207
+ }
208
+ )
209
+
210
+ progress(0.2, desc="Model loaded")
211
+ separator.load_model(model_filename=model)
212
+
213
+ progress(0.7, desc="Audio separated")
214
+ separation = separator.separate(audio)
215
+
216
+ progress(0.9, desc="Stems renamed")
217
+ stems = rename_stems(audio, out_dir, separation, out_format)
218
+
219
+ return stems[0], stems[1]
 
220
 
221
  def demucs_separator(audio, model, seg_size, shifts, overlap, segments_enabled, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress()):
222
  """Separate audio using Demucs model."""
223
+ separator = Separator(
224
+ model_file_dir=model_dir,
225
+ output_dir=out_dir,
226
+ output_format=out_format,
227
+ normalization_threshold=norm_thresh,
228
+ amplification_threshold=amp_thresh,
229
+ demucs_params={
230
+ "segment_size": seg_size,
231
+ "shifts": shifts,
232
+ "overlap": overlap,
233
+ "segments_enabled": segments_enabled,
234
+ }
235
+ )
236
+
237
+ progress(0.2, desc="Model loaded")
238
+ separator.load_model(model_filename=model)
239
+
240
+ progress(0.7, desc="Audio separated")
241
+ separation = separator.separate(audio)
242
+
243
+ progress(0.9, desc="Stems renamed")
244
+ stems = rename_stems(audio, out_dir, separation, out_format)
245
+
246
+ return stems[0], stems[1], stems[2], stems[3]
 
247
 
248
  with gr.Blocks(title="🎵 PolUVR - Politrees 🎵", css="footer{display:none !important}") as app:
249
  gr.Markdown("<h1> Audio-Separator by Politrees </h1>")