Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# os.system("wget -P cvec/ https://huggingface.co/spaces/innnky/nanami/resolve/main/checkpoint_best_legacy_500.pt")
|
| 5 |
+
import gradio as gr
|
| 6 |
+
import librosa
|
| 7 |
+
import numpy as np
|
| 8 |
+
import soundfile
|
| 9 |
+
from inference.infer_tool import Svc
|
| 10 |
+
import logging
|
| 11 |
+
|
| 12 |
+
logging.getLogger('numba').setLevel(logging.WARNING)
|
| 13 |
+
logging.getLogger('markdown_it').setLevel(logging.WARNING)
|
| 14 |
+
logging.getLogger('urllib3').setLevel(logging.WARNING)
|
| 15 |
+
logging.getLogger('matplotlib').setLevel(logging.WARNING)
|
| 16 |
+
|
| 17 |
+
config_path = "config.json"
|
| 18 |
+
|
| 19 |
+
model = Svc("G_754.pth", "config.json")
|
| 20 |
+
|
| 21 |
+
# model = Svc("E:/Items/so-vits-svc/models/Arknights/G_10400.pth", "E:/Items/so-vits-svc/models/Arknights/config.json")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def vc_fn(input_audio, vc_transform, auto_f0,cluster_ratio, slice_db, noise_scale):
|
| 25 |
+
if input_audio is None:
|
| 26 |
+
return "You need to upload an audio", None
|
| 27 |
+
sampling_rate, audio = input_audio
|
| 28 |
+
# print(audio.shape,sampling_rate)
|
| 29 |
+
duration = audio.shape[0] / sampling_rate
|
| 30 |
+
if duration > 90:
|
| 31 |
+
return "请上传小于90s的音频,需要转换长音频请本地进行转换", None
|
| 32 |
+
audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
|
| 33 |
+
if len(audio.shape) > 1:
|
| 34 |
+
audio = librosa.to_mono(audio.transpose(1, 0))
|
| 35 |
+
# if sampling_rate != 16000:
|
| 36 |
+
# audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000)
|
| 37 |
+
print(audio.shape)
|
| 38 |
+
out_wav_path = "temp.wav"
|
| 39 |
+
soundfile.write(out_wav_path, audio, 16000, format="wav")
|
| 40 |
+
# print( cluster_ratio, auto_f0, noise_scale)
|
| 41 |
+
_audio = model.slice_inference(out_wav_path)
|
| 42 |
+
return "Success", (44100, _audio)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
app = gr.Blocks()
|
| 46 |
+
with app:
|
| 47 |
+
with gr.Tabs():
|
| 48 |
+
with gr.TabItem("Basic"):
|
| 49 |
+
gr.Markdown(value="""
|
| 50 |
+
sovits4.0 Arknights
|
| 51 |
+
自练模型,内有 伊芙利特 凯尔希 桃金娘 塞雷娅 斯卡蒂
|
| 52 |
+
""")
|
| 53 |
+
spks = list(model.spk2id.keys())
|
| 54 |
+
vc_input3 = gr.Audio(label="上传音频(长度小于90秒)")
|
| 55 |
+
vc_submit = gr.Button("转换", variant="primary")
|
| 56 |
+
vc_output1 = gr.Textbox(label="Output Message")
|
| 57 |
+
vc_output2 = gr.Audio(label="Output Audio")
|
| 58 |
+
vc_submit.click(vc_fn, [vc_input3], [vc_output1, vc_output2])
|
| 59 |
+
|
| 60 |
+
app.launch()
|