ASesYusuf1 commited on
Commit
aecae1e
·
verified ·
1 Parent(s): 6bc0914

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -1
app.py CHANGED
@@ -369,6 +369,13 @@ def roformer_separator(audio, model_key, seg_size, override_seg_size, overlap, p
369
  if not audio:
370
  raise ValueError("No audio file provided.")
371
 
 
 
 
 
 
 
 
372
  override_seg_size = override_seg_size == "True"
373
 
374
  if os.path.exists(output_dir):
@@ -409,6 +416,10 @@ def roformer_separator(audio, model_key, seg_size, override_seg_size, overlap, p
409
  except Exception as e:
410
  logger.error(f"Separation failed: {e}")
411
  raise RuntimeError(f"Separation failed: {e}")
 
 
 
 
412
 
413
  @spaces.GPU
414
  def auto_ensemble_process(audio, model_keys, seg_size, overlap, out_format, use_tta, model_dir, output_dir, norm_thresh, amp_thresh, batch_size, ensemble_method, exclude_stems="", weights_str="", progress=gr.Progress()):
@@ -416,6 +427,13 @@ def auto_ensemble_process(audio, model_keys, seg_size, overlap, out_format, use_
416
  if not audio or not model_keys:
417
  raise ValueError("Audio or models missing.")
418
 
 
 
 
 
 
 
 
419
  use_tta = use_tta == "True"
420
 
421
  if os.path.exists(output_dir):
@@ -478,7 +496,11 @@ def auto_ensemble_process(audio, model_keys, seg_size, overlap, out_format, use_
478
 
479
  progress(1.0, desc="Ensemble complete")
480
  return output_file, f"Ensemble completed with {ensemble_method}, excluded: {exclude_stems if exclude_stems else 'None'}"
481
-
 
 
 
 
482
  def update_roformer_models(category):
483
  """Update Roformer model dropdown based on selected category."""
484
  choices = list(ROFORMER_MODELS.get(category, {}).keys()) or []
 
369
  if not audio:
370
  raise ValueError("No audio file provided.")
371
 
372
+ # If audio is a tuple (sample_rate, data), save it as a temporary file
373
+ if isinstance(audio, tuple):
374
+ sample_rate, data = audio
375
+ temp_audio_path = os.path.join("/tmp", "temp_audio.wav")
376
+ scipy.io.wavfile.write(temp_audio_path, sample_rate, data)
377
+ audio = temp_audio_path
378
+
379
  override_seg_size = override_seg_size == "True"
380
 
381
  if os.path.exists(output_dir):
 
416
  except Exception as e:
417
  logger.error(f"Separation failed: {e}")
418
  raise RuntimeError(f"Separation failed: {e}")
419
+ finally:
420
+ # Clean up temporary file if created
421
+ if isinstance(audio, tuple) and os.path.exists(temp_audio_path):
422
+ os.remove(temp_audio_path)
423
 
424
  @spaces.GPU
425
  def auto_ensemble_process(audio, model_keys, seg_size, overlap, out_format, use_tta, model_dir, output_dir, norm_thresh, amp_thresh, batch_size, ensemble_method, exclude_stems="", weights_str="", progress=gr.Progress()):
 
427
  if not audio or not model_keys:
428
  raise ValueError("Audio or models missing.")
429
 
430
+ # If audio is a tuple (sample_rate, data), save it as a temporary file
431
+ if isinstance(audio, tuple):
432
+ sample_rate, data = audio
433
+ temp_audio_path = os.path.join("/tmp", "temp_audio.wav")
434
+ scipy.io.wavfile.write(temp_audio_path, sample_rate, data)
435
+ audio = temp_audio_path
436
+
437
  use_tta = use_tta == "True"
438
 
439
  if os.path.exists(output_dir):
 
496
 
497
  progress(1.0, desc="Ensemble complete")
498
  return output_file, f"Ensemble completed with {ensemble_method}, excluded: {exclude_stems if exclude_stems else 'None'}"
499
+ finally:
500
+ # Clean up temporary file if created
501
+ if isinstance(audio, tuple) and os.path.exists(temp_audio_path):
502
+ os.remove(temp_audio_path)
503
+
504
  def update_roformer_models(category):
505
  """Update Roformer model dropdown based on selected category."""
506
  choices = list(ROFORMER_MODELS.get(category, {}).keys()) or []