Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,7 +12,7 @@ import os
|
|
| 12 |
import re
|
| 13 |
import glob
|
| 14 |
import spaces
|
| 15 |
-
from
|
| 16 |
|
| 17 |
### Initializations
|
| 18 |
|
|
@@ -234,7 +234,7 @@ def clear_audio():
|
|
| 234 |
###
|
| 235 |
|
| 236 |
@spaces.GPU
|
| 237 |
-
def voice_extract_demucs(
|
| 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 |
-
|
| 249 |
]
|
| 250 |
subprocess.run(cmd, check=True)
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
###
|