Spaces:
Runtime error
Runtime error
Daryl Fung
commited on
Commit
•
98fdba8
0
Parent(s):
added spleeter code
Browse files
.gitattributes
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
pretrained_models filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Rvc Spleeter Voice
|
3 |
+
emoji: 🌍
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: green
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 4.36.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
---
|
11 |
+
|
12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from spleeter.separator import Separator
|
2 |
+
import gradio as gr
|
3 |
+
import shutil
|
4 |
+
import librosa
|
5 |
+
import soundfile
|
6 |
+
import os
|
7 |
+
from gradio_client import Client, file
|
8 |
+
import subprocess
|
9 |
+
|
10 |
+
try:
|
11 |
+
shutil.rmtree("output")
|
12 |
+
except FileNotFoundError:
|
13 |
+
pass
|
14 |
+
|
15 |
+
|
16 |
+
def spleeter(aud, model_file, index_file, pitch):
|
17 |
+
separator = Separator('spleeter:2stems')
|
18 |
+
filename = os.path.basename(aud).split('.')[0]
|
19 |
+
accompaniment_filename = f"./output/audio_example/{filename}_accompaniment.wav"
|
20 |
+
vocal_filename = f"./output/audio_example/{filename}_vocals.wav"
|
21 |
+
song_filename = f'./output/audio_example/{filename}_song.wav'
|
22 |
+
|
23 |
+
separator.separate_to_file(aud, "output/", filename_format="audio_example/%s_{instrument}.wav" % filename)
|
24 |
+
|
25 |
+
# change pitch
|
26 |
+
y, sr = librosa.load(accompaniment_filename)
|
27 |
+
new_accompaniment = librosa.effects.pitch_shift(y, sr, pitch)
|
28 |
+
soundfile.write(accompaniment_filename, new_accompaniment, sr, )
|
29 |
+
|
30 |
+
# send vocal for processing
|
31 |
+
# https://huggingface.co/spaces/r3gm/rvc_zero
|
32 |
+
client = Client("r3gm/rvc_zero")
|
33 |
+
result = client.predict(
|
34 |
+
audio_files=[file(vocal_filename)],
|
35 |
+
file_m=file(model_file),
|
36 |
+
pitch_alg="rmvpe+",
|
37 |
+
pitch_lvl=pitch,
|
38 |
+
file_index=file(index_file),
|
39 |
+
index_inf=0.75,
|
40 |
+
r_m_f=3,
|
41 |
+
e_r=0.25,
|
42 |
+
c_b_p=0.5,
|
43 |
+
active_noise_reduce=False,
|
44 |
+
audio_effects=False,
|
45 |
+
api_name="/run"
|
46 |
+
)[0]
|
47 |
+
|
48 |
+
# combine accompaniment and vocal
|
49 |
+
command = f"""ffmpeg -i "{result}" -i "{accompaniment_filename}" -filter_complex amix=inputs=2:duration=longest "{song_filename}" """
|
50 |
+
subprocess.call(command, shell=True)
|
51 |
+
|
52 |
+
return song_filename
|
53 |
+
|
54 |
+
inputs = [
|
55 |
+
gr.Audio(sources='upload', label="Input Audio File", type="filepath"),
|
56 |
+
gr.File(
|
57 |
+
label="Model file",
|
58 |
+
type="filepath",
|
59 |
+
height=130,
|
60 |
+
),
|
61 |
+
gr.File(
|
62 |
+
label="Index file",
|
63 |
+
type="filepath",
|
64 |
+
height=130,
|
65 |
+
),
|
66 |
+
gr.Slider(
|
67 |
+
label="Pitch level",
|
68 |
+
minimum=-24,
|
69 |
+
maximum=24,
|
70 |
+
step=1,
|
71 |
+
value=0,
|
72 |
+
visible=True,
|
73 |
+
interactive=True,
|
74 |
+
)
|
75 |
+
]
|
76 |
+
outputs = [
|
77 |
+
gr.Audio(label="Output Audio", type="filepath"),
|
78 |
+
]
|
79 |
+
|
80 |
+
title = "Music Spleeter"
|
81 |
+
description = "Clearing a musical composition of the performer's voice is a common task. It is solved well, for example, by professional audio file editing programs. AI algorithms have also been gaining ground recently."
|
82 |
+
article = "<div style='text-align: center; max-width:800px; margin:10px auto;'><p>In this case we use Deezer's Spleeter with ready pretrained models. It can leave as an output both just the music and just the performer's voice.</p><p>Sources: <a href='https://github.com/deezer/spleeter/' target='_blank'>Spleeter</a>: a Fast and Efficient Music Source Separation Tool with Pre-Trained Models</p><p style='text-align: center'><a href='https://starstat.yt/cat/music' target='_blank'>StarStat Music</a>: Youtubers Net Worth in category Music</p></div>"
|
83 |
+
|
84 |
+
|
85 |
+
if __name__ == '__main__':
|
86 |
+
gr.Interface(spleeter, inputs, outputs).launch()
|
87 |
+
|
main.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from gradio_client import Client, file
|
2 |
+
|
3 |
+
client = Client("r3gm/rvc_zero")
|
4 |
+
result = client.predict(
|
5 |
+
audio_files=[file('https://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdf')],
|
6 |
+
file_m=file('https://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdf'),
|
7 |
+
pitch_alg="rmvpe+",
|
8 |
+
pitch_lvl=0,
|
9 |
+
file_index=file('https://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdf'),
|
10 |
+
index_inf=0.75,
|
11 |
+
r_m_f=3,
|
12 |
+
e_r=0.25,
|
13 |
+
c_b_p=0.5,
|
14 |
+
active_noise_reduce=False,
|
15 |
+
audio_effects=False,
|
16 |
+
api_name="/run"
|
17 |
+
)
|