Loren commited on
Commit
d092661
Β·
verified Β·
1 Parent(s): d2aef1b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -6
app.py CHANGED
@@ -12,7 +12,7 @@ import os
12
  import re
13
  import glob
14
  import spaces
15
- from scipy.io.wavfile import write
16
 
17
  ### Initializations
18
 
@@ -234,7 +234,7 @@ def clear_audio():
234
  ###
235
 
236
  @spaces.GPU
237
- def voice_extract_demucs(audio):
238
  """
239
  Returns the path of the voice extracted file.
240
  """
@@ -245,12 +245,20 @@ def voice_extract_demucs(audio):
245
  "demucs",
246
  "--two-stems=vocals",
247
  "--out", "out_demucs",
248
- audio
249
  ]
250
  subprocess.run(cmd, check=True)
251
- voice_path = os.path.join(".", "demucs", "htdemucs", "audio_file", "vocals.wav")
252
- success_message = "βœ… **Success!** Voice extracted. ("+voice_path+")"
253
- return voice_path, voice_path, gr.Markdown(success_message)
 
 
 
 
 
 
 
 
254
  except Exception as e:
255
  return None, None, gr.Markdown(f"❌ **Error:** An unexpected ERROR occurred: {e}")
256
  ###
 
12
  import re
13
  import glob
14
  import spaces
15
+ from pathlib import Path
16
 
17
  ### Initializations
18
 
 
234
  ###
235
 
236
  @spaces.GPU
237
+ def voice_extract_demucs(audio_path):
238
  """
239
  Returns the path of the voice extracted file.
240
  """
 
245
  "demucs",
246
  "--two-stems=vocals",
247
  "--out", "out_demucs",
248
+ audio_path
249
  ]
250
  subprocess.run(cmd, check=True)
251
+ base_name = Path(audio_path).stem
252
+ model_dirs = list(Path("out_demucs").glob("*"))
253
+ if not model_dirs:
254
+ vocals_path = audio_path
255
+ success_message = "❌ **Error:** No files found on out_demucs."
256
+ else:
257
+ result_dir = model_dirs[0] / base_name
258
+ vocals_path = result_dir / "vocals.wav"
259
+ success_message = "βœ… **Success!** Voice extracted. ("+vocals_path+")"
260
+
261
+ return vocals_path, vocals_path, gr.Markdown(success_message)
262
  except Exception as e:
263
  return None, None, gr.Markdown(f"❌ **Error:** An unexpected ERROR occurred: {e}")
264
  ###