Spaces:
Runtime error
Runtime error
xj
commited on
Commit
•
a90c9d1
1
Parent(s):
29dc912
[bug] fix some bugs
Browse files
app.py
CHANGED
@@ -12,6 +12,7 @@ from torch import no_grad, LongTensor
|
|
12 |
import webbrowser
|
13 |
import logging
|
14 |
import gradio.processing_utils as gr_processing_utils
|
|
|
15 |
logging.getLogger('numba').setLevel(logging.WARNING)
|
16 |
limitation = os.getenv("SYSTEM") == "spaces" # limit text and audio length in huggingface spaces
|
17 |
|
@@ -20,7 +21,7 @@ def audio_postprocess(self, y):
|
|
20 |
data = audio_postprocess_ori(self, y)
|
21 |
if data is None:
|
22 |
return None
|
23 |
-
return
|
24 |
gr.Audio.postprocess = audio_postprocess
|
25 |
|
26 |
def get_text(text, hps):
|
@@ -35,7 +36,7 @@ def vits(text, language, speaker_id, noise_scale, noise_scale_w, length_scale):
|
|
35 |
if not len(text):
|
36 |
return "输入文本不能为空!", None, None
|
37 |
text = text.replace('\n', ' ').replace('\r', '').replace(" ", "")
|
38 |
-
if len(text) >
|
39 |
return f"输入文字过长!{len(text)}>100", None, None
|
40 |
if language == 0:
|
41 |
text = f"[ZH]{text}[ZH]"
|
@@ -92,7 +93,7 @@ download_audio_js = """
|
|
92 |
if __name__ == '__main__':
|
93 |
parser = argparse.ArgumentParser()
|
94 |
parser.add_argument('--device', type=str, default='cpu')
|
95 |
-
parser.add_argument('--api', action="store_true", default=
|
96 |
parser.add_argument("--share", action="store_true", default=False, help="share gradio app")
|
97 |
parser.add_argument("--colab", action="store_true", default=False, help="share gradio app")
|
98 |
args = parser.parse_args()
|
@@ -107,6 +108,7 @@ if __name__ == '__main__':
|
|
107 |
**hps_ms.model)
|
108 |
_ = net_g_ms.eval().to(device)
|
109 |
speakers = hps_ms.speakers
|
|
|
110 |
model, optimizer, learning_rate, epochs = utils.load_checkpoint(r'./model/G_953000.pth', net_g_ms, None)
|
111 |
|
112 |
with gr.Blocks() as app:
|
@@ -118,16 +120,16 @@ if __name__ == '__main__':
|
|
118 |
with gr.TabItem("vits"):
|
119 |
with gr.Row():
|
120 |
with gr.Column():
|
121 |
-
input_text = gr.Textbox(label="Text (
|
122 |
lang = gr.Dropdown(label="Language", choices=["中文", "日语", "中日混合(中文用[ZH][ZH]包裹起来,日文用[JA][JA]包裹起来)"],
|
123 |
type="index", value="中文")
|
124 |
btn = gr.Button(value="Submit")
|
125 |
with gr.Row():
|
126 |
search = gr.Textbox(label="Search Speaker", lines=1)
|
127 |
btn2 = gr.Button(value="Search")
|
128 |
-
sid = gr.Dropdown(label="Speaker", choices=speakers, type="index", value=speakers[
|
129 |
with gr.Row():
|
130 |
-
ns = gr.Slider(label="noise_scale(控制感情变化程度)", minimum=0.1, maximum=1.0, step=0.1, value=0.
|
131 |
nsw = gr.Slider(label="noise_scale_w(控制音素发音长度)", minimum=0.1, maximum=1.0, step=0.1, value=0.668, interactive=True)
|
132 |
ls = gr.Slider(label="length_scale(控制整体语速)", minimum=0.1, maximum=2.0, step=0.1, value=1.2, interactive=True)
|
133 |
with gr.Column():
|
|
|
12 |
import webbrowser
|
13 |
import logging
|
14 |
import gradio.processing_utils as gr_processing_utils
|
15 |
+
from gradio_client import utils as client_utils
|
16 |
logging.getLogger('numba').setLevel(logging.WARNING)
|
17 |
limitation = os.getenv("SYSTEM") == "spaces" # limit text and audio length in huggingface spaces
|
18 |
|
|
|
21 |
data = audio_postprocess_ori(self, y)
|
22 |
if data is None:
|
23 |
return None
|
24 |
+
return client_utils.encode_url_or_file_to_base64(data["name"])
|
25 |
gr.Audio.postprocess = audio_postprocess
|
26 |
|
27 |
def get_text(text, hps):
|
|
|
36 |
if not len(text):
|
37 |
return "输入文本不能为空!", None, None
|
38 |
text = text.replace('\n', ' ').replace('\r', '').replace(" ", "")
|
39 |
+
if len(text) > 200 and limitation:
|
40 |
return f"输入文字过长!{len(text)}>100", None, None
|
41 |
if language == 0:
|
42 |
text = f"[ZH]{text}[ZH]"
|
|
|
93 |
if __name__ == '__main__':
|
94 |
parser = argparse.ArgumentParser()
|
95 |
parser.add_argument('--device', type=str, default='cpu')
|
96 |
+
parser.add_argument('--api', action="store_true", default=True)
|
97 |
parser.add_argument("--share", action="store_true", default=False, help="share gradio app")
|
98 |
parser.add_argument("--colab", action="store_true", default=False, help="share gradio app")
|
99 |
args = parser.parse_args()
|
|
|
108 |
**hps_ms.model)
|
109 |
_ = net_g_ms.eval().to(device)
|
110 |
speakers = hps_ms.speakers
|
111 |
+
speakers = [f"{i}.{s}" for i, s in enumerate(speakers)]
|
112 |
model, optimizer, learning_rate, epochs = utils.load_checkpoint(r'./model/G_953000.pth', net_g_ms, None)
|
113 |
|
114 |
with gr.Blocks() as app:
|
|
|
120 |
with gr.TabItem("vits"):
|
121 |
with gr.Row():
|
122 |
with gr.Column():
|
123 |
+
input_text = gr.Textbox(label="Text (200 words limitation) " if limitation else "Text", lines=5, value="可莉不知道喔。", elem_id=f"input-text")
|
124 |
lang = gr.Dropdown(label="Language", choices=["中文", "日语", "中日混合(中文用[ZH][ZH]包裹起来,日文用[JA][JA]包裹起来)"],
|
125 |
type="index", value="中文")
|
126 |
btn = gr.Button(value="Submit")
|
127 |
with gr.Row():
|
128 |
search = gr.Textbox(label="Search Speaker", lines=1)
|
129 |
btn2 = gr.Button(value="Search")
|
130 |
+
sid = gr.Dropdown(label="Speaker", choices=speakers, type="index", value=speakers[329])
|
131 |
with gr.Row():
|
132 |
+
ns = gr.Slider(label="noise_scale(控制感情变化程度)", minimum=0.1, maximum=1.0, step=0.1, value=0.1, interactive=True)
|
133 |
nsw = gr.Slider(label="noise_scale_w(控制音素发音长度)", minimum=0.1, maximum=1.0, step=0.1, value=0.668, interactive=True)
|
134 |
ls = gr.Slider(label="length_scale(控制整体语速)", minimum=0.1, maximum=2.0, step=0.1, value=1.2, interactive=True)
|
135 |
with gr.Column():
|