IAsistemofinteres commited on
Commit
ec4139e
·
verified ·
1 Parent(s): e679636

Upload 2 files

Browse files
Files changed (2) hide show
  1. xtts_my_model.py +249 -0
  2. xtts_train.py +401 -0
xtts_my_model.py ADDED
@@ -0,0 +1,249 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import os
3
+ import sys
4
+ import tempfile
5
+
6
+ import gradio as gr
7
+ import librosa.display
8
+ import numpy as np
9
+
10
+ import os
11
+ import torch
12
+ import torchaudio
13
+ import traceback
14
+ from TTS.demos.xtts_ft_demo.utils.formatter import format_audio_list
15
+ from TTS.demos.xtts_ft_demo.utils.gpt_train import train_gpt
16
+
17
+ from TTS.tts.configs.xtts_config import XttsConfig
18
+ from TTS.tts.models.xtts import Xtts
19
+
20
+
21
+ def clear_gpu_cache():
22
+ # clear the GPU cache
23
+ if torch.cuda.is_available():
24
+ torch.cuda.empty_cache()
25
+
26
+ XTTS_MODEL = None
27
+ def load_model(xtts_checkpoint, xtts_config, xtts_vocab):
28
+ global XTTS_MODEL
29
+ clear_gpu_cache()
30
+ if not xtts_checkpoint or not xtts_config or not xtts_vocab:
31
+ return "You need to run the previous steps or manually set the `XTTS checkpoint path`, `XTTS config path`, and `XTTS vocab path` fields !!"
32
+ config = XttsConfig()
33
+ config.load_json(xtts_config)
34
+ XTTS_MODEL = Xtts.init_from_config(config)
35
+ print("Loading XTTS model! ")
36
+ XTTS_MODEL.load_checkpoint(config, checkpoint_path=xtts_checkpoint, vocab_path=xtts_vocab, use_deepspeed=False)
37
+ if torch.cuda.is_available():
38
+ XTTS_MODEL.cuda()
39
+
40
+ print("Model Loaded!")
41
+ return "Model Loaded!"
42
+
43
+ def run_tts(lang, tts_text, speaker_audio_file):
44
+ if XTTS_MODEL is None or not speaker_audio_file:
45
+ return "You need to run the previous step to load the model !!", None, None
46
+
47
+ gpt_cond_latent, speaker_embedding = XTTS_MODEL.get_conditioning_latents(audio_path=speaker_audio_file, gpt_cond_len=XTTS_MODEL.config.gpt_cond_len, max_ref_length=XTTS_MODEL.config.max_ref_len, sound_norm_refs=XTTS_MODEL.config.sound_norm_refs)
48
+ out = XTTS_MODEL.inference(
49
+ text=tts_text,
50
+ language=lang,
51
+ gpt_cond_latent=gpt_cond_latent,
52
+ speaker_embedding=speaker_embedding,
53
+ temperature=XTTS_MODEL.config.temperature, # Add custom parameters here
54
+ length_penalty=XTTS_MODEL.config.length_penalty,
55
+ repetition_penalty=XTTS_MODEL.config.repetition_penalty,
56
+ top_k=XTTS_MODEL.config.top_k,
57
+ top_p=XTTS_MODEL.config.top_p,
58
+ )
59
+
60
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
61
+ out["wav"] = torch.tensor(out["wav"]).unsqueeze(0)
62
+ out_path = fp.name
63
+ torchaudio.save(out_path, out["wav"], 24000)
64
+
65
+ return "Speech generated !", out_path, speaker_audio_file
66
+
67
+
68
+
69
+
70
+ # define a logger to redirect
71
+ class Logger:
72
+ def __init__(self, filename="log.out"):
73
+ self.log_file = filename
74
+ self.terminal = sys.stdout
75
+ self.log = open(self.log_file, "w")
76
+
77
+ def write(self, message):
78
+ self.terminal.write(message)
79
+ self.log.write(message)
80
+
81
+ def flush(self):
82
+ self.terminal.flush()
83
+ self.log.flush()
84
+
85
+ def isatty(self):
86
+ return False
87
+
88
+ # redirect stdout and stderr to a file
89
+ sys.stdout = Logger()
90
+ sys.stderr = sys.stdout
91
+
92
+
93
+ # logging.basicConfig(stream=sys.stdout, level=logging.INFO)
94
+ import logging
95
+ logging.basicConfig(
96
+ level=logging.INFO,
97
+ format="%(asctime)s [%(levelname)s] %(message)s",
98
+ handlers=[
99
+ logging.StreamHandler(sys.stdout)
100
+ ]
101
+ )
102
+
103
+ def read_logs():
104
+ sys.stdout.flush()
105
+ with open(sys.stdout.log_file, "r") as f:
106
+ return f.read()
107
+
108
+
109
+ if __name__ == "__main__":
110
+
111
+ parser = argparse.ArgumentParser(
112
+ description="""XTTS fine-tuning demo\n\n"""
113
+ """
114
+ Example runs:
115
+ python3 TTS/demos/xtts_ft_demo/xtts_demo.py --port
116
+ """,
117
+ formatter_class=argparse.RawTextHelpFormatter,
118
+ )
119
+ parser.add_argument(
120
+ "--port",
121
+ type=int,
122
+ help="Port to run the gradio demo. Default: 5003",
123
+ default=5003,
124
+ )
125
+ parser.add_argument(
126
+ "--out_path",
127
+ type=str,
128
+ help="Output path (where data and checkpoints will be saved) Default: /tmp/xtts_ft/",
129
+ default="/tmp/xtts_ft/",
130
+ )
131
+
132
+ parser.add_argument(
133
+ "--num_epochs",
134
+ type=int,
135
+ help="Number of epochs to train. Default: 10",
136
+ default=10,
137
+ )
138
+ parser.add_argument(
139
+ "--batch_size",
140
+ type=int,
141
+ help="Batch size. Default: 4",
142
+ default=4,
143
+ )
144
+ parser.add_argument(
145
+ "--grad_acumm",
146
+ type=int,
147
+ help="Grad accumulation steps. Default: 1",
148
+ default=1,
149
+ )
150
+ parser.add_argument(
151
+ "--max_audio_length",
152
+ type=int,
153
+ help="Max permitted audio size in seconds. Default: 11",
154
+ default=11,
155
+ )
156
+
157
+ args = parser.parse_args()
158
+
159
+ language_names = {
160
+ "en": "English",
161
+ "es": "Spanish",
162
+ "fr": "French",
163
+ "de": "German",
164
+ "it": "Italian",
165
+ "pt": "Portuguese",
166
+ "pl": "Polish",
167
+ "tr": "Turkish",
168
+ "ru": "Russian",
169
+ "nl": "Dutch",
170
+ "cs": "Czech",
171
+ "ar": "Arabic",
172
+ "zh": "Chinese",
173
+ "hu": "Hungarian",
174
+ "ko": "Korean",
175
+ "ja": "Japanese",
176
+ }
177
+
178
+ with gr.Blocks() as demo:
179
+ with gr.Tab("Inference"):
180
+ with gr.Row():
181
+ with gr.Column() as col1:
182
+ xtts_checkpoint = gr.Textbox(
183
+ label="XTTS checkpoint path:",
184
+ value="/content/Modelo/best_model.pth",
185
+ )
186
+ xtts_config = gr.Textbox(
187
+ label="XTTS config path:",
188
+ value="/content/Modelo/config.json",
189
+ )
190
+
191
+ xtts_vocab = gr.Textbox(
192
+ label="XTTS vocab path:",
193
+ value="/content/Modelo/vocab.json",
194
+ )
195
+ progress_load = gr.Label(
196
+ label="Progress:"
197
+ )
198
+ load_btn = gr.Button(value="Load Fine-tuned XTTS model")
199
+
200
+ with gr.Column() as col2:
201
+ speaker_reference_audio = gr.File(
202
+ file_count="multiple",
203
+ label="Speaker reference audio (Supported formats: wav, mp3, and flac)",
204
+ )
205
+ tts_language = gr.Dropdown(
206
+ label="Language",
207
+ value="en",
208
+ choices=list(zip(language_names.values(), language_names.keys()))
209
+ )
210
+ tts_text = gr.Textbox(
211
+ label="Input Text.",
212
+ value="This model sounds really good and above all, it's reasonably fast.",
213
+ )
214
+ tts_btn = gr.Button(value="Step 4 - Inference")
215
+
216
+ with gr.Column() as col3:
217
+ progress_gen = gr.Label(
218
+ label="Progress:"
219
+ )
220
+ tts_output_audio = gr.Audio(label="Generated Audio.")
221
+ reference_audio = gr.Audio(label="Reference audio used.")
222
+
223
+
224
+ load_btn.click(
225
+ fn=load_model,
226
+ inputs=[
227
+ xtts_checkpoint,
228
+ xtts_config,
229
+ xtts_vocab
230
+ ],
231
+ outputs=[progress_load],
232
+ )
233
+
234
+ tts_btn.click(
235
+ fn=run_tts,
236
+ inputs=[
237
+ tts_language,
238
+ tts_text,
239
+ speaker_reference_audio,
240
+ ],
241
+ outputs=[progress_gen, tts_output_audio, reference_audio],
242
+ )
243
+
244
+ demo.launch(
245
+ share=True,
246
+ debug=False,
247
+ server_port=args.port,
248
+ server_name="0.0.0.0"
249
+ )
xtts_train.py ADDED
@@ -0,0 +1,401 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import argparse
2
+ import os
3
+ import sys
4
+ import tempfile
5
+
6
+ import gradio as gr
7
+ import librosa.display
8
+ import numpy as np
9
+
10
+ import os
11
+ import torch
12
+ import torchaudio
13
+ import traceback
14
+ from TTS.demos.xtts_ft_demo.utils.formatter import format_audio_list
15
+ from TTS.demos.xtts_ft_demo.utils.gpt_train import train_gpt
16
+
17
+ from TTS.tts.configs.xtts_config import XttsConfig
18
+ from TTS.tts.models.xtts import Xtts
19
+
20
+
21
+ def clear_gpu_cache():
22
+ # clear the GPU cache
23
+ if torch.cuda.is_available():
24
+ torch.cuda.empty_cache()
25
+
26
+ XTTS_MODEL = None
27
+ def load_model(xtts_checkpoint, xtts_config, xtts_vocab):
28
+ global XTTS_MODEL
29
+ clear_gpu_cache()
30
+ if not xtts_checkpoint or not xtts_config or not xtts_vocab:
31
+ return "You need to run the previous steps or manually set the `XTTS checkpoint path`, `XTTS config path`, and `XTTS vocab path` fields !!"
32
+ config = XttsConfig()
33
+ config.load_json(xtts_config)
34
+ XTTS_MODEL = Xtts.init_from_config(config)
35
+ print("Loading XTTS model! ")
36
+ XTTS_MODEL.load_checkpoint(config, checkpoint_path=xtts_checkpoint, vocab_path=xtts_vocab, use_deepspeed=False)
37
+ if torch.cuda.is_available():
38
+ XTTS_MODEL.cuda()
39
+
40
+ print("Model Loaded!")
41
+ return "Model Loaded!"
42
+
43
+ def run_tts(lang, tts_text, speaker_audio_file):
44
+ if XTTS_MODEL is None or not speaker_audio_file:
45
+ return "You need to run the previous step to load the model !!", None, None
46
+
47
+ gpt_cond_latent, speaker_embedding = XTTS_MODEL.get_conditioning_latents(audio_path=speaker_audio_file, gpt_cond_len=XTTS_MODEL.config.gpt_cond_len, max_ref_length=XTTS_MODEL.config.max_ref_len, sound_norm_refs=XTTS_MODEL.config.sound_norm_refs)
48
+ out = XTTS_MODEL.inference(
49
+ text=tts_text,
50
+ language=lang,
51
+ gpt_cond_latent=gpt_cond_latent,
52
+ speaker_embedding=speaker_embedding,
53
+ temperature=XTTS_MODEL.config.temperature, # Add custom parameters here
54
+ length_penalty=XTTS_MODEL.config.length_penalty,
55
+ repetition_penalty=XTTS_MODEL.config.repetition_penalty,
56
+ top_k=XTTS_MODEL.config.top_k,
57
+ top_p=XTTS_MODEL.config.top_p,
58
+ )
59
+
60
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
61
+ out["wav"] = torch.tensor(out["wav"]).unsqueeze(0)
62
+ out_path = fp.name
63
+ torchaudio.save(out_path, out["wav"], 24000)
64
+
65
+ return "Speech generated !", out_path, speaker_audio_file
66
+
67
+
68
+
69
+
70
+ # define a logger to redirect
71
+ class Logger:
72
+ def __init__(self, filename="log.out"):
73
+ self.log_file = filename
74
+ self.terminal = sys.stdout
75
+ self.log = open(self.log_file, "w")
76
+
77
+ def write(self, message):
78
+ self.terminal.write(message)
79
+ self.log.write(message)
80
+
81
+ def flush(self):
82
+ self.terminal.flush()
83
+ self.log.flush()
84
+
85
+ def isatty(self):
86
+ return False
87
+
88
+ # redirect stdout and stderr to a file
89
+ sys.stdout = Logger()
90
+ sys.stderr = sys.stdout
91
+
92
+
93
+ # logging.basicConfig(stream=sys.stdout, level=logging.INFO)
94
+ import logging
95
+ logging.basicConfig(
96
+ level=logging.INFO,
97
+ format="%(asctime)s [%(levelname)s] %(message)s",
98
+ handlers=[
99
+ logging.StreamHandler(sys.stdout)
100
+ ]
101
+ )
102
+
103
+ def read_logs():
104
+ sys.stdout.flush()
105
+ with open(sys.stdout.log_file, "r") as f:
106
+ return f.read()
107
+
108
+
109
+ if __name__ == "__main__":
110
+
111
+ parser = argparse.ArgumentParser(
112
+ description="""XTTS fine-tuning demo\n\n"""
113
+ """
114
+ Example runs:
115
+ python3 TTS/demos/xtts_ft_demo/xtts_demo.py --port
116
+ """,
117
+ formatter_class=argparse.RawTextHelpFormatter,
118
+ )
119
+ parser.add_argument(
120
+ "--port",
121
+ type=int,
122
+ help="Port to run the gradio demo. Default: 5003",
123
+ default=5003,
124
+ )
125
+ parser.add_argument(
126
+ "--out_path",
127
+ type=str,
128
+ help="Output path (where data and checkpoints will be saved) Default: /tmp/xtts_ft/",
129
+ default="/tmp/xtts_ft/",
130
+ )
131
+
132
+ parser.add_argument(
133
+ "--num_epochs",
134
+ type=int,
135
+ help="Number of epochs to train. Default: 10",
136
+ default=10,
137
+ )
138
+ parser.add_argument(
139
+ "--batch_size",
140
+ type=int,
141
+ help="Batch size. Default: 4",
142
+ default=4,
143
+ )
144
+ parser.add_argument(
145
+ "--grad_acumm",
146
+ type=int,
147
+ help="Grad accumulation steps. Default: 1",
148
+ default=1,
149
+ )
150
+ parser.add_argument(
151
+ "--max_audio_length",
152
+ type=int,
153
+ help="Max permitted audio size in seconds. Default: 11",
154
+ default=11,
155
+ )
156
+
157
+
158
+ args = parser.parse_args()
159
+
160
+ language_names = {
161
+ "en": "English",
162
+ "es": "Spanish",
163
+ "fr": "French",
164
+ "de": "German",
165
+ "it": "Italian",
166
+ "pt": "Portuguese",
167
+ "pl": "Polish",
168
+ "tr": "Turkish",
169
+ "ru": "Russian",
170
+ "nl": "Dutch",
171
+ "cs": "Czech",
172
+ "ar": "Arabic",
173
+ "zh": "Chinese",
174
+ "hu": "Hungarian",
175
+ "ko": "Korean",
176
+ "ja": "Japanese",
177
+ }
178
+
179
+ with gr.Blocks() as demo:
180
+ with gr.Tab("1 - Data processing"):
181
+ out_path = gr.Textbox(
182
+ label="Output path (where data and checkpoints will be saved):",
183
+ value=args.out_path,
184
+ )
185
+ # upload_file = gr.Audio(
186
+ # sources="upload",
187
+ # label="Select here the audio files that you want to use for XTTS trainining !",
188
+ # type="filepath",
189
+ # )
190
+ upload_file = gr.File(
191
+ file_count="multiple",
192
+ label="Select here the audio files that you want to use for XTTS trainining (Supported formats: wav, mp3, and flac)",
193
+ )
194
+ lang = gr.Dropdown(
195
+ label="Dataset Language",
196
+ value="en",
197
+ choices=list(zip(language_names.values(), language_names.keys()))
198
+ )
199
+ progress_data = gr.Label(
200
+ label="Progress:"
201
+ )
202
+ logs = gr.Textbox(
203
+ label="Logs:",
204
+ interactive=False,
205
+ )
206
+ demo.load(read_logs, None, logs, every=1)
207
+
208
+ prompt_compute_btn = gr.Button(value="Step 1 - Create dataset")
209
+
210
+ def preprocess_dataset(audio_path, language, out_path, progress=gr.Progress(track_tqdm=True)):
211
+ clear_gpu_cache()
212
+ out_path = os.path.join(out_path, "dataset")
213
+ os.makedirs(out_path, exist_ok=True)
214
+ if audio_path is None:
215
+ return "You should provide one or multiple audio files! If you provided it, probably the upload of the files is not finished yet!", "", ""
216
+ else:
217
+ try:
218
+ train_meta, eval_meta, audio_total_size = format_audio_list(audio_path, target_language=language, out_path=out_path, gradio_progress=progress)
219
+ except:
220
+ traceback.print_exc()
221
+ error = traceback.format_exc()
222
+ return f"The data processing was interrupted due an error !! Please check the console to verify the full error message! \n Error summary: {error}", "", ""
223
+
224
+ clear_gpu_cache()
225
+
226
+ # if audio total len is less than 2 minutes raise an error
227
+ if audio_total_size < 120:
228
+ message = "The sum of the duration of the audios that you provided should be at least 2 minutes!"
229
+ print(message)
230
+ return message, "", ""
231
+
232
+ print("Dataset Processed!")
233
+ return "Dataset Processed!", train_meta, eval_meta
234
+
235
+ with gr.Tab("2 - Fine-tuning XTTS Encoder"):
236
+ train_csv = gr.Textbox(
237
+ label="Train CSV:",
238
+ )
239
+ eval_csv = gr.Textbox(
240
+ label="Eval CSV:",
241
+ )
242
+ num_epochs = gr.Slider(
243
+ label="Number of epochs:",
244
+ minimum=1,
245
+ maximum=100,
246
+ step=1,
247
+ value=args.num_epochs,
248
+ )
249
+ batch_size = gr.Slider(
250
+ label="Batch size:",
251
+ minimum=2,
252
+ maximum=512,
253
+ step=1,
254
+ value=args.batch_size,
255
+ )
256
+ grad_acumm = gr.Slider(
257
+ label="Grad accumulation steps:",
258
+ minimum=2,
259
+ maximum=128,
260
+ step=1,
261
+ value=args.grad_acumm,
262
+ )
263
+ max_audio_length = gr.Slider(
264
+ label="Max permitted audio size in seconds:",
265
+ minimum=2,
266
+ maximum=20,
267
+ step=1,
268
+ value=args.max_audio_length,
269
+ )
270
+ progress_train = gr.Label(
271
+ label="Progress:"
272
+ )
273
+ logs_tts_train = gr.Textbox(
274
+ label="Logs:",
275
+ interactive=False,
276
+ )
277
+ demo.load(read_logs, None, logs_tts_train, every=1)
278
+ train_btn = gr.Button(value="Step 2 - Run the training")
279
+
280
+ def train_model(language, train_csv, eval_csv, num_epochs, batch_size, grad_acumm, output_path, max_audio_length):
281
+ clear_gpu_cache()
282
+ if not train_csv or not eval_csv:
283
+ return "You need to run the data processing step or manually set `Train CSV` and `Eval CSV` fields !", "", "", "", ""
284
+ try:
285
+ # convert seconds to waveform frames
286
+ max_audio_length = int(max_audio_length * 22050)
287
+ config_path, original_xtts_checkpoint, vocab_file, exp_path, speaker_wav = train_gpt(language, num_epochs, batch_size, grad_acumm, train_csv, eval_csv, output_path=output_path, max_audio_length=max_audio_length)
288
+ except:
289
+ traceback.print_exc()
290
+ error = traceback.format_exc()
291
+ return f"The training was interrupted due an error !! Please check the console to check the full error message! \n Error summary: {error}", "", "", "", ""
292
+
293
+ # copy original files to avoid parameters changes issues
294
+ os.system(f"cp {config_path} {exp_path}")
295
+ os.system(f"cp {vocab_file} {exp_path}")
296
+
297
+ ft_xtts_checkpoint = os.path.join(exp_path, "best_model.pth")
298
+ print("Model training done!")
299
+ clear_gpu_cache()
300
+ return "Model training done!", config_path, vocab_file, ft_xtts_checkpoint, speaker_wav
301
+
302
+ with gr.Tab("3 - Inference"):
303
+ with gr.Row():
304
+ with gr.Column() as col1:
305
+ xtts_checkpoint = gr.Textbox(
306
+ label="XTTS checkpoint path:",
307
+ value="/content/Modelo/best_model.pth",
308
+ )
309
+ xtts_config = gr.Textbox(
310
+ label="XTTS config path:",
311
+ value="/content/Modelo/config.json",
312
+ )
313
+
314
+ xtts_vocab = gr.Textbox(
315
+ label="XTTS vocab path:",
316
+ value="/content/Modelo/vocab.json",
317
+ )
318
+ progress_load = gr.Label(
319
+ label="Progress:"
320
+ )
321
+ load_btn = gr.Button(value="Step 3 - Load Fine-tuned XTTS model")
322
+
323
+ with gr.Column() as col2:
324
+ speaker_reference_audio = gr.File(
325
+ file_count="multiple",
326
+ label="Speaker reference audio (Supported formats: wav, mp3, and flac)",
327
+ )
328
+ tts_language = gr.Dropdown(
329
+ label="Language",
330
+ value="en",
331
+ choices=list(zip(language_names.values(), language_names.keys()))
332
+ )
333
+ tts_text = gr.Textbox(
334
+ label="Input Text.",
335
+ value="This model sounds really good and above all, it's reasonably fast.",
336
+ )
337
+ tts_btn = gr.Button(value="Step 4 - Inference")
338
+
339
+ with gr.Column() as col3:
340
+ progress_gen = gr.Label(
341
+ label="Progress:"
342
+ )
343
+ tts_output_audio = gr.Audio(label="Generated Audio.")
344
+ reference_audio = gr.Audio(label="Reference audio used.")
345
+
346
+ prompt_compute_btn.click(
347
+ fn=preprocess_dataset,
348
+ inputs=[
349
+ upload_file,
350
+ lang,
351
+ out_path,
352
+ ],
353
+ outputs=[
354
+ progress_data,
355
+ train_csv,
356
+ eval_csv,
357
+ ],
358
+ )
359
+
360
+
361
+ train_btn.click(
362
+ fn=train_model,
363
+ inputs=[
364
+ lang,
365
+ train_csv,
366
+ eval_csv,
367
+ num_epochs,
368
+ batch_size,
369
+ grad_acumm,
370
+ out_path,
371
+ max_audio_length,
372
+ ],
373
+ outputs=[progress_train, xtts_config, xtts_vocab, xtts_checkpoint, speaker_reference_audio],
374
+ )
375
+
376
+ load_btn.click(
377
+ fn=load_model,
378
+ inputs=[
379
+ xtts_checkpoint,
380
+ xtts_config,
381
+ xtts_vocab
382
+ ],
383
+ outputs=[progress_load],
384
+ )
385
+
386
+ tts_btn.click(
387
+ fn=run_tts,
388
+ inputs=[
389
+ tts_language,
390
+ tts_text,
391
+ speaker_reference_audio,
392
+ ],
393
+ outputs=[progress_gen, tts_output_audio, reference_audio],
394
+ )
395
+
396
+ demo.launch(
397
+ share=True,
398
+ debug=False,
399
+ server_port=args.port,
400
+ server_name="0.0.0.0"
401
+ )