Spaces:
Runtime error
Runtime error
Crawford.Zhou
commited on
Commit
•
cb557b3
1
Parent(s):
b4043e9
添加gpt
Browse files- app.py +23 -21
- requirements.txt +1 -0
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,8 +62,10 @@ 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 |
bert, phones, tones, lang_ids = get_text(text, "ZH", hps)
|
57 |
with torch.no_grad():
|
58 |
x_tst=phones.to(device).unsqueeze(0)
|
@@ -67,9 +80,9 @@ 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 |
|
@@ -113,10 +126,14 @@ 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 |
声音归属:贝拉kira https://space.bilibili.com/672353429\n
|
119 |
Bert-VITS2项目:https://github.com/Stardust-minus/Bert-VITS2\n
|
|
|
|
|
|
|
120 |
使用本模型请严格遵守法律法规!\n
|
121 |
发布二创作品请标注本项目作者及链接、作品使用Bert-VITS2 AI生成!\n
|
122 |
""")
|
@@ -131,26 +148,11 @@ if __name__ == "__main__":
|
|
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/Ava-Bert-VITS2\n
|
136 |
-
【AI嘉然】https://huggingface.co/spaces/XzJosh/Diana-Bert-VITS2\n
|
137 |
-
【AI乃琳】https://huggingface.co/spaces/XzJosh/Eileen-Bert-VITS2\n
|
138 |
-
【AI珈乐】https://huggingface.co/spaces/XzJosh/Carol-Bert-VITS2\n
|
139 |
-
【AI塔菲】https://huggingface.co/spaces/XzJosh/Taffy-Bert-VITS2\n
|
140 |
-
【AI东雪莲】https://huggingface.co/spaces/XzJosh/Azuma-Bert-VITS2\n
|
141 |
-
【AI奶绿】https://huggingface.co/spaces/XzJosh/LAPLACE-Bert-VITS2\n
|
142 |
-
【AI尼奈】https://huggingface.co/spaces/XzJosh/nine1-Bert-VITS2\n
|
143 |
-
【AI电棍】https://huggingface.co/spaces/XzJosh/otto-Bert-VITS2\n
|
144 |
-
【AI七海】https://huggingface.co/spaces/XzJosh/Nana7mi-Bert-VITS2\n
|
145 |
-
【AI阿梓】https://huggingface.co/spaces/XzJosh/Azusa-Bert-VITS2\n
|
146 |
-
【AI星瞳】https://huggingface.co/spaces/XzJosh/XingTong-Bert-VITS2\n
|
147 |
-
【AI剑魔】https://huggingface.co/spaces/XzJosh/Aatrox-Bert-VITS2\n
|
148 |
-
""")
|
149 |
btn.click(tts_fn,
|
150 |
inputs=[text, speaker, sdp_ratio, noise_scale, noise_scale_w, length_scale],
|
151 |
outputs=[text_output, audio_output])
|
152 |
-
|
153 |
# webbrowser.open("http://127.0.0.1:6006")
|
154 |
# app.launch(server_port=6006, show_error=True)
|
155 |
-
|
156 |
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(text, "ZH", hps)
|
70 |
with torch.no_grad():
|
71 |
x_tst=phones.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 |
|
|
|
126 |
with gr.Row():
|
127 |
with gr.Column():
|
128 |
gr.Markdown(value="""
|
129 |
+
【AI贝拉】在线语音对话版(Bert-Vits2 + gpt)\n
|
130 |
作者:Xz乔希 https://space.bilibili.com/5859321\n
|
131 |
+
集成作者:碎语碎念 https://space.bilibili.com/4269384\n
|
132 |
声音归属:贝拉kira https://space.bilibili.com/672353429\n
|
133 |
Bert-VITS2项目:https://github.com/Stardust-minus/Bert-VITS2\n
|
134 |
+
GPT_API_free项目:https://github.com/chatanywhere/GPT_API_free\n
|
135 |
+
本项目中的apiKey可以免费从https://github.com/chatanywhere/GPT_API_free\n
|
136 |
+
获取,参考项目文档即可!\n
|
137 |
使用本模型请严格遵守法律法规!\n
|
138 |
发布二创作品请标注本项目作者及链接、作品使用Bert-VITS2 AI生成!\n
|
139 |
""")
|
|
|
148 |
with gr.Column():
|
149 |
text_output = gr.Textbox(label="Message")
|
150 |
audio_output = gr.Audio(label="Output Audio")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
btn.click(tts_fn,
|
152 |
inputs=[text, speaker, sdp_ratio, noise_scale, noise_scale_w, length_scale],
|
153 |
outputs=[text_output, audio_output])
|
154 |
+
|
155 |
# webbrowser.open("http://127.0.0.1:6006")
|
156 |
# app.launch(server_port=6006, show_error=True)
|
157 |
+
|
158 |
app.launch(show_error=True)
|
requirements.txt
CHANGED
@@ -15,3 +15,4 @@ pypinyin
|
|
15 |
cn2an
|
16 |
gradio
|
17 |
av
|
|
|
|
15 |
cn2an
|
16 |
gradio
|
17 |
av
|
18 |
+
openai==0.28
|