Spaces:
Sleeping
Sleeping
amirgame197
commited on
Commit
•
b8e4d8f
1
Parent(s):
75e3471
Update app.py
Browse files
app.py
CHANGED
@@ -13,24 +13,35 @@ 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 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
randomnumber = str(random.randint(111111111, 999999999))
|
23 |
paths = []
|
|
|
24 |
if stem_count == 2:
|
25 |
-
paths.append(gradio_temp_path
|
26 |
-
paths.append(gradio_temp_path
|
27 |
elif stem_count == 4 or stem_count == 5:
|
28 |
-
paths.append(gradio_temp_path
|
29 |
-
paths.append(gradio_temp_path
|
30 |
-
paths.append(gradio_temp_path
|
31 |
-
paths.append(gradio_temp_path
|
32 |
if stem_count == 5:
|
33 |
-
paths.append(gradio_temp_path
|
34 |
|
35 |
# Return the audio file paths as a list of Audio components
|
36 |
return [gr.Audio(path) for path in paths]
|
@@ -39,7 +50,7 @@ def separate_audio(audio_path, stem_count):
|
|
39 |
iface = gr.Interface(
|
40 |
fn=separate_audio,
|
41 |
inputs=[gr.Audio(type="filepath"), gr.Radio([2, 4, 5])],
|
42 |
-
outputs=[gr.Audio(
|
43 |
)
|
44 |
|
45 |
# Launch the interface
|
|
|
13 |
print(f"{audio_filename=}")
|
14 |
print(f"{stem_count=}")
|
15 |
|
16 |
+
# Construct the spleeter command
|
17 |
+
command = f"spleeter separate -p spleeter:{stem_count}stems -o {gradio_temp_path} {audio_path}"
|
18 |
command = command.split()
|
19 |
print(f"{command=}")
|
20 |
|
21 |
+
# Run the spleeter command and capture the output
|
22 |
+
result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
23 |
+
print(f"stdout: {result.stdout.decode('utf-8')}")
|
24 |
+
print(f"stderr: {result.stderr.decode('utf-8')}")
|
25 |
+
|
26 |
+
# Check if the command executed successfully
|
27 |
+
if result.returncode != 0:
|
28 |
+
print(f"Error executing command: {result.returncode}")
|
29 |
+
return []
|
30 |
+
|
31 |
+
# Generate a random number for unique folder naming
|
32 |
randomnumber = str(random.randint(111111111, 999999999))
|
33 |
paths = []
|
34 |
+
# Define the output paths for the separated stems
|
35 |
if stem_count == 2:
|
36 |
+
paths.append(os.path.join(gradio_temp_path, f"separated_audio/{audio_filename}/accompaniment.wav"))
|
37 |
+
paths.append(os.path.join(gradio_temp_path, f"separated_audio/{audio_filename}/vocals.wav"))
|
38 |
elif stem_count == 4 or stem_count == 5:
|
39 |
+
paths.append(os.path.join(gradio_temp_path, f"separated_audio/{audio_filename}/vocals.wav"))
|
40 |
+
paths.append(os.path.join(gradio_temp_path, f"separated_audio/{audio_filename}/drums.wav"))
|
41 |
+
paths.append(os.path.join(gradio_temp_path, f"separated_audio/{audio_filename}/bass.wav"))
|
42 |
+
paths.append(os.path.join(gradio_temp_path, f"separated_audio/{audio_filename}/other.wav"))
|
43 |
if stem_count == 5:
|
44 |
+
paths.append(os.path.join(gradio_temp_path, f"separated_audio/{audio_filename}/piano.wav"))
|
45 |
|
46 |
# Return the audio file paths as a list of Audio components
|
47 |
return [gr.Audio(path) for path in paths]
|
|
|
50 |
iface = gr.Interface(
|
51 |
fn=separate_audio,
|
52 |
inputs=[gr.Audio(type="filepath"), gr.Radio([2, 4, 5])],
|
53 |
+
outputs=[gr.Audio() for _ in range(max_stem_count)] # Adjust the range according to the max number of stems
|
54 |
)
|
55 |
|
56 |
# Launch the interface
|