reha commited on
Commit
14cdbd7
1 Parent(s): 0af542d

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import io
2
+
3
+ import gradio as gr
4
+ import librosa
5
+ import numpy as np
6
+ import soundfile
7
+ import torch
8
+ from inference.infer_tool import Svc
9
+ import logging
10
+
11
+ logging.getLogger('numba').setLevel(logging.WARNING)
12
+
13
+ model_name = "logs/32k/G_98000.pth"
14
+ config_name = "configs/config.json"
15
+
16
+ svc_model = Svc(model_name, config_name)
17
+ sid_map = {
18
+ "Ztech": "Ztech"
19
+ }
20
+
21
+
22
+ def vc_fn(sid, input_audio, vc_transform):
23
+ if input_audio is None:
24
+ return "You need to upload an audio", None
25
+ sampling_rate, audio = input_audio
26
+ # print(audio.shape,sampling_rate)
27
+ duration = audio.shape[0] / sampling_rate
28
+ if duration > 45:
29
+ return "请上传小于45s的音频,需要转换长音频请本地进行转换", None
30
+ audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
31
+ if len(audio.shape) > 1:
32
+ audio = librosa.to_mono(audio.transpose(1, 0))
33
+ if sampling_rate != 16000:
34
+ audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000)
35
+ print(audio.shape)
36
+ out_wav_path = io.BytesIO()
37
+ soundfile.write(out_wav_path, audio, 16000, format="wav")
38
+ out_wav_path.seek(0)
39
+
40
+ sid = sid_map[sid]
41
+ out_audio, out_sr = svc_model.infer(sid, vc_transform, out_wav_path)
42
+ _audio = out_audio.cpu().numpy()
43
+ return "Success", (32000, _audio)
44
+
45
+
46
+ app = gr.Blocks()
47
+ with app:
48
+ with gr.Tabs():
49
+ with gr.TabItem("Basic"):
50
+ gr.Markdown(value="""
51
+ 这是sovits 3.0 32khz版本ai粘连科技的在线demo
52
+
53
+ 人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人人
54
+
55
+ 在使用此模型前请阅读[AI粘连科技模型使用协议](https://huggingface.co/spaces/reha/Stick_Tech/blob/main/terms.md)
56
+
57
+ YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY
58
+
59
+ 粘连科技Official@bilibili:[点击关注](https://space.bilibili.com/248582596)
60
+
61
+ 如果要在本地使用该demo,请使用git lfs clone 该仓库,安装requirements.txt后运行app.py即可
62
+
63
+ 项目改写基于 https://huggingface.co/spaces/innnky/nyaru-svc-3.0
64
+
65
+ 本地合成可以删除26、27两行代码以解除合成45s长度限制""")
66
+ sid = gr.Dropdown(label="音色", choices=["Ztech"], value="Ztech")
67
+ vc_input3 = gr.Audio(label="上传音频(长度小于45秒)")
68
+ vc_transform = gr.Number(label="变调(整数,可以正负,半音数量,升高八度就是12)", value=0)
69
+ vc_submit = gr.Button("转换", variant="primary")
70
+ vc_output1 = gr.Textbox(label="Output Message")
71
+ vc_output2 = gr.Audio(label="Output Audio")
72
+ vc_submit.click(vc_fn, [sid, vc_input3, vc_transform], [vc_output1, vc_output2])
73
+
74
+ app.launch()