Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import os
|
| 3 |
-
import random
|
| 4 |
-
import subprocess
|
| 5 |
-
|
| 6 |
-
def separate_audio(audio_path, stem_count):
|
| 7 |
-
print(f"{audio_path=}")
|
| 8 |
-
head, tail = os.path.split(audio_path)
|
| 9 |
-
|
| 10 |
-
gradio_temp_path = head
|
| 11 |
-
audio_filename = tail.split('.')[0]
|
| 12 |
-
print(f"{gradio_temp_path=}")
|
| 13 |
-
print(f"{audio_filename=}")
|
| 14 |
-
print(f"{stem_count=}")
|
| 15 |
-
|
| 16 |
-
command = f"spleeter separate -p spleeter:{stem_count}stems {audio_path}"
|
| 17 |
-
command = command.split()
|
| 18 |
-
print(f"{command=}")
|
| 19 |
-
|
| 20 |
-
result = subprocess.run(command)
|
| 21 |
-
print(result)
|
| 22 |
-
randomnumber = str(random.randint(111111111, 999999999))
|
| 23 |
-
paths = []
|
| 24 |
-
if stem_count == 2:
|
| 25 |
-
paths.append(('Accompaniment', f"{gradio_temp_path}/separated_audio/{randomnumber}/accompaniment.wav"))
|
| 26 |
-
paths.append(('Vocals', f"{gradio_temp_path}/separated_audio/{randomnumber}/vocals.wav"))
|
| 27 |
-
elif stem_count == 4 or stem_count == 5:
|
| 28 |
-
paths.append(('Vocals', f"{gradio_temp_path}/separated_audio/{randomnumber}/vocals.wav"))
|
| 29 |
-
paths.append(('Drums', f"{gradio_temp_path}/separated_audio/{randomnumber}/drums.wav"))
|
| 30 |
-
paths.append(('Bass', f"{gradio_temp_path}/separated_audio/{randomnumber}/bass.wav"))
|
| 31 |
-
paths.append(('Other', f"{gradio_temp_path}/separated_audio/{randomnumber}/other.wav"))
|
| 32 |
-
if stem_count == 5:
|
| 33 |
-
paths.append(('Piano', f"{gradio_temp_path}/separated_audio/{randomnumber}/piano.wav"))
|
| 34 |
-
|
| 35 |
-
audio_outputs = []
|
| 36 |
-
for label, filepath in paths:
|
| 37 |
-
audio_outputs.append(gr.outputs.Audio(filepath, label=label))
|
| 38 |
-
return audio_outputs
|
| 39 |
-
|
| 40 |
-
iface = gr.Interface(
|
| 41 |
-
fn=separate_audio,
|
| 42 |
-
inputs=[gr.Audio(type="filepath"), gr.Radio([2, 4, 5], label="Number of Stems")],
|
| 43 |
-
outputs="text", # Changed to "text" temporarily for testing
|
| 44 |
-
)
|
| 45 |
-
|
| 46 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|