Spaces:
Running
on
Zero
Running
on
Zero
JacobLinCool
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -4,8 +4,11 @@ from zerorvc import RVC
|
|
4 |
import soundfile as sf
|
5 |
from pydub import AudioSegment
|
6 |
from joblib import memory
|
|
|
|
|
7 |
|
8 |
memory = memory.Memory(location="cache", verbose=0)
|
|
|
9 |
|
10 |
@memory.cache(ignore=["client"])
|
11 |
def split(client, audio):
|
@@ -16,10 +19,15 @@ def split(client, audio):
|
|
16 |
)
|
17 |
return result[0], result[1]
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
def process_audio(client, model, audio, pitch_modification):
|
20 |
-
rvc = RVC.from_pretrained(model)
|
21 |
vocal, bgm = split(client, audio)
|
22 |
-
samples =
|
23 |
|
24 |
sf.write("vocal.wav", samples, rvc.sr)
|
25 |
|
@@ -45,11 +53,14 @@ def set_client_for_session(request: gr.Request):
|
|
45 |
|
46 |
with gr.Blocks() as demo:
|
47 |
client = gr.State()
|
|
|
|
|
|
|
48 |
btn = gr.Button("Run", variant="primary")
|
49 |
|
50 |
btn.click(
|
51 |
process_audio,
|
52 |
-
[client,
|
53 |
[gr.Audio(label="Combined"), gr.Audio(label="Vocal"), gr.Audio(label="Background")]
|
54 |
)
|
55 |
|
|
|
4 |
import soundfile as sf
|
5 |
from pydub import AudioSegment
|
6 |
from joblib import memory
|
7 |
+
import spaces
|
8 |
+
from accelerate import Accelerator
|
9 |
|
10 |
memory = memory.Memory(location="cache", verbose=0)
|
11 |
+
accelerator = Accelerator()
|
12 |
|
13 |
@memory.cache(ignore=["client"])
|
14 |
def split(client, audio):
|
|
|
19 |
)
|
20 |
return result[0], result[1]
|
21 |
|
22 |
+
@spaces.GPU
|
23 |
+
def convert(model, vocal, pitch_modification):
|
24 |
+
rvc = RVC.from_pretrained(model).to(accelerator.device)
|
25 |
+
samples = rvc.convert(vocal, pitch_modification=pitch_modification)
|
26 |
+
return samples
|
27 |
+
|
28 |
def process_audio(client, model, audio, pitch_modification):
|
|
|
29 |
vocal, bgm = split(client, audio)
|
30 |
+
samples = convert(model, vocal, pitch_modification)
|
31 |
|
32 |
sf.write("vocal.wav", samples, rvc.sr)
|
33 |
|
|
|
53 |
|
54 |
with gr.Blocks() as demo:
|
55 |
client = gr.State()
|
56 |
+
model = gr.Text("someone/model")
|
57 |
+
audio = gr.Audio(type="filepath")
|
58 |
+
pitch = gr.Slider(minimum=-36, maximum=36, value=0, step=1)
|
59 |
btn = gr.Button("Run", variant="primary")
|
60 |
|
61 |
btn.click(
|
62 |
process_audio,
|
63 |
+
[client, model, audio, pitch],
|
64 |
[gr.Audio(label="Combined"), gr.Audio(label="Vocal"), gr.Audio(label="Background")]
|
65 |
)
|
66 |
|