Plachta commited on
Commit
b2d8161
1 Parent(s): a664789

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -25
app.py CHANGED
@@ -13,7 +13,29 @@ 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
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  def show_memory_info(hint):
18
  pid = os.getpid()
19
  p = psutil.Process(pid)
@@ -42,11 +64,18 @@ _ = net_g.eval()
42
  _ = utils.load_checkpoint("pretrained_models/G_1153000.pth", net_g, None)
43
 
44
  def infer(text, character, language, duration, noise_scale, noise_scale_w):
 
 
 
 
 
45
  # check text length
46
  if limitation:
47
  text_len = len(re.sub("\[([A-Z]{2})\]", "", text))
48
  if text_len > max_len:
49
  return "Error: Text is too long", None
 
 
50
  show_memory_info("infer调用前")
51
  if language == '日本語':
52
  pass
@@ -85,31 +114,10 @@ if __name__ == "__main__":
85
  with gr.Row():
86
  with gr.Column():
87
  # We instantiate the Textbox class
88
- textbox = gr.Textbox(label="Text", placeholder="Type your sentence here (Maximum 150 words)", lines=2)
89
  # select character
90
- char_dropdown = gr.Dropdown(choices=['0:特别周', '1:无声铃鹿', '2:东海帝王', '3:丸善斯基',
91
- '4:富士奇迹', '5:小栗帽', '6:黄金船', '7:伏特加',
92
- '8:大和赤骥', '9:大树快车', '10:草上飞', '11:菱亚马逊',
93
- '12:目白麦昆', '13:神鹰', '14:好歌剧', '15:成田白仁',
94
- '16:鲁道夫象征', '17:气槽', '18:爱丽数码', '19:青云天空',
95
- '20:玉藻十字', '21:美妙姿势', '22:琵琶晨光', '23:重炮',
96
- '24:曼城茶座', '25:美普波旁', '26:目白雷恩', '27:菱曙',
97
- '28:雪之美人', '29:米浴', '30:艾尼斯风神', '31:爱丽速子',
98
- '32:爱慕织姬', '33:稻荷一', '34:胜利奖券', '35:空中神宫',
99
- '36:荣进闪耀', '37:真机伶', '38:川上公主', '39:黄金城市',
100
- '40:樱花进王', '41:采珠', '42:新光风', '43:东商变革',
101
- '44:超级小溪', '45:醒目飞鹰', '46:荒漠英雄', '47:东瀛佐敦',
102
- '48:中山庆典', '49:成田大进', '50:西野花', '51:春乌拉拉',
103
- '52:青竹回忆', '53:微光飞驹', '54:美丽周日', '55:待兼福来',
104
- '56:Mr.C.B', '57:名将怒涛', '58:目白多伯', '59:优秀素质',
105
- '60:帝王光环', '61:待兼诗歌剧', '62:生野狄杜斯', '63:目白善信',
106
- '64:大拓太阳神', '65:双涡轮', '66:里见光钻', '67:北部玄驹',
107
- '68:樱花千代王', '69:天狼星象征', '70:目白阿尔丹', '71:八重无敌',
108
- '72:鹤丸刚志', '73:目白光明', '74:樱花桂冠', '75:成田路',
109
- '76:也文摄辉', '77:吉兆', '78:谷野美酒', '79:第一红宝石',
110
- '80:真弓快车', '81:骏川手纲', '82:凯斯奇迹', '83:小林历奇',
111
- '84:北港火山', '85:奇锐骏', '86:秋川理事长'], label='character')
112
- language_dropdown = gr.Dropdown(choices=['日本語', '简体中文', 'English'], label='language')
113
 
114
 
115
  duration_slider = gr.Slider(minimum=0.1, maximum=5, value=1, step=0.1, label='时长 Duration')
 
13
  import psutil
14
  limitation = os.getenv("SYSTEM") == "spaces" # limit text and audio length in huggingface spaces
15
  max_len = 150
16
+ languages = ['日本語', '简体中文', 'English']
17
+ characters = ['0:特别周', '1:无声铃鹿', '2:东海帝王', '3:丸善斯基',
18
+ '4:富士奇迹', '5:小栗帽', '6:黄金船', '7:伏特加',
19
+ '8:大和赤骥', '9:大树快车', '10:草上飞', '11:菱亚马逊',
20
+ '12:目白麦昆', '13:神鹰', '14:好歌剧', '15:成田白仁',
21
+ '16:鲁道夫象征', '17:气槽', '18:爱丽数码', '19:青云天空',
22
+ '20:玉藻十字', '21:美妙姿势', '22:琵琶晨光', '23:重炮',
23
+ '24:曼城茶座', '25:美普波旁', '26:目白雷恩', '27:菱曙',
24
+ '28:雪之美人', '29:米浴', '30:艾尼斯风神', '31:爱丽速子',
25
+ '32:爱慕织姬', '33:稻荷一', '34:胜利奖券', '35:空中神宫',
26
+ '36:荣进闪耀', '37:真机伶', '38:川上公主', '39:黄金城市',
27
+ '40:樱花进王', '41:采珠', '42:新光风', '43:东商变革',
28
+ '44:超级小溪', '45:醒目飞鹰', '46:荒漠英雄', '47:东瀛佐敦',
29
+ '48:中山庆典', '49:成田大进', '50:西野花', '51:春乌拉拉',
30
+ '52:青竹回忆', '53:微光飞驹', '54:美丽周日', '55:待兼福来',
31
+ '56:Mr.C.B', '57:名将怒涛', '58:目白多伯', '59:优秀素质',
32
+ '60:帝王光环', '61:待兼诗歌剧', '62:生野狄杜斯', '63:目白善信',
33
+ '64:大拓太阳神', '65:双涡轮', '66:里见光钻', '67:北部玄驹',
34
+ '68:樱花千代王', '69:天狼星象征', '70:目白阿尔丹', '71:八重无敌',
35
+ '72:鹤丸刚志', '73:目白光明', '74:樱花桂冠', '75:成田路',
36
+ '76:也文摄辉', '77:吉兆', '78:谷野美酒', '79:第一红宝石',
37
+ '80:真弓快车', '81:骏川手纲', '82:凯斯奇迹', '83:小林历奇',
38
+ '84:北港火山', '85:奇锐骏', '86:秋川理事长']
39
  def show_memory_info(hint):
40
  pid = os.getpid()
41
  p = psutil.Process(pid)
 
64
  _ = utils.load_checkpoint("pretrained_models/G_1153000.pth", net_g, None)
65
 
66
  def infer(text, character, language, duration, noise_scale, noise_scale_w):
67
+ # check character & duraction parameter
68
+ if language not in languages:
69
+ return "Error: No such language", None
70
+ if character not in characters:
71
+ return "Error: No such character", None
72
  # check text length
73
  if limitation:
74
  text_len = len(re.sub("\[([A-Z]{2})\]", "", text))
75
  if text_len > max_len:
76
  return "Error: Text is too long", None
77
+ if text_len == 0:
78
+ return "Error: Please input text!", None
79
  show_memory_info("infer调用前")
80
  if language == '日本語':
81
  pass
 
114
  with gr.Row():
115
  with gr.Column():
116
  # We instantiate the Textbox class
117
+ textbox = gr.Textbox(label="Text", placeholder="Type your sentence here (Maximum 150 words)", value = "こんにちわ!", lines=2)
118
  # select character
119
+ char_dropdown = gr.Dropdown(choices=characters, value = "0:特别周", label='character')
120
+ language_dropdown = gr.Dropdown(choices=languages, value = "日本語", label='language')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
121
 
122
 
123
  duration_slider = gr.Slider(minimum=0.1, maximum=5, value=1, step=0.1, label='时长 Duration')