Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,51 @@
|
|
1 |
-
import os
|
2 |
import gradio as gr
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
-
write('test.wav', audio[0], audio[1])
|
9 |
-
os.system("python3 -m demucs.separate -n htdemucs --two-stems=vocals -d cpu test.wav -o out")
|
10 |
-
return "./out/htdemucs/test/vocals.wav","./out/htdemucs/test/no_vocals.wav"
|
11 |
-
|
12 |
-
title = "Ilaria UVR 💖"
|
13 |
-
description = "Drag and drop an audio file to easily separate it! [Join AI Hub Discord Server](https://discord.gg/aihub).</p>"
|
14 |
-
article = "Made with 💖 by Ilaria"
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
examples=[['test.mp3']]
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
title=title,
|
22 |
description=description,
|
23 |
article=article,
|
24 |
examples=examples
|
25 |
-
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
+
|
4 |
+
def inference(input_file_path,model_name):
|
5 |
+
if model_name == "":
|
6 |
+
model_name = "htdemucs"
|
7 |
+
# Make sure the output directory exists
|
8 |
+
temp_dir = os.path.dirname(input_file_path)
|
9 |
+
temp_out_dir = os.path.join(temp_dir, 'out')
|
10 |
+
os.makedirs(f'{temp_out_dir}', exist_ok=True)
|
11 |
+
|
12 |
|
13 |
+
print(input_file_path)
|
14 |
+
# Define the output file paths
|
15 |
+
filename = os.path.basename(input_file_path).split('.')[0]
|
16 |
|
17 |
+
vocals_out = os.path.join(temp_out_dir, model_name,filename,"vocals.mp3")
|
18 |
+
no_vocals_out = os.path.join(temp_out_dir, model_name,filename,"no_vocals.mp3")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
+
cmd = f'python -m demucs.separate -n {model_name} --mp3 --two-stems vocals -o {temp_out_dir} "{input_file_path}"'
|
21 |
+
print(cmd)
|
22 |
+
os.system(cmd)
|
23 |
+
|
24 |
+
print("process finish:",vocals_out,no_vocals_out)
|
25 |
+
# Return the paths of the output files
|
26 |
+
return vocals_out, no_vocals_out
|
27 |
+
|
28 |
+
title = "Facebook UVR Test"
|
29 |
+
description = "Seperate vocals and music using UVR"
|
30 |
+
article = "Made by line"
|
31 |
examples=[['test.mp3']]
|
32 |
+
# Create a Gradio interface
|
33 |
+
|
34 |
+
demo = gr.Interface(
|
35 |
+
fn=inference,
|
36 |
+
inputs=[
|
37 |
+
gr.Audio(type="filepath", label="Input Audio"),
|
38 |
+
gr.Dropdown(["htdemucs", "htdemucs_ft", "htdemucs_6s", "piano"], label="Model Name")
|
39 |
+
],
|
40 |
+
outputs=[
|
41 |
+
gr.Audio(type="filepath", label="Vocals out"),
|
42 |
+
gr.Audio(type="filepath", label="Music out"),
|
43 |
+
],
|
44 |
title=title,
|
45 |
description=description,
|
46 |
article=article,
|
47 |
examples=examples
|
48 |
+
)
|
49 |
+
|
50 |
+
if __name__ == "__main__":
|
51 |
+
demo.launch()
|