Kamtera commited on
Commit
34fce4e
1 Parent(s): 3d3ba6d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -15
app.py CHANGED
@@ -6,25 +6,47 @@ import gradio as gr
6
  from TTS.utils.manage import ModelManager
7
  from TTS.utils.synthesizer import Synthesizer
8
 
9
-
 
 
 
 
 
10
  MAX_TXT_LEN = 800
11
  model_path = os.getcwd() + "/best_model.pth"
12
  config_path = os.getcwd() + "/config.json"
13
 
14
- synthesizer = Synthesizer(
15
- model_path, config_path
16
- )
17
 
18
 
19
- def tts(text: str):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  if len(text) > MAX_TXT_LEN:
21
  text = text[:MAX_TXT_LEN]
22
  print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
23
  print(text)
24
 
25
 
26
-
27
  # synthesize
 
 
 
28
  if synthesizer is None:
29
  raise NameError("model not found")
30
  wavs = synthesizer.tts(text)
@@ -37,20 +59,28 @@ def tts(text: str):
37
  description="""
38
  This is a demo of persian text to speech model.
39
 
40
- Model can be found here: https://huggingface.co/Kamtera/persian-tts-female-glow_tts
 
 
 
 
41
 
42
- Model trained on this dataset : https://www.kaggle.com/datasets/magnoliasis/persian-tts-dataset-famale
 
 
43
 
44
 
45
 
46
  """
47
  article= ""
48
  examples=[
49
- ["شیش سیخ جیگر سیخی شیش هزار"],
50
- ["سه شیشه شیر ، سه سیر سرشیر"],
51
- ["دزدی دزدید ز بز دزدی بزی ، عجب دزدی که دزدید ز بز دزدی بزی"],
52
- ["مثنوی یکی از قالب های شعری است ک هر بیت قافیه ی جداگانه دارد"],
53
- ["در گلو ماند خس او سالها، چیست آن خس مهر جاه و مالها"],
 
 
54
  ]
55
  iface = gr.Interface(
56
  fn=tts,
@@ -58,11 +88,16 @@ iface = gr.Interface(
58
  gr.Textbox(
59
  label="Text",
60
  value="زندگی فقط یک بار است؛ از آن به خوبی استفاده کن",
61
- )
 
 
 
 
 
62
  ],
63
  outputs=gr.Audio(label="Output",type='filepath'),
64
  examples=examples,
65
- title="🗣️Persian ttt - glow_tts 🗣️",
66
  description=description,
67
  article=article,
68
  live=False
 
6
  from TTS.utils.manage import ModelManager
7
  from TTS.utils.synthesizer import Synthesizer
8
 
9
+ MODEL_NAMES=[
10
+ "vits-male",
11
+ "vits-female",
12
+ "glowtts-male",
13
+ "glowtts-female"
14
+ ]
15
  MAX_TXT_LEN = 800
16
  model_path = os.getcwd() + "/best_model.pth"
17
  config_path = os.getcwd() + "/config.json"
18
 
 
 
 
19
 
20
 
21
+ from TTS.utils.download import download_url
22
+ modelInfo=[
23
+ ["vits-male","best_model_65633.pth","config-0.json","https://huggingface.co/Kamtera/persian-tts-male-vits/resolve/main/"],
24
+ ["vits-female","checkpoint_48000.pth","config-2.json","https://huggingface.co/Kamtera/persian-tts-female-vits/resolve/main/"],
25
+ ["glowtts-male","best_model_77797.pth","config-1.json","https://huggingface.co/Kamtera/persian-tts-male-glow_tts/resolve/main/"],
26
+ ["glowtts-female","best_model.pth","config.json","https://huggingface.co/Kamtera/persian-tts-female-glow_tts/resolve/main/"]
27
+ ]
28
+
29
+ for d in modelInfo:
30
+ directory=d[0]
31
+ if not os.path.exists(directory):
32
+ os.makedirs(directory)
33
+ download_url(
34
+ d[3]+d[1],directory,"best_model.pth"
35
+ )
36
+ download_url(
37
+ d[3]+d[2],directory,"config.json"
38
+ )
39
+ def tts(text: str,model_name: str):
40
  if len(text) > MAX_TXT_LEN:
41
  text = text[:MAX_TXT_LEN]
42
  print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
43
  print(text)
44
 
45
 
 
46
  # synthesize
47
+ synthesizer = Synthesizer(
48
+ model_name+"/best_model.pth", model_name+"/config.json"
49
+ )
50
  if synthesizer is None:
51
  raise NameError("model not found")
52
  wavs = synthesizer.tts(text)
 
59
  description="""
60
  This is a demo of persian text to speech model.
61
 
62
+ Models can be found here:
63
+ https://huggingface.co/Kamtera/persian-tts-female-vits
64
+ https://huggingface.co/Kamtera/persian-tts-male-vits
65
+ https://huggingface.co/Kamtera/persian-tts-male-glow_tts
66
+ https://huggingface.co/Kamtera/persian-tts-female-glow_tts
67
 
68
+ Models trained on these datasets :
69
+ https://www.kaggle.com/datasets/magnoliasis/persian-tts-dataset
70
+ https://www.kaggle.com/datasets/magnoliasis/persian-tts-dataset-famale
71
 
72
 
73
 
74
  """
75
  article= ""
76
  examples=[
77
+ ["و خداوند شما را با ارسال روح در جسم زندگانی و حیات بخشید","vits-male"],
78
+ ["تاجر تو چه تجارت می کنی ، تو را چه که چه تجارت می کنم؟","vits-female"],
79
+ ["شیش سیخ جیگر سیخی شیش هزار","vits-female"],
80
+ ["سه شیشه شیر ، سه سیر سرشیر","vits-female"],
81
+ ["دزدی دزدید ز بز دزدی بزی ، عجب دزدی که دزدید ز بز دزدی بزی","vits-female"],
82
+ ["مثنوی یکی از قالب های شعری است ک هر بیت قافیه ی جداگانه دارد","vits-female"],
83
+ ["در گلو ماند خس او سالها، چیست آن خس مهر جاه و مالها","vits-female"],
84
  ]
85
  iface = gr.Interface(
86
  fn=tts,
 
88
  gr.Textbox(
89
  label="Text",
90
  value="زندگی فقط یک بار است؛ از آن به خوبی استفاده کن",
91
+ ),
92
+ gr.Radio(
93
+ label="Pick a TTS Model ",
94
+ choices=MODEL_NAMES,
95
+ value="vits-female",
96
+ ),
97
  ],
98
  outputs=gr.Audio(label="Output",type='filepath'),
99
  examples=examples,
100
+ title="🗣️ Persian tts 🗣️",
101
  description=description,
102
  article=article,
103
  live=False