Politrees commited on
Commit
00daee1
·
verified ·
1 Parent(s): 1fa8947

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -20
app.py CHANGED
@@ -98,6 +98,17 @@ DEMUCS_MODELS = [
98
  'hdemucs_mmi.yaml',
99
  ]
100
 
 
 
 
 
 
 
 
 
 
 
 
101
  def print_message(input_file, model_name):
102
  """Prints information about the audio separation process."""
103
  base_name = os.path.splitext(os.path.basename(input_file))[0]
@@ -135,7 +146,7 @@ def prepare_output_dir(input_file, output_dir):
135
  raise
136
  return out_dir
137
 
138
- def roformer_separator(audio, model_key, seg_size, override_seg_size, overlap, pitch_shift, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress(track_tqdm=True)):
139
  """Separate audio using Roformer model."""
140
  print_message(audio, model_key)
141
  model = ROFORMER_MODELS[model_key]
@@ -157,13 +168,13 @@ def roformer_separator(audio, model_key, seg_size, override_seg_size, overlap, p
157
  }
158
  )
159
 
160
- progress(0.2, desc="Model loaded")
161
  separator.load_model(model_filename=model)
162
 
163
- progress(0.7, desc="Audio separated")
164
  separation = separator.separate(audio)
165
 
166
- progress(0.9, desc="Stems renamed")
167
  stems = rename_stems(audio, out_dir, separation, out_format)
168
 
169
  return stems[0], stems[1]
@@ -171,7 +182,7 @@ def roformer_separator(audio, model_key, seg_size, override_seg_size, overlap, p
171
  logging.error(f"Roformer separation failed: {e}")
172
  return None, None
173
 
174
- def mdx23c_separator(audio, model, seg_size, override_seg_size, overlap, pitch_shift, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress(track_tqdm=True)):
175
  """Separate audio using MDX23C model."""
176
  print_message(audio, model)
177
  try:
@@ -192,13 +203,13 @@ def mdx23c_separator(audio, model, seg_size, override_seg_size, overlap, pitch_s
192
  }
193
  )
194
 
195
- progress(0.2, desc="Model loaded")
196
  separator.load_model(model_filename=model)
197
 
198
- progress(0.7, desc="Audio separated")
199
  separation = separator.separate(audio)
200
 
201
- progress(0.9, desc="Stems renamed")
202
  stems = rename_stems(audio, out_dir, separation, out_format)
203
 
204
  return stems[0], stems[1]
@@ -206,7 +217,7 @@ def mdx23c_separator(audio, model, seg_size, override_seg_size, overlap, pitch_s
206
  logging.error(f"MDX23C separation failed: {e}")
207
  return None, None
208
 
209
- def mdx_separator(audio, model, hop_length, seg_size, overlap, denoise, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress(track_tqdm=True)):
210
  """Separate audio using MDX-NET model."""
211
  print_message(audio, model)
212
  try:
@@ -227,13 +238,13 @@ def mdx_separator(audio, model, hop_length, seg_size, overlap, denoise, model_di
227
  }
228
  )
229
 
230
- progress(0.2, desc="Model loaded")
231
  separator.load_model(model_filename=model)
232
 
233
- progress(0.7, desc="Audio separated")
234
  separation = separator.separate(audio)
235
 
236
- progress(0.9, desc="Stems renamed")
237
  stems = rename_stems(audio, out_dir, separation, out_format)
238
 
239
  return stems[0], stems[1]
@@ -241,7 +252,7 @@ def mdx_separator(audio, model, hop_length, seg_size, overlap, denoise, model_di
241
  logging.error(f"MDX-NET separation failed: {e}")
242
  return None, None
243
 
244
- 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(track_tqdm=True)):
245
  """Separate audio using VR ARCH model."""
246
  print_message(audio, model)
247
  try:
@@ -264,13 +275,13 @@ def vr_separator(audio, model, window_size, aggression, tta, post_process, post_
264
  }
265
  )
266
 
267
- progress(0.2, desc="Model loaded")
268
  separator.load_model(model_filename=model)
269
 
270
- progress(0.7, desc="Audio separated")
271
  separation = separator.separate(audio)
272
 
273
- progress(0.9, desc="Stems renamed")
274
  stems = rename_stems(audio, out_dir, separation, out_format)
275
 
276
  return stems[0], stems[1]
@@ -278,7 +289,7 @@ def vr_separator(audio, model, window_size, aggression, tta, post_process, post_
278
  logging.error(f"VR ARCH separation failed: {e}")
279
  return None, None
280
 
281
- def demucs_separator(audio, model, seg_size, shifts, overlap, segments_enabled, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=gr.Progress(track_tqdm=True)):
282
  """Separate audio using Demucs model."""
283
  print_message(audio, model)
284
  try:
@@ -298,13 +309,13 @@ def demucs_separator(audio, model, seg_size, shifts, overlap, segments_enabled,
298
  }
299
  )
300
 
301
- progress(0.2, desc="Model loaded")
302
  separator.load_model(model_filename=model)
303
 
304
- progress(0.7, desc="Audio separated")
305
  separation = separator.separate(audio)
306
 
307
- progress(0.9, desc="Stems renamed")
308
  stems = rename_stems(audio, out_dir, separation, out_format)
309
 
310
  return stems[0], stems[1], stems[2], stems[3]
 
98
  'hdemucs_mmi.yaml',
99
  ]
100
 
101
+ class CustomProgressBar:
102
+ def __init__(self, total=1.0):
103
+ self.total = total
104
+ self.current = 0.0
105
+ self.desc = ""
106
+
107
+ def update(self, value, desc):
108
+ self.current = value
109
+ self.desc = desc
110
+ print(f"Progress: {self.current * 100:.2f}% - {self.desc}")
111
+
112
  def print_message(input_file, model_name):
113
  """Prints information about the audio separation process."""
114
  base_name = os.path.splitext(os.path.basename(input_file))[0]
 
146
  raise
147
  return out_dir
148
 
149
+ def roformer_separator(audio, model_key, seg_size, override_seg_size, overlap, pitch_shift, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=CustomProgressBar()):
150
  """Separate audio using Roformer model."""
151
  print_message(audio, model_key)
152
  model = ROFORMER_MODELS[model_key]
 
168
  }
169
  )
170
 
171
+ progress.update(0.2, "Model loaded")
172
  separator.load_model(model_filename=model)
173
 
174
+ progress.update(0.7, "Audio separated")
175
  separation = separator.separate(audio)
176
 
177
+ progress.update(0.9, "Stems renamed")
178
  stems = rename_stems(audio, out_dir, separation, out_format)
179
 
180
  return stems[0], stems[1]
 
182
  logging.error(f"Roformer separation failed: {e}")
183
  return None, None
184
 
185
+ def mdx23c_separator(audio, model, seg_size, override_seg_size, overlap, pitch_shift, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=CustomProgressBar()):
186
  """Separate audio using MDX23C model."""
187
  print_message(audio, model)
188
  try:
 
203
  }
204
  )
205
 
206
+ progress.update(0.2, "Model loaded")
207
  separator.load_model(model_filename=model)
208
 
209
+ progress.update(0.7, "Audio separated")
210
  separation = separator.separate(audio)
211
 
212
+ progress.update(0.9, "Stems renamed")
213
  stems = rename_stems(audio, out_dir, separation, out_format)
214
 
215
  return stems[0], stems[1]
 
217
  logging.error(f"MDX23C separation failed: {e}")
218
  return None, None
219
 
220
+ def mdx_separator(audio, model, hop_length, seg_size, overlap, denoise, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=CustomProgressBar()):
221
  """Separate audio using MDX-NET model."""
222
  print_message(audio, model)
223
  try:
 
238
  }
239
  )
240
 
241
+ progress.update(0.2, "Model loaded")
242
  separator.load_model(model_filename=model)
243
 
244
+ progress.update(0.7, "Audio separated")
245
  separation = separator.separate(audio)
246
 
247
+ progress.update(0.9, "Stems renamed")
248
  stems = rename_stems(audio, out_dir, separation, out_format)
249
 
250
  return stems[0], stems[1]
 
252
  logging.error(f"MDX-NET separation failed: {e}")
253
  return None, None
254
 
255
+ 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=CustomProgressBar()):
256
  """Separate audio using VR ARCH model."""
257
  print_message(audio, model)
258
  try:
 
275
  }
276
  )
277
 
278
+ progress.update(0.2, "Model loaded")
279
  separator.load_model(model_filename=model)
280
 
281
+ progress.update(0.7, "Audio separated")
282
  separation = separator.separate(audio)
283
 
284
+ progress.update(0.9, "Stems renamed")
285
  stems = rename_stems(audio, out_dir, separation, out_format)
286
 
287
  return stems[0], stems[1]
 
289
  logging.error(f"VR ARCH separation failed: {e}")
290
  return None, None
291
 
292
+ def demucs_separator(audio, model, seg_size, shifts, overlap, segments_enabled, model_dir, out_dir, out_format, norm_thresh, amp_thresh, progress=CustomProgressBar()):
293
  """Separate audio using Demucs model."""
294
  print_message(audio, model)
295
  try:
 
309
  }
310
  )
311
 
312
+ progress.update(0.2, "Model loaded")
313
  separator.load_model(model_filename=model)
314
 
315
+ progress.update(0.7, "Audio separated")
316
  separation = separator.separate(audio)
317
 
318
+ progress.update(0.9, "Stems renamed")
319
  stems = rename_stems(audio, out_dir, separation, out_format)
320
 
321
  return stems[0], stems[1], stems[2], stems[3]