Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,33 +13,33 @@ def separate_audio(audio_path, stem_count):
|
|
| 13 |
print(f"{audio_filename=}")
|
| 14 |
print(f"{stem_count=}")
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
command = command.split()
|
| 18 |
print(f"{command=}")
|
| 19 |
|
| 20 |
result = subprocess.run(command, capture_output=True)
|
| 21 |
print(result)
|
| 22 |
if result.returncode != 0:
|
| 23 |
-
print(f"Error: {result.stderr}")
|
| 24 |
return []
|
| 25 |
|
| 26 |
-
|
| 27 |
-
output_folder = f"{gradio_temp_path}/separated_audio/{randomnumber}"
|
| 28 |
-
os.makedirs(output_folder, exist_ok=True) # Ensure the output directory exists
|
| 29 |
-
|
| 30 |
paths = []
|
| 31 |
stems = ['vocals', 'drums', 'bass', 'other', 'piano']
|
| 32 |
-
for
|
| 33 |
-
stem_path = os.path.join(output_folder, f"{stem}.wav")
|
|
|
|
| 34 |
if os.path.exists(stem_path):
|
| 35 |
-
paths.append((stem.capitalize()
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
audio_outputs = []
|
| 39 |
-
for label, path in paths:
|
| 40 |
-
audio_outputs.append(gr.Audio(file=path, label=label))
|
| 41 |
|
| 42 |
-
return
|
| 43 |
|
| 44 |
iface = gr.Interface(
|
| 45 |
fn=separate_audio,
|
|
|
|
| 13 |
print(f"{audio_filename=}")
|
| 14 |
print(f"{stem_count=}")
|
| 15 |
|
| 16 |
+
# Ensure the output directory exists
|
| 17 |
+
randomnumber = str(random.randint(111111111, 999999999))
|
| 18 |
+
output_folder = f"{gradio_temp_path}/separated_audio/{randomnumber}"
|
| 19 |
+
os.makedirs(output_folder, exist_ok=True)
|
| 20 |
+
|
| 21 |
+
command = f"spleeter separate -p spleeter:{stem_count}stems -o {output_folder} {audio_path}"
|
| 22 |
command = command.split()
|
| 23 |
print(f"{command=}")
|
| 24 |
|
| 25 |
result = subprocess.run(command, capture_output=True)
|
| 26 |
print(result)
|
| 27 |
if result.returncode != 0:
|
| 28 |
+
print(f"Error: {result.stderr.decode('utf-8')}")
|
| 29 |
return []
|
| 30 |
|
| 31 |
+
# Check if the separated files exist and return their paths
|
|
|
|
|
|
|
|
|
|
| 32 |
paths = []
|
| 33 |
stems = ['vocals', 'drums', 'bass', 'other', 'piano']
|
| 34 |
+
for stem in stems[:stem_count]:
|
| 35 |
+
stem_path = os.path.join(output_folder, stem, f"{audio_filename}_{stem}.wav")
|
| 36 |
+
print(f"Checking {stem_path}")
|
| 37 |
if os.path.exists(stem_path):
|
| 38 |
+
paths.append(gr.Audio(file=stem_path, label=stem.capitalize()))
|
| 39 |
+
else:
|
| 40 |
+
print(f"File not found: {stem_path}")
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
+
return paths
|
| 43 |
|
| 44 |
iface = gr.Interface(
|
| 45 |
fn=separate_audio,
|