barghavani commited on
Commit
a17d90e
1 Parent(s): 99371ec

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -114
app.py DELETED
@@ -1,114 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """app
3
-
4
- Automatically generated by Colaboratory.
5
-
6
- Original file is located at
7
- https://colab.research.google.com/drive/1LnYpxRP3tX4uiJ-gnE2YN6hhSdJ-rvTz
8
- """
9
-
10
- import tempfile ,os
11
- from TTS.config import load_config
12
- import gradio as gr
13
-
14
- from TTS.utils.manage import ModelManager
15
- from TTS.utils.synthesizer import Synthesizer
16
-
17
- MODEL_NAMES=[
18
- "vits male azure(best)",
19
- "common voice reduce",
20
- "vits arman ebook",
21
- #"persian-tts-grapheme-arm24-finetuned-on1",
22
- #"glowtts-male",
23
- #"glowtts-female",
24
- #"female tacotron2"
25
- ]
26
- MAX_TXT_LEN = 800
27
- model_path = os.getcwd() + "/best_model.pth"
28
- config_path = os.getcwd() + "/config.json"
29
-
30
-
31
-
32
- from TTS.utils.download import download_url
33
- modelInfo=[
34
- ["vits-male-azure","best_model_15934.pth","config.json","saillab/persian-tts-azure-grapheme-60K/resolve/main/"],
35
- ["common_voice_reduce","checkpoint_26000.pth","config.json","https://huggingface.co/saillab/persian-tts-cv15-reduct-grapheme-multispeaker/resolve/main/"],
36
- ["vits_arman_ebook","best_model_66651.pth","config.json","https://huggingface.co/saillab/persian-tts-grapheme-arm24-finetuned-on1/resolve/main/"]
37
- #["glowtts-female","best_model.pth","config.json","https://huggingface.co/Kamtera/persian-tts-female-glow_tts/resolve/main/"],
38
- #["vits male1 (best)","checkpoint_88000.pth","config.json","https://huggingface.co/Kamtera/persian-tts-male1-vits/resolve/main/"],
39
- #["vits female1","checkpoint_50000.pth","config.json","https://huggingface.co/Kamtera/persian-tts-female1-vits/resolve/main/"],
40
- #["female tacotron2","checkpoint_313000.pth","config.json","https://huggingface.co/Kamtera/persian-tts-female-tacotron2/resolve/main/"]
41
- ]
42
-
43
- for d in modelInfo:
44
- directory=d[0]
45
- if not os.path.exists(directory):
46
- os.makedirs(directory)
47
- print("|> Downloading: ",directory)
48
- download_url(
49
- d[3]+d[1],directory,"best_model.pth"
50
- )
51
- download_url(
52
- d[3]+d[2],directory,"config.json"
53
- )
54
- def tts(text: str,model_name: str):
55
- if len(text) > MAX_TXT_LEN:
56
- text = text[:MAX_TXT_LEN]
57
- print(f"Input text was cutoff since it went over the {MAX_TXT_LEN} character limit.")
58
- print(text)
59
-
60
-
61
- # synthesize
62
- synthesizer = Synthesizer(
63
- model_name+"/best_model.pth", model_name+"/config.json"
64
- )
65
- if synthesizer is None:
66
- raise NameError("model not found")
67
- wavs = synthesizer.tts(text)
68
- # return output
69
- with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
70
- synthesizer.save_wav(wavs, fp)
71
- return fp.name
72
-
73
- description="""
74
- This is a demo of persian text to speech model.
75
- **Github : https://github.com/UNHSAILLab/Persian-TTS **
76
- Models can be found here: <br>
77
- |Model|Dataset|
78
- |----|------|
79
- |["vits male azure(best)"](https://huggingface.co/saillab/persian-tts-azure-grapheme-60K)|
80
- |["common voice reduce"](https://huggingface.co/saillab/persian-tts-cv15-reduct-grapheme-multispeaker)|
81
- |["vits arman ebook"](https://huggingface.co/saillab/persian-tts-grapheme-arm24-finetuned-on1)|
82
-
83
- """
84
- article= ""
85
- examples=[
86
- ["و خداوند شما را با ارسال روح در جسم زندگانی و حیات بخشید","vits male azure(best)"],
87
- ["تاجر تو چه تجارت می کنی ، تو را چه که چه تجارت می کنم؟","vits male azure(best)"],
88
- ["شیش سیخ جیگر سیخی شیش هزار","vits male azure(best)"],
89
- ["سه شیشه شیر ، سه سیر سرشیر","vits male azure(best)"],
90
- ["دزدی دزدید ز بز دزدی بزی ، عجب دزدی که دزدید ز بز دزدی بزی","vits male azure(best)"],
91
- ["مثنوی یکی از قالب های شعری است ک هر بیت قافیه ی جداگانه دارد","vits male azure(best)"],
92
- ["در گلو ماند خس او سالها، چیست آن خس مهر جاه و مالها","vits male azure(best)"],
93
- ]
94
- iface = gr.Interface(
95
- fn=tts,
96
- inputs=[
97
- gr.Textbox(
98
- label="Text",
99
- value="برای گسترش زبان فارسی به ما بپیوندید و در این مسیر ما را یاری کنید",
100
- ),
101
- gr.Radio(
102
- label="Pick a TTS Model ",
103
- choices=MODEL_NAMES,
104
- value="vits-female",
105
- ),
106
- ],
107
- outputs=gr.Audio(label="Output",type='filepath'),
108
- examples=examples,
109
- title="🗣️ Persian tts 🗣️",
110
- description=description,
111
- article=article,
112
- live=False
113
- )
114
- iface.launch(share=False)