YazawaSunrise
commited on
Commit
•
7e02203
1
Parent(s):
d6266d7
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from inference.infer_tool_grad import VitsSvc
|
2 |
+
import gradio as gr
|
3 |
+
import os
|
4 |
+
|
5 |
+
class VitsGradio:
|
6 |
+
def __init__(self):
|
7 |
+
self.so = VitsSvc()
|
8 |
+
self.lspk = []
|
9 |
+
self.modelPaths = []
|
10 |
+
for root,dirs,files in os.walk("checkpoints"):
|
11 |
+
for dir in dirs:
|
12 |
+
self.modelPaths.append(dir)
|
13 |
+
with gr.Blocks() as self.Vits:
|
14 |
+
with gr.Tab("VoiceConversion"):
|
15 |
+
with gr.Row(visible=False) as self.VoiceConversion:
|
16 |
+
with gr.Column():
|
17 |
+
with gr.Row():
|
18 |
+
with gr.Column():
|
19 |
+
self.srcaudio = gr.Audio(label = "输入音频")
|
20 |
+
self.btnVC = gr.Button("说话人转换")
|
21 |
+
with gr.Column():
|
22 |
+
self.dsid = gr.Dropdown(label = "目标角色", choices = self.lspk)
|
23 |
+
self.tran = gr.Slider(label = "升降调", maximum = 60, minimum = -60, step = 1, value = 0)
|
24 |
+
self.th = gr.Slider(label = "切片阈值", maximum = 32767, minimum = -32768, step = 0.1, value = -40)
|
25 |
+
with gr.Row():
|
26 |
+
self.VCOutputs = gr.Audio()
|
27 |
+
self.btnVC.click(self.so.inference, inputs=[self.srcaudio,self.dsid,self.tran,self.th], outputs=[self.VCOutputs])
|
28 |
+
with gr.Tab("SelectModel"):
|
29 |
+
with gr.Column():
|
30 |
+
modelstrs = gr.Dropdown(label = "模型", choices = self.modelPaths, value = self.modelPaths[0], type = "value")
|
31 |
+
devicestrs = gr.Dropdown(label = "设备", choices = ["cpu","cuda"], value = "cpu", type = "value")
|
32 |
+
btnMod = gr.Button("载入模型")
|
33 |
+
btnMod.click(self.loadModel, inputs=[modelstrs,devicestrs], outputs = [self.dsid,self.VoiceConversion])
|
34 |
+
|
35 |
+
def loadModel(self, path, device):
|
36 |
+
self.lspk = []
|
37 |
+
self.so.set_device(device)
|
38 |
+
self.so.loadCheckpoint(path)
|
39 |
+
for spk, sid in self.so.hps.spk.items():
|
40 |
+
self.lspk.append(spk)
|
41 |
+
VChange = gr.update(visible = True)
|
42 |
+
SDChange = gr.update(choices = self.lspk, value = self.lspk[0])
|
43 |
+
return [SDChange,VChange]
|
44 |
+
|
45 |
+
grVits = VitsGradio()
|
46 |
+
|
47 |
+
grVits.Vits.launch()
|