Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
|
|
3 |
import torch
|
4 |
import commons
|
5 |
import utils
|
|
|
6 |
from models import SynthesizerTrn
|
7 |
from text.symbols import symbols
|
8 |
from text import text_to_sequence
|
@@ -10,6 +11,8 @@ import numpy as np
|
|
10 |
import os
|
11 |
import translators.server as tss
|
12 |
import psutil
|
|
|
|
|
13 |
def show_memory_info(hint):
|
14 |
pid = os.getpid()
|
15 |
p = psutil.Process(pid)
|
@@ -38,6 +41,11 @@ _ = net_g.eval()
|
|
38 |
_ = utils.load_checkpoint("pretrained_models/G_1153000.pth", net_g, None)
|
39 |
|
40 |
def infer(text, character, language, duration, noise_scale, noise_scale_w):
|
|
|
|
|
|
|
|
|
|
|
41 |
show_memory_info("infer调用前")
|
42 |
if language == '日本語':
|
43 |
pass
|
@@ -78,7 +86,7 @@ if __name__ == "__main__":
|
|
78 |
with gr.Row():
|
79 |
with gr.Column():
|
80 |
# We instantiate the Textbox class
|
81 |
-
textbox = gr.Textbox(label="Text", placeholder="Type your sentence here", lines=2)
|
82 |
# select character
|
83 |
char_dropdown = gr.Dropdown(choices=['0:特别周', '1:无声铃鹿', '2:东海帝王', '3:丸善斯基',
|
84 |
'4:富士奇迹', '5:小栗帽', '6:黄金船', '7:伏特加',
|
|
|
3 |
import torch
|
4 |
import commons
|
5 |
import utils
|
6 |
+
import re
|
7 |
from models import SynthesizerTrn
|
8 |
from text.symbols import symbols
|
9 |
from text import text_to_sequence
|
|
|
11 |
import os
|
12 |
import translators.server as tss
|
13 |
import psutil
|
14 |
+
limitation = os.getenv("SYSTEM") == "spaces" # limit text and audio length in huggingface spaces
|
15 |
+
max_len = 150
|
16 |
def show_memory_info(hint):
|
17 |
pid = os.getpid()
|
18 |
p = psutil.Process(pid)
|
|
|
41 |
_ = utils.load_checkpoint("pretrained_models/G_1153000.pth", net_g, None)
|
42 |
|
43 |
def infer(text, character, language, duration, noise_scale, noise_scale_w):
|
44 |
+
# check text length
|
45 |
+
if limitation:
|
46 |
+
text_len = len(re.sub("\[([A-Z]{2})\]", "", text))
|
47 |
+
if text_len > max_len:
|
48 |
+
return "Error: Text is too long", None
|
49 |
show_memory_info("infer调用前")
|
50 |
if language == '日本語':
|
51 |
pass
|
|
|
86 |
with gr.Row():
|
87 |
with gr.Column():
|
88 |
# We instantiate the Textbox class
|
89 |
+
textbox = gr.Textbox(label="Text", placeholder="Type your sentence here (Maximum 150 words)", lines=2)
|
90 |
# select character
|
91 |
char_dropdown = gr.Dropdown(choices=['0:特别周', '1:无声铃鹿', '2:东海帝王', '3:丸善斯基',
|
92 |
'4:富士奇迹', '5:小栗帽', '6:黄金船', '7:伏特加',
|