Spaces:
Build error
Build error
cuda or cpu condition
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
from scipy.io.wavfile import write
|
| 4 |
import subprocess
|
|
|
|
| 5 |
|
| 6 |
from audio_separator import Separator # Ensure this is correctly implemented
|
| 7 |
|
|
@@ -9,10 +10,15 @@ def inference(audio):
|
|
| 9 |
os.makedirs("out", exist_ok=True)
|
| 10 |
audio_path = 'test.wav'
|
| 11 |
write(audio_path, audio[0], audio[1])
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
try:
|
|
|
|
| 14 |
# Using subprocess.run for better control
|
| 15 |
-
command = f"python3 -m demucs.separate -n htdemucs_6s -d
|
| 16 |
process = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 17 |
print("Demucs script output:", process.stdout.decode())
|
| 18 |
except subprocess.CalledProcessError as e:
|
|
@@ -21,7 +27,7 @@ def inference(audio):
|
|
| 21 |
|
| 22 |
try:
|
| 23 |
# Separating the stems using your custom separator
|
| 24 |
-
separator = Separator("./out/htdemucs_6s/test/vocals.wav", model_name='UVR_MDXNET_KARA_2', use_cuda=
|
| 25 |
primary_stem_path, secondary_stem_path = separator.separate()
|
| 26 |
except Exception as e:
|
| 27 |
print("Error in custom separation:", str(e))
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from scipy.io.wavfile import write
|
| 4 |
import subprocess
|
| 5 |
+
import torch
|
| 6 |
|
| 7 |
from audio_separator import Separator # Ensure this is correctly implemented
|
| 8 |
|
|
|
|
| 10 |
os.makedirs("out", exist_ok=True)
|
| 11 |
audio_path = 'test.wav'
|
| 12 |
write(audio_path, audio[0], audio[1])
|
| 13 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 14 |
+
if device=='cuda':
|
| 15 |
+
use_cuda=True
|
| 16 |
+
else:
|
| 17 |
+
use_cuda=False
|
| 18 |
try:
|
| 19 |
+
|
| 20 |
# Using subprocess.run for better control
|
| 21 |
+
command = f"python3 -m demucs.separate -n htdemucs_6s -d {device} {audio_path} -o out"
|
| 22 |
process = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 23 |
print("Demucs script output:", process.stdout.decode())
|
| 24 |
except subprocess.CalledProcessError as e:
|
|
|
|
| 27 |
|
| 28 |
try:
|
| 29 |
# Separating the stems using your custom separator
|
| 30 |
+
separator = Separator("./out/htdemucs_6s/test/vocals.wav", model_name='UVR_MDXNET_KARA_2', use_cuda=use_cuda, output_format='mp3')
|
| 31 |
primary_stem_path, secondary_stem_path = separator.separate()
|
| 32 |
except Exception as e:
|
| 33 |
print("Error in custom separation:", str(e))
|