Nuno-Tome commited on
Commit
ef8da59
1 Parent(s): f085ca0

done, working vertion

Browse files
Files changed (3) hide show
  1. app.py +58 -6
  2. app_.py +262 -0
  3. requirements.txt +1 -1
app.py CHANGED
@@ -6,20 +6,72 @@ import json
6
  #from flask import Flask, jsonify
7
 
8
  DEBUG_MODE = False
 
 
9
 
 
 
 
 
 
 
10
 
 
 
 
 
 
11
 
12
- def echo(text, lang, request: gr.Request):
13
- output_text = {"report1": "SUCCESS"} # Initialize as a dictionary
14
- output_text["report3"] = text
15
-
16
 
17
  if request:
18
  # Convert headers to a dictionary and include them in the output_text
19
  output_text["headers"] = dict(request.headers.items())
20
-
21
 
22
  output_text_json = json.dumps(output_text)
23
  return output_text_json
24
 
25
- io = gr.Interface(echo, ["textarea", "textbox"], "json").launch(share=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  #from flask import Flask, jsonify
7
 
8
  DEBUG_MODE = False
9
+ TITLE = "《★~ N.N.F. Text To Speech V2 ~★ 》"
10
+ FAVICON = "https://aeiljuispo.cloudimg.io/v7/https://cdn-uploads.huggingface.co/production/uploads/65b453089151075ad87382ea/9NpWGb4xBrZovX1o7DF-5.jpeg"
11
 
12
+ INPUT_TEXT_PROMPT_EXAMPLE="""
13
+ Não sou nada,
14
+ não serei nada,
15
+ não posso querer ser nada.
16
+ À parte isso, tenho em mim todos os sonhos do mundo.
17
+ """
18
 
19
+ DECRIPTION = """
20
+ This is a simple Text To Speech (TTS) model that uses the XTTS model from Hugging Face.
21
+ You can use this model to generate audio from text in multiple languages.
22
+ It can be used as an API or as a standalone application.
23
+ """
24
 
25
+ def predict(text, lang, audio, request: gr.Request):
26
+ output_text = {"verdict ": "SUCCESS"} # Initialize as a dictionary
27
+ output_text["Text"] = text
28
+ output_text["Language"] = lang
29
 
30
  if request:
31
  # Convert headers to a dictionary and include them in the output_text
32
  output_text["headers"] = dict(request.headers.items())
 
33
 
34
  output_text_json = json.dumps(output_text)
35
  return output_text_json
36
 
37
+ io = gr.Interface(
38
+ fn=predict,
39
+ inputs=[
40
+ #definition of the input text to parse
41
+ gr.Textbox(
42
+ label="Text Prompt",
43
+ info="One or two sentences at a time is better",
44
+ value=INPUT_TEXT_PROMPT_EXAMPLE,
45
+ ),
46
+ gr.Dropdown(
47
+ label="Language",
48
+ info="Select an output language for the reader",
49
+ choices=[
50
+ "en",
51
+ "es",
52
+ "fr",
53
+ "it",
54
+ "pt",
55
+ "nl",
56
+ ],
57
+ #max_choices=1,
58
+ value="pt",
59
+ ),
60
+ #gr.Audio(
61
+ # label="Reference Audio",
62
+ # info="Click on the ✎ button to upload your own target speaker audio",
63
+ # type="filepath",
64
+ # value="examples/female.wav",
65
+ #),
66
+ ],
67
+ outputs=[
68
+ #gr.Video(label="Waveform Visual"),
69
+ "json",
70
+ ],
71
+ title=TITLE,
72
+ description=DECRIPTION,
73
+ #favicon_path=FAVICON,
74
+ #article=article,
75
+ #cache_examples=False,
76
+ #examples=examples,
77
+ ).queue().launch(share=True)
app_.py ADDED
@@ -0,0 +1,262 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #from https://huggingface.co/spaces/kerncraze/XTTS_V1_CPU/tree/main
2
+ import sys
3
+ import os
4
+ # By using XTTS you agree to CPML license https://coqui.ai/cpml
5
+ os.environ["COQUI_TOS_AGREED"] = "1"
6
+
7
+ import gradio as gr
8
+ from TTS.api import TTS
9
+
10
+ model_names = TTS().list_models()
11
+ m = model_names[0]
12
+ #print(model_names)
13
+ print(os.system("pip show TTS"))
14
+ print(f"Model: {m}")
15
+ tts = TTS(m, gpu=False)
16
+ tts.to("cpu") # no GPU or Amd
17
+ #tts.to("cuda") # cuda only
18
+
19
+ def predict(prompt, language, audio_file_pth, mic_file_path, use_mic, agree):
20
+ if agree == True:
21
+ if use_mic == True:
22
+ if mic_file_path is not None:
23
+ speaker_wav=mic_file_path
24
+ else:
25
+ gr.Warning("Please record your voice with Microphone, or uncheck Use Microphone to use reference audios")
26
+ return (
27
+ None,
28
+ None,
29
+ )
30
+
31
+ else:
32
+ speaker_wav=audio_file_pth
33
+
34
+ if len(prompt)<2:
35
+ gr.Warning("Please give a longer prompt text")
36
+ return (
37
+ None,
38
+ None,
39
+ )
40
+ if len(prompt)>10000:
41
+ gr.Warning("Text length limited to 10000 characters for this demo, please try shorter text")
42
+ return (
43
+ None,
44
+ None,
45
+ )
46
+ try:
47
+ if language == "fr":
48
+ if m.find("your") != -1:
49
+ language = "fr-fr"
50
+ if m.find("/fr/") != -1:
51
+ language = None
52
+ tts.tts_to_file(
53
+ text=prompt,
54
+ file_path="output.wav",
55
+ speaker_wav=speaker_wav,
56
+ language=language
57
+ )
58
+ except RuntimeError as e :
59
+ if "device-assert" in str(e):
60
+ # cannot do anything on cuda device side error, need tor estart
61
+ gr.Warning("Unhandled Exception encounter, please retry in a minute")
62
+ print("Cuda device-assert Runtime encountered need restart")
63
+ sys.exit("Exit due to cuda device-assert")
64
+ else:
65
+ raise e
66
+
67
+ return (
68
+ gr.make_waveform(
69
+ audio="output.wav",
70
+ ),
71
+ "output.wav",
72
+ )
73
+ else:
74
+ gr.Warning("Please accept the Terms & Condition!")
75
+ return (
76
+ None,
77
+ None,
78
+ )
79
+
80
+
81
+ title = "XTTS Glz's remake (Fonctional Text-2-Speech)"
82
+
83
+ description = """
84
+ <a href="https://huggingface.co/coqui/XTTS-v1">XTTS</a> is a Voice generation model that lets you clone voices into different languages by using just a quick 3-second audio clip.
85
+ <br/>
86
+ XTTS is built on previous research, like Tortoise, with additional architectural innovations and training to make cross-language voice cloning and multilingual speech generation possible.
87
+ <br/>
88
+ This is the same model that powers our creator application <a href="https://coqui.ai">Coqui Studio</a> as well as the <a href="https://docs.coqui.ai">Coqui API</a>. In production we apply modifications to make low-latency streaming possible.
89
+ <br/>
90
+ Leave a star on the Github <a href="https://github.com/coqui-ai/TTS">TTS</a>, where our open-source inference and training code lives.
91
+ <br/>
92
+ <p>For faster inference without waiting in the queue, you should duplicate this space and upgrade to GPU via the settings.
93
+ <br/>
94
+ <a href="https://huggingface.co/spaces/coqui/xtts?duplicate=true">
95
+ <img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
96
+ </p>
97
+ """
98
+
99
+ article = """
100
+ <div style='margin:20px auto;'>
101
+ <p>By using this demo you agree to the terms of the Coqui Public Model License at https://coqui.ai/cpml</p>
102
+ </div>
103
+ """
104
+ examples = [
105
+ [
106
+ "Hello, World !, here is an example of light voice cloning. Try to upload your best audio samples quality",
107
+ "en",
108
+ "examples/female.wav",
109
+ None,
110
+ False,
111
+ True,
112
+ ],
113
+ [
114
+ "Je suis un lycéen français de 17 ans, passioner par la Cyber-Sécuritée et les models d'IA.",
115
+ "fr",
116
+ "examples/male.wav",
117
+ None,
118
+ False,
119
+ True,
120
+ ],
121
+ [
122
+ "Als ich sechs war, sah ich einmal ein wunderbares Bild",
123
+ "de",
124
+ "examples/female.wav",
125
+ None,
126
+ False,
127
+ True,
128
+ ],
129
+ [
130
+ "Cuando tenía seis años, vi una vez una imagen magnífica",
131
+ "es",
132
+ "examples/male.wav",
133
+ None,
134
+ False,
135
+ True,
136
+ ],
137
+ [
138
+ "Quando eu tinha seis anos eu vi, uma vez, uma imagem magnífica",
139
+ "pt",
140
+ "examples/female.wav",
141
+ None,
142
+ False,
143
+ True,
144
+ ],
145
+ [
146
+ "Kiedy miałem sześć lat, zobaczyłem pewnego razu wspaniały obrazek",
147
+ "pl",
148
+ "examples/male.wav",
149
+ None,
150
+ False,
151
+ True,
152
+ ],
153
+ [
154
+ "Un tempo lontano, quando avevo sei anni, vidi un magnifico disegno",
155
+ "it",
156
+ "examples/female.wav",
157
+ None,
158
+ False,
159
+ True,
160
+ ],
161
+ [
162
+ "Bir zamanlar, altı yaşındayken, muhteşem bir resim gördüm",
163
+ "tr",
164
+ "examples/female.wav",
165
+ None,
166
+ False,
167
+ True,
168
+ ],
169
+ [
170
+ "Когда мне было шесть лет, я увидел однажды удивительную картинку",
171
+ "ru",
172
+ "examples/female.wav",
173
+ None,
174
+ False,
175
+ True,
176
+ ],
177
+ [
178
+ "Toen ik een jaar of zes was, zag ik op een keer een prachtige plaat",
179
+ "nl",
180
+ "examples/male.wav",
181
+ None,
182
+ False,
183
+ True,
184
+ ],
185
+ [
186
+ "Když mi bylo šest let, viděl jsem jednou nádherný obrázek",
187
+ "cs",
188
+ "examples/female.wav",
189
+ None,
190
+ False,
191
+ True,
192
+ ],
193
+ [
194
+ "当我还只有六岁的时候, 看到了一副精彩的插画",
195
+ "zh-cn",
196
+ "examples/female.wav",
197
+ None,
198
+ False,
199
+ True,
200
+ ],
201
+ ]
202
+
203
+
204
+
205
+ gr.Interface(
206
+ fn=predict,
207
+ inputs=[
208
+ gr.Textbox(
209
+ label="Text Prompt",
210
+ info="One or two sentences at a time is better",
211
+ value="Hello, World !, here is an example of light voice cloning. Try to upload your best audio samples quality",
212
+ ),
213
+ gr.Dropdown(
214
+ label="Language",
215
+ info="Select an output language for the synthesised speech",
216
+ choices=[
217
+ "en",
218
+ "es",
219
+ "fr",
220
+ "de",
221
+ "it",
222
+ "pt",
223
+ "pl",
224
+ "tr",
225
+ "ru",
226
+ "nl",
227
+ "cs",
228
+ "ar",
229
+ "zh-cn",
230
+ ],
231
+ max_choices=1,
232
+ value="en",
233
+ ),
234
+ gr.Audio(
235
+ label="Reference Audio",
236
+ info="Click on the ✎ button to upload your own target speaker audio",
237
+ type="filepath",
238
+ value="examples/female.wav",
239
+ ),
240
+ gr.Audio(source="microphone",
241
+ type="filepath",
242
+ info="Use your microphone to record audio",
243
+ label="Use Microphone for Reference"),
244
+ gr.Checkbox(label="Check to use Microphone as Reference",
245
+ value=False,
246
+ info="Notice: Microphone input may not work properly under traffic",),
247
+ gr.Checkbox(
248
+ label="Agree",
249
+ value=True,
250
+ info="I agree to the terms of the Coqui Public Model License at https://coqui.ai/cpml",
251
+ ),
252
+ ],
253
+ outputs=[
254
+ gr.Video(label="Waveform Visual"),
255
+ gr.Audio(label="Synthesised Audio"),
256
+ ],
257
+ title=title,
258
+ description=description,
259
+ article=article,
260
+ cache_examples=False,
261
+ examples=examples,
262
+ ).queue().launch(debug=True, show_error=True)
requirements.txt CHANGED
@@ -4,4 +4,4 @@ bark
4
  #numpy
5
  #share_btn
6
  flask
7
- #bark.generation
 
4
  #numpy
5
  #share_btn
6
  flask
7
+ #bark.generation