Spaces:
Runtime error
Runtime error
CrawfordZhou
commited on
Commit
•
be3665d
1
Parent(s):
b3c3cef
Update app.py
Browse files
app.py
CHANGED
@@ -24,7 +24,18 @@ from text import cleaned_text_to_sequence, get_bert
|
|
24 |
from text.cleaner import clean_text
|
25 |
import gradio as gr
|
26 |
import webbrowser
|
|
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
net_g = None
|
30 |
|
@@ -51,9 +62,11 @@ def get_text(text, language_str, hps):
|
|
51 |
|
52 |
return bert, phone, tone, language
|
53 |
|
54 |
-
def infer(text, sdp_ratio, noise_scale, noise_scale_w, length_scale, sid):
|
55 |
global net_g
|
56 |
-
|
|
|
|
|
57 |
with torch.no_grad():
|
58 |
x_tst=phones.to(device).unsqueeze(0)
|
59 |
tones=tones.to(device).unsqueeze(0)
|
@@ -67,15 +80,15 @@ def infer(text, sdp_ratio, noise_scale, noise_scale_w, length_scale, sid):
|
|
67 |
del x_tst, tones, lang_ids, bert, x_tst_lengths, speakers
|
68 |
return audio
|
69 |
|
70 |
-
def tts_fn(text, speaker, sdp_ratio, noise_scale, noise_scale_w, length_scale):
|
71 |
with torch.no_grad():
|
72 |
-
audio = infer(text, sdp_ratio=sdp_ratio, noise_scale=noise_scale, noise_scale_w=noise_scale_w, length_scale=length_scale, sid=speaker)
|
73 |
return "Success", (hps.data.sampling_rate, audio)
|
74 |
|
75 |
|
76 |
if __name__ == "__main__":
|
77 |
parser = argparse.ArgumentParser()
|
78 |
-
parser.add_argument("--model_dir", default="./logs/
|
79 |
parser.add_argument("--config_dir", default="./configs/config.json", help="path of your config file")
|
80 |
parser.add_argument("--share", default=False, help="make link public")
|
81 |
parser.add_argument("-d", "--debug", action="store_true", help="enable DEBUG-LEVEL log")
|
@@ -113,40 +126,36 @@ if __name__ == "__main__":
|
|
113 |
with gr.Row():
|
114 |
with gr.Column():
|
115 |
gr.Markdown(value="""
|
116 |
-
【AI
|
|
|
|
|
117 |
作者:Xz乔希 https://space.bilibili.com/5859321\n
|
|
|
118 |
声音归属:向晚大魔王 https://space.bilibili.com/672346917\n
|
119 |
Bert-VITS2项目:https://github.com/Stardust-minus/Bert-VITS2\n
|
|
|
|
|
120 |
使用本模型请严格遵守法律法规!\n
|
121 |
发布二创作品请标注本项目作者及链接、作品使用Bert-VITS2 AI生成!\n
|
122 |
""")
|
123 |
-
text = gr.TextArea(label="
|
124 |
-
|
|
|
|
|
125 |
speaker = gr.Dropdown(choices=speakers, value=speakers[0], label='Speaker')
|
126 |
sdp_ratio = gr.Slider(minimum=0.1, maximum=1, value=0.2, step=0.01, label='SDP/DP混合比')
|
127 |
noise_scale = gr.Slider(minimum=0.1, maximum=1, value=0.5, step=0.01, label='感情调节')
|
128 |
noise_scale_w = gr.Slider(minimum=0.1, maximum=1, value=0.9, step=0.01, label='音素长度')
|
129 |
-
length_scale = gr.Slider(minimum=0.1, maximum=2, value=1, step=0.01, label='生成长度')
|
130 |
btn = gr.Button("点击生成", variant="primary")
|
131 |
with gr.Column():
|
132 |
text_output = gr.Textbox(label="Message")
|
133 |
audio_output = gr.Audio(label="Output Audio")
|
134 |
-
gr.Markdown(value="""
|
135 |
-
【AI塔菲】https://huggingface.co/spaces/XzJosh/Taffy-Bert-VITS2\n
|
136 |
-
【AI东雪莲】https://huggingface.co/spaces/XzJosh/Azuma-Bert-VITS2\n
|
137 |
-
【AI奶绿】https://huggingface.co/spaces/XzJosh/LAPLACE-Bert-VITS2\n
|
138 |
-
【AI尼奈】https://huggingface.co/spaces/XzJosh/nine1-Bert-VITS2\n
|
139 |
-
【AI珈乐】https://huggingface.co/spaces/XzJosh/Carol-Bert-VITS2\n
|
140 |
-
【AI电棍】https://huggingface.co/spaces/XzJosh/otto-Bert-VITS2\n
|
141 |
-
【AI七海】https://huggingface.co/spaces/XzJosh/Nana7mi-Bert-VITS2\n
|
142 |
-
【AI阿梓】https://huggingface.co/spaces/XzJosh/Azusa-Bert-VITS2\n
|
143 |
-
【AI星瞳】https://huggingface.co/spaces/XzJosh/XingTong-Bert-VITS2\n
|
144 |
-
""")
|
145 |
btn.click(tts_fn,
|
146 |
-
inputs=[text, speaker, sdp_ratio, noise_scale, noise_scale_w, length_scale],
|
147 |
outputs=[text_output, audio_output])
|
148 |
-
|
149 |
# webbrowser.open("http://127.0.0.1:6006")
|
150 |
# app.launch(server_port=6006, show_error=True)
|
151 |
-
|
152 |
app.launch(show_error=True)
|
|
|
24 |
from text.cleaner import clean_text
|
25 |
import gradio as gr
|
26 |
import webbrowser
|
27 |
+
import openai
|
28 |
|
29 |
+
# openai.log = "debug"
|
30 |
+
openai.api_base = "https://api.chatanywhere.com.cn/v1"
|
31 |
+
|
32 |
+
|
33 |
+
# 非流式响应
|
34 |
+
|
35 |
+
def gpt_35_api(gptkey, message):
|
36 |
+
openai.api_key = "sk-" + gptkey
|
37 |
+
completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": message}])
|
38 |
+
return completion.choices[0].message.content
|
39 |
|
40 |
net_g = None
|
41 |
|
|
|
62 |
|
63 |
return bert, phone, tone, language
|
64 |
|
65 |
+
def infer(text, key, sdp_ratio, noise_scale, noise_scale_w, length_scale, sid):
|
66 |
global net_g
|
67 |
+
message = gpt_35_api(key, text)
|
68 |
+
print(message)
|
69 |
+
bert, phones, tones, lang_ids = get_text(message, "ZH", hps)
|
70 |
with torch.no_grad():
|
71 |
x_tst=phones.to(device).unsqueeze(0)
|
72 |
tones=tones.to(device).unsqueeze(0)
|
|
|
80 |
del x_tst, tones, lang_ids, bert, x_tst_lengths, speakers
|
81 |
return audio
|
82 |
|
83 |
+
def tts_fn(text, key, speaker, sdp_ratio, noise_scale, noise_scale_w, length_scale):
|
84 |
with torch.no_grad():
|
85 |
+
audio = infer(text, key,sdp_ratio=sdp_ratio, noise_scale=noise_scale, noise_scale_w=noise_scale_w, length_scale=length_scale, sid=speaker)
|
86 |
return "Success", (hps.data.sampling_rate, audio)
|
87 |
|
88 |
|
89 |
if __name__ == "__main__":
|
90 |
parser = argparse.ArgumentParser()
|
91 |
+
parser.add_argument("--model_dir", default="./logs/Bella/G_3100.pth", help="path of your model")
|
92 |
parser.add_argument("--config_dir", default="./configs/config.json", help="path of your config file")
|
93 |
parser.add_argument("--share", default=False, help="make link public")
|
94 |
parser.add_argument("-d", "--debug", action="store_true", help="enable DEBUG-LEVEL log")
|
|
|
126 |
with gr.Row():
|
127 |
with gr.Column():
|
128 |
gr.Markdown(value="""
|
129 |
+
# 【AI向晚】在线语音对话版(Bert-Vits2 + gpt)\n
|
130 |
+
!(ava.png)\n
|
131 |
+
对话内容基于gpt生成,由于接口转发,生成可能需要2分钟!\n
|
132 |
作者:Xz乔希 https://space.bilibili.com/5859321\n
|
133 |
+
集成作者:碎语碎念 https://space.bilibili.com/4269384\n
|
134 |
声音归属:向晚大魔王 https://space.bilibili.com/672346917\n
|
135 |
Bert-VITS2项目:https://github.com/Stardust-minus/Bert-VITS2\n
|
136 |
+
GPT_API_free项目:https://github.com/chatanywhere/GPT_API_free\n
|
137 |
+
本项目中的apiKey可以从上面的项目免费获取(本项目默认提供了一个,如果没法用了去仓库申请替换就好啦)!\n
|
138 |
使用本模型请严格遵守法律法规!\n
|
139 |
发布二创作品请标注本项目作者及链接、作品使用Bert-VITS2 AI生成!\n
|
140 |
""")
|
141 |
+
text = gr.TextArea(label="要对向晚说什么呢", placeholder="Input Text Here",
|
142 |
+
value="虚拟主播是什么?")
|
143 |
+
key = gr.Text(label="GPT Key", placeholder="请输入上面提示中获取的gpt key",
|
144 |
+
value="izlrijShDu7tp2rIgvYfibcC2J0Eh3uWfdm9ndrxN5nWrL96")
|
145 |
speaker = gr.Dropdown(choices=speakers, value=speakers[0], label='Speaker')
|
146 |
sdp_ratio = gr.Slider(minimum=0.1, maximum=1, value=0.2, step=0.01, label='SDP/DP混合比')
|
147 |
noise_scale = gr.Slider(minimum=0.1, maximum=1, value=0.5, step=0.01, label='感情调节')
|
148 |
noise_scale_w = gr.Slider(minimum=0.1, maximum=1, value=0.9, step=0.01, label='音素长度')
|
149 |
+
length_scale = gr.Slider(minimum=0.1, maximum=2, value=1.1, step=0.01, label='生成长度')
|
150 |
btn = gr.Button("点击生成", variant="primary")
|
151 |
with gr.Column():
|
152 |
text_output = gr.Textbox(label="Message")
|
153 |
audio_output = gr.Audio(label="Output Audio")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
154 |
btn.click(tts_fn,
|
155 |
+
inputs=[text, key, speaker, sdp_ratio, noise_scale, noise_scale_w, length_scale],
|
156 |
outputs=[text_output, audio_output])
|
157 |
+
|
158 |
# webbrowser.open("http://127.0.0.1:6006")
|
159 |
# app.launch(server_port=6006, show_error=True)
|
160 |
+
|
161 |
app.launch(show_error=True)
|