eBlessings commited on
Commit
c03ab73
·
verified ·
1 Parent(s): 81d5048

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +547 -0
app.py ADDED
@@ -0,0 +1,547 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ruff: noqa: E402
2
+ import json
3
+ import re
4
+ import tempfile
5
+ from collections import OrderedDict
6
+ from importlib.resources import files
7
+ from pydub import AudioSegment, silence
8
+
9
+ import click
10
+ import gradio as gr
11
+ import numpy as np
12
+ import soundfile as sf
13
+ import torchaudio
14
+ from cached_path import cached_path
15
+ from transformers import AutoModelForCausalLM, AutoTokenizer
16
+
17
+ try:
18
+ import spaces
19
+ USING_SPACES = True
20
+ except ImportError:
21
+ USING_SPACES = False
22
+
23
+ def gpu_decorator(func):
24
+ if USING_SPACES:
25
+ return spaces.GPU(func)
26
+ else:
27
+ return func
28
+
29
+ # ========== CORE CONFIGURATION ========== #
30
+ DEFAULT_TTS_MODEL = "F5-TTS"
31
+ DEFAULT_TTS_MODEL_CFG = [
32
+ "hf://SWivid/F5-TTS/F5TTS_Base/model_1200000.safetensors",
33
+ "hf://SWivid/F5-TTS/F5TTS_Base/vocab.txt",
34
+ json.dumps(dict(dim=1024, depth=22, heads=16, ff_mult=2, text_dim=512, conv_layers=4)),
35
+ ]
36
+
37
+ last_used_custom = files("f5_tts").joinpath("infer/.cache/last_used_custom_model_info.txt")
38
+ tts_model_choice = DEFAULT_TTS_MODEL
39
+ target_sample_rate = 24000
40
+
41
+ # ========== CUSTOM MODEL HANDLING ========== #
42
+ def load_last_used_custom():
43
+ try:
44
+ with open(last_used_custom, "r", encoding="utf-8") as f:
45
+ return [line.strip() for line in f.readlines()]
46
+ except FileNotFoundError:
47
+ last_used_custom.parent.mkdir(parents=True, exist_ok=True)
48
+ return DEFAULT_TTS_MODEL_CFG
49
+
50
+ def set_custom_model(custom_ckpt_path, custom_vocab_path, custom_model_cfg):
51
+ global tts_model_choice
52
+ tts_model_choice = [
53
+ "Custom",
54
+ custom_ckpt_path,
55
+ custom_vocab_path,
56
+ json.loads(custom_model_cfg)
57
+ ]
58
+ with open(last_used_custom, "w", encoding="utf-8") as f:
59
+ f.write("\n".join([custom_ckpt_path, custom_vocab_path, custom_model_cfg]))
60
+
61
+ def switch_tts_model(new_choice):
62
+ global tts_model_choice
63
+ if new_choice == "Custom":
64
+ custom_config = load_last_used_custom()
65
+ tts_model_choice = ["Custom"] + custom_config
66
+ return (
67
+ gr.update(visible=True, value=custom_config[0]),
68
+ gr.update(visible=True, value=custom_config[1]),
69
+ gr.update(visible=True, value=custom_config[2])
70
+ )
71
+ else:
72
+ tts_model_choice = new_choice
73
+ return (
74
+ gr.update(visible=False),
75
+ gr.update(visible=False),
76
+ gr.update(visible=False)
77
+ )
78
+
79
+ # ========== MODEL LOADING ========== #
80
+ from f5_tts.model import DiT, UNetT
81
+ from f5_tts.infer.utils_infer import (
82
+ load_vocoder,
83
+ load_model,
84
+ preprocess_ref_audio_text,
85
+ infer_process,
86
+ remove_silence_for_generated_wav,
87
+ save_spectrogram,
88
+ )
89
+
90
+ vocoder = load_vocoder()
91
+
92
+ def load_f5tts(ckpt_path=str(cached_path(DEFAULT_TTS_MODEL_CFG[0]))):
93
+ return load_model(DiT, json.loads(DEFAULT_TTS_MODEL_CFG[2]), ckpt_path)
94
+
95
+ def load_e2tts(ckpt_path=str(cached_path("hf://SWivid/E2-TTS/E2TTS_Base/model_1200000.safetensors"))):
96
+ E2TTS_model_cfg = dict(dim=1024, depth=24, heads=16, ff_mult=4)
97
+ return load_model(UNetT, E2TTS_model_cfg, ckpt_path)
98
+
99
+ F5TTS_ema_model = load_f5tts()
100
+ E2TTS_ema_model = load_e2tts() if USING_SPACES else None
101
+ custom_ema_model, pre_custom_path = None, ""
102
+
103
+ # ========== CORE INFERENCE FUNCTION ========== #
104
+ @gpu_decorator
105
+ def generate_response(messages, model, tokenizer):
106
+ """Generate response using Qwen"""
107
+ text = tokenizer.apply_chat_template(
108
+ messages,
109
+ tokenize=False,
110
+ add_generation_prompt=True,
111
+ )
112
+
113
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
114
+ generated_ids = model.generate(
115
+ **model_inputs,
116
+ max_new_tokens=512,
117
+ temperature=0.7,
118
+ top_p=0.95,
119
+ )
120
+
121
+ generated_ids = [
122
+ output_ids[len(input_ids) :] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
123
+ ]
124
+ return tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
125
+
126
+
127
+ @gpu_decorator
128
+ def infer(
129
+ ref_audio_orig,
130
+ ref_text,
131
+ gen_text,
132
+ model,
133
+ remove_silence,
134
+ cross_fade_duration=0.15,
135
+ nfe_step=32,
136
+ speed=1,
137
+ show_info=gr.Info,
138
+ ):
139
+ if not ref_audio_orig:
140
+ gr.Warning("Please provide reference audio.")
141
+ return gr.update(), gr.update(), ref_text
142
+
143
+ if not gen_text.strip():
144
+ gr.Warning("Please enter text to generate.")
145
+ return gr.update(), gr.update(), ref_text
146
+
147
+ ref_audio, ref_text = preprocess_ref_audio_text(ref_audio_orig, ref_text, show_info=show_info)
148
+
149
+ if model == "F5-TTS":
150
+ ema_model = F5TTS_ema_model
151
+ elif model == "E2-TTS":
152
+ global E2TTS_ema_model
153
+ if E2TTS_ema_model is None:
154
+ show_info("Loading E2-TTS model...")
155
+ E2TTS_ema_model = load_e2tts()
156
+ ema_model = E2TTS_ema_model
157
+ elif isinstance(model, list) and model[0] == "Custom":
158
+ assert not USING_SPACES, "Only official checkpoints allowed in Spaces."
159
+ global custom_ema_model, pre_custom_path
160
+ if pre_custom_path != model[1]:
161
+ show_info("Loading Custom TTS model...")
162
+ custom_ema_model = load_custom(model[1], vocab_path=model[2], model_cfg=model[3])
163
+ pre_custom_path = model[1]
164
+ ema_model = custom_ema_model
165
+
166
+ final_wave, final_sample_rate, combined_spectrogram = infer_process(
167
+ ref_audio,
168
+ ref_text,
169
+ gen_text,
170
+ ema_model,
171
+ vocoder,
172
+ cross_fade_duration=cross_fade_duration,
173
+ nfe_step=nfe_step,
174
+ speed=speed,
175
+ show_info=show_info,
176
+ progress=gr.Progress(),
177
+ )
178
+
179
+ # Remove silence
180
+ if remove_silence:
181
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as f:
182
+ sf.write(f.name, final_wave, final_sample_rate)
183
+ remove_silence_for_generated_wav(f.name)
184
+ final_wave, _ = torchaudio.load(f.name)
185
+ final_wave = final_wave.squeeze().cpu().numpy()
186
+
187
+ # Save the spectrogram
188
+ with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as tmp_spectrogram:
189
+ spectrogram_path = tmp_spectrogram.name
190
+ save_spectrogram(combined_spectrogram, spectrogram_path)
191
+
192
+ return (final_sample_rate, final_wave), spectrogram_path, ref_text
193
+ # ========== PODCAST UI WITH 10 SPEAKERS ========== #
194
+ with gr.Blocks() as app_podcast:
195
+ gr.Markdown("# Podcast Generation (10 Speakers)")
196
+ with gr.Row():
197
+ with gr.Column():
198
+ speaker1_name = gr.Textbox(label="Speaker 1 Name", placeholder="e.g. John")
199
+ ref_audio_input1 = gr.Audio(label="Reference Audio 1", type="filepath")
200
+ ref_text_input1 = gr.Textbox(label="Reference Text 1", lines=2)
201
+ with gr.Column():
202
+ speaker2_name = gr.Textbox(label="Speaker 2 Name", placeholder="e.g. Sarah")
203
+ ref_audio_input2 = gr.Audio(label="Reference Audio 2", type="filepath")
204
+ ref_text_input2 = gr.Textbox(label="Reference Text 2", lines=2)
205
+ with gr.Column():
206
+ speaker3_name = gr.Textbox(label="Speaker 3 Name", placeholder="e.g. Alex")
207
+ ref_audio_input3 = gr.Audio(label="Reference Audio 3", type="filepath")
208
+ ref_text_input3 = gr.Textbox(label="Reference Text 3", lines=2)
209
+ with gr.Column():
210
+ speaker4_name = gr.Textbox(label="Speaker 4 Name", placeholder="e.g. Jane")
211
+ ref_audio_input4 = gr.Audio(label="Reference Audio 4", type="filepath")
212
+ ref_text_input4 = gr.Textbox(label="Reference Text 4", lines=2)
213
+ with gr.Column():
214
+ speaker5_name = gr.Textbox(label="Speaker 5 Name", placeholder="e.g. Mike")
215
+ ref_audio_input5 = gr.Audio(label="Reference Audio 5", type="filepath")
216
+ ref_text_input5 = gr.Textbox(label="Reference Text 5", lines=2)
217
+ with gr.Row():
218
+ with gr.Column():
219
+ speaker6_name = gr.Textbox(label="Speaker 6 Name", placeholder="e.g. Anna")
220
+ ref_audio_input6 = gr.Audio(label="Reference Audio 6", type="filepath")
221
+ ref_text_input6 = gr.Textbox(label="Reference Text 6", lines=2)
222
+ with gr.Column():
223
+ speaker7_name = gr.Textbox(label="Speaker 7 Name", placeholder="e.g. Bob")
224
+ ref_audio_input7 = gr.Audio(label="Reference Audio 7", type="filepath")
225
+ ref_text_input7 = gr.Textbox(label="Reference Text 7", lines=2)
226
+ with gr.Column():
227
+ speaker8_name = gr.Textbox(label="Speaker 8 Name", placeholder="e.g. Carol")
228
+ ref_audio_input8 = gr.Audio(label="Reference Audio 8", type="filepath")
229
+ ref_text_input8 = gr.Textbox(label="Reference Text 8", lines=2)
230
+ with gr.Column():
231
+ speaker9_name = gr.Textbox(label="Speaker 9 Name", placeholder="e.g. Dave")
232
+ ref_audio_input9 = gr.Audio(label="Reference Audio 9", type="filepath")
233
+ ref_text_input9 = gr.Textbox(label="Reference Text 9", lines=2)
234
+ with gr.Column():
235
+ speaker10_name = gr.Textbox(label="Speaker 10 Name", placeholder="e.g. Emma")
236
+ ref_audio_input10 = gr.Audio(label="Reference Audio 10", type="filepath")
237
+ ref_text_input10 = gr.Textbox(label="Reference Text 10", lines=2)
238
+
239
+ script_input = gr.Textbox(
240
+ label="Podcast Script",
241
+ lines=10,
242
+ placeholder="Format:\nSpeaker1: Hello...\nSpeaker2: Hi...\n... Speaker10: Goodbye...\n"
243
+ )
244
+
245
+ with gr.Row():
246
+ podcast_model_choice = gr.Radio(
247
+ choices=["F5-TTS", "E2-TTS"],
248
+ label="TTS Model",
249
+ value="F5-TTS"
250
+ )
251
+ podcast_remove_silence = gr.Checkbox(
252
+ label="Remove Silences Between Dialogues",
253
+ value=True
254
+ )
255
+
256
+ generate_podcast_btn = gr.Button("Generate Podcast", variant="primary")
257
+ podcast_output = gr.Audio(label="Generated Podcast", autoplay=True)
258
+
259
+ @gpu_decorator
260
+ def generate_podcast(
261
+ script,
262
+ speaker1,
263
+ ref_audio1,
264
+ ref_text1,
265
+ speaker2,
266
+ ref_audio2,
267
+ ref_text2,
268
+ speaker3,
269
+ ref_audio3,
270
+ ref_text3,
271
+ speaker4,
272
+ ref_audio4,
273
+ ref_text4,
274
+ speaker5,
275
+ ref_audio5,
276
+ ref_text5,
277
+ speaker6,
278
+ ref_audio6,
279
+ ref_text6,
280
+ speaker7,
281
+ ref_audio7,
282
+ ref_text7,
283
+ speaker8,
284
+ ref_audio8,
285
+ ref_text8,
286
+ speaker9,
287
+ ref_audio9,
288
+ ref_text9,
289
+ speaker10,
290
+ ref_audio10,
291
+ ref_text10,
292
+ model,
293
+ remove_silence
294
+ ):
295
+ # Validate inputs
296
+ if not all([speaker1, speaker2, speaker3, speaker4, speaker5, speaker6, speaker7, speaker8, speaker9, speaker10]):
297
+ raise gr.Error("All ten speaker names must be provided")
298
+ if not all([ref_audio1, ref_audio2, ref_audio3, ref_audio4, ref_audio5, ref_audio6, ref_audio7, ref_audio8, ref_audio9, ref_audio10]):
299
+ raise gr.Error("All ten reference audios must be provided")
300
+
301
+ # Split script using regex pattern for 10 speakers
302
+ pattern = re.compile(
303
+ f"({re.escape(speaker1)}:|{re.escape(speaker2)}:|{re.escape(speaker3)}:|{re.escape(speaker4)}:|{re.escape(speaker5)}:|{re.escape(speaker6)}:|{re.escape(speaker7)}:|{re.escape(speaker8)}:|{re.escape(speaker9)}:|{re.escape(speaker10)}:)"
304
+ )
305
+ speaker_blocks = pattern.split(script)[1:]
306
+
307
+ generated_audio_segments = []
308
+ speaker_map = {
309
+ speaker1: {"audio": ref_audio1, "text": ref_text1},
310
+ speaker2: {"audio": ref_audio2, "text": ref_text2},
311
+ speaker3: {"audio": ref_audio3, "text": ref_text3},
312
+ speaker4: {"audio": ref_audio4, "text": ref_text4},
313
+ speaker5: {"audio": ref_audio5, "text": ref_text5},
314
+ speaker6: {"audio": ref_audio6, "text": ref_text6},
315
+ speaker7: {"audio": ref_audio7, "text": ref_text7},
316
+ speaker8: {"audio": ref_audio8, "text": ref_text8},
317
+ speaker9: {"audio": ref_audio9, "text": ref_text9},
318
+ speaker10: {"audio": ref_audio10, "text": ref_text10}
319
+ }
320
+
321
+ for i in range(0, len(speaker_blocks), 2):
322
+ if i+1 >= len(speaker_blocks):
323
+ break
324
+
325
+ speaker_tag = speaker_blocks[i].strip(":")
326
+ text = speaker_blocks[i+1].strip()
327
+
328
+ # Get speaker config
329
+ config = speaker_map.get(speaker_tag)
330
+ if not config:
331
+ continue
332
+
333
+ # Generate audio using original infer function
334
+ audio_result, _, _ = infer(
335
+ config["audio"],
336
+ config["text"],
337
+ text,
338
+ model,
339
+ remove_silence,
340
+ cross_fade_duration=0.15,
341
+ nfe_step=32,
342
+ speed=1.0
343
+ )
344
+ sr, audio_data = audio_result
345
+ generated_audio_segments.append(audio_data)
346
+
347
+ # Add pause between speakers (500ms silence)
348
+ if i < len(speaker_blocks)-2:
349
+ generated_audio_segments.append(np.zeros(int(0.5 * sr)))
350
+
351
+ # Combine all audio segments
352
+ if generated_audio_segments:
353
+ final_audio = np.concatenate(generated_audio_segments)
354
+ return (target_sample_rate, final_audio)
355
+ return None
356
+
357
+ generate_podcast_btn.click(
358
+ generate_podcast,
359
+ inputs=[
360
+ script_input,
361
+ speaker1_name, ref_audio_input1, ref_text_input1,
362
+ speaker2_name, ref_audio_input2, ref_text_input2,
363
+ speaker3_name, ref_audio_input3, ref_text_input3,
364
+ speaker4_name, ref_audio_input4, ref_text_input4,
365
+ speaker5_name, ref_audio_input5, ref_text_input5,
366
+ speaker6_name, ref_audio_input6, ref_text_input6,
367
+ speaker7_name, ref_audio_input7, ref_text_input7,
368
+ speaker8_name, ref_audio_input8, ref_text_input8,
369
+ speaker9_name, ref_audio_input9, ref_text_input9,
370
+ speaker10_name, ref_audio_input10, ref_text_input10,
371
+ podcast_model_choice, podcast_remove_silence
372
+ ],
373
+ outputs=podcast_output
374
+ )
375
+ with gr.Blocks() as app_credits:
376
+ gr.Markdown("""
377
+ # Credits
378
+
379
+ * [mrfakename](https://github.com/fakerybakery) for the original [online demo](https://huggingface.co/spaces/mrfakename/E2-F5-TTS)
380
+ * [RootingInLoad](https://github.com/RootingInLoad) for initial chunk generation and podcast app exploration
381
+ * [jpgallegoar](https://github.com/jpgallegoar) for multiple speech-type generation & voice chat
382
+ """)
383
+
384
+ with gr.Blocks() as app_tts:
385
+ gr.Markdown("# Batched TTS")
386
+ ref_audio_input = gr.Audio(label="Reference Audio", type="filepath")
387
+ gen_text_input = gr.Textbox(label="Text to Generate", lines=10)
388
+ generate_btn = gr.Button("Synthesize", variant="primary")
389
+ with gr.Accordion("Advanced Settings", open=False):
390
+ ref_text_input = gr.Textbox(
391
+ label="Reference Text",
392
+ info="Leave blank to automatically transcribe the reference audio. If you enter text it will override automatic transcription.",
393
+ lines=2,
394
+ )
395
+ remove_silence = gr.Checkbox(
396
+ label="Remove Silences",
397
+ info="The model tends to produce silences, especially on longer audio. We can manually remove silences if needed. Note that this is an experimental feature and may produce strange results. This will also increase generation time.",
398
+ value=False,
399
+ )
400
+ speed_slider = gr.Slider(
401
+ label="Speed",
402
+ minimum=0.3,
403
+ maximum=2.0,
404
+ value=1.0,
405
+ step=0.1,
406
+ info="Adjust the speed of the audio.",
407
+ )
408
+ nfe_slider = gr.Slider(
409
+ label="NFE Steps",
410
+ minimum=4,
411
+ maximum=64,
412
+ value=32,
413
+ step=2,
414
+ info="Set the number of denoising steps.",
415
+ )
416
+ cross_fade_duration_slider = gr.Slider(
417
+ label="Cross-Fade Duration (s)",
418
+ minimum=0.0,
419
+ maximum=1.0,
420
+ value=0.15,
421
+ step=0.01,
422
+ info="Set the duration of the cross-fade between audio clips.",
423
+ )
424
+
425
+ audio_output = gr.Audio(label="Synthesized Audio")
426
+ spectrogram_output = gr.Image(label="Spectrogram")
427
+
428
+ @gpu_decorator
429
+ def basic_tts(
430
+ ref_audio_input,
431
+ ref_text_input,
432
+ gen_text_input,
433
+ remove_silence,
434
+ cross_fade_duration_slider,
435
+ nfe_slider,
436
+ speed_slider,
437
+ ):
438
+ audio_out, spectrogram_path, ref_text_out = infer(
439
+ ref_audio_input,
440
+ ref_text_input,
441
+ gen_text_input,
442
+ tts_model_choice,
443
+ remove_silence,
444
+ cross_fade_duration=cross_fade_duration_slider,
445
+ nfe_step=nfe_slider,
446
+ speed=speed_slider,
447
+ )
448
+ return audio_out, spectrogram_path, ref_text_out
449
+
450
+ generate_btn.click(
451
+ basic_tts,
452
+ inputs=[
453
+ ref_audio_input,
454
+ ref_text_input,
455
+ gen_text_input,
456
+ remove_silence,
457
+ cross_fade_duration_slider,
458
+ nfe_slider,
459
+ speed_slider,
460
+ ],
461
+ outputs=[audio_output, spectrogram_output, ref_text_input],
462
+ )
463
+ with gr.Blocks() as app_multistyle:
464
+ gr.Markdown("# Multiple Speech-Type Generation")
465
+ # ... [Keep original multistyle interface unchanged] ...
466
+ with gr.Blocks() as app_chat:
467
+ gr.Markdown("# Voice Chat")
468
+ # ... [Keep original voice chat interface unchanged] ...
469
+
470
+ with gr.Blocks() as app:
471
+ gr.Markdown(f"""
472
+ # E2/F5 TTS
473
+ {"Local web UI for [F5 TTS](https://github.com/SWivid/F5-TTS)" if not USING_SPACES else "Online demo for [F5-TTS](https://github.com/SWivid/F5-TTS)"}
474
+ """)
475
+
476
+ with gr.Row():
477
+ if not USING_SPACES:
478
+ choose_tts_model = gr.Radio(
479
+ choices=[DEFAULT_TTS_MODEL, "E2-TTS", "Custom"],
480
+ label="TTS Model",
481
+ value=DEFAULT_TTS_MODEL
482
+ )
483
+ else:
484
+ choose_tts_model = gr.Radio(
485
+ choices=[DEFAULT_TTS_MODEL, "E2-TTS"],
486
+ label="TTS Model",
487
+ value=DEFAULT_TTS_MODEL
488
+ )
489
+
490
+ custom_ckpt_path = gr.Dropdown(
491
+ choices=[DEFAULT_TTS_MODEL_CFG[0]],
492
+ value=load_last_used_custom()[0],
493
+ allow_custom_value=True,
494
+ label="Model Path",
495
+ visible=False
496
+ )
497
+ custom_vocab_path = gr.Dropdown(
498
+ choices=[DEFAULT_TTS_MODEL_CFG[1]],
499
+ value=load_last_used_custom()[1],
500
+ allow_custom_value=True,
501
+ label="Vocab Path",
502
+ visible=False
503
+ )
504
+ custom_model_cfg = gr.Dropdown(
505
+ choices=[DEFAULT_TTS_MODEL_CFG[2]],
506
+ value=load_last_used_custom()[2],
507
+ allow_custom_value=True,
508
+ label="Model Config",
509
+ visible=False
510
+ )
511
+
512
+ choose_tts_model.change(
513
+ switch_tts_model,
514
+ inputs=[choose_tts_model],
515
+ outputs=[custom_ckpt_path, custom_vocab_path, custom_model_cfg]
516
+ )
517
+
518
+ gr.TabbedInterface(
519
+ [app_tts, app_podcast, app_multistyle, app_chat, app_credits],
520
+ ["Basic TTS", "Podcast", "Multi-Style", "Voice Chat", "Credits"],
521
+ )
522
+
523
+ @click.command()
524
+ @click.option("--port", "-p", default=None, type=int)
525
+ @click.option("--host", "-H", default=None)
526
+ @click.option("--share", "-s", default=True, is_flag=True)
527
+ @click.option("--api", "-a", default=True, is_flag=True)
528
+ @click.option("--root_path", "-r", default=None)
529
+ def main(port, host, share, api, root_path):
530
+ global app
531
+ print("Launching app...")
532
+ app.queue(api_open=api).launch(
533
+ server_name=host,
534
+ server_port=port,
535
+ share=share,
536
+ show_api=api,
537
+ root_path=root_path
538
+ )
539
+
540
+ if __name__ == "__main__":
541
+ if not USING_SPACES:
542
+ main()
543
+ else:
544
+ app.queue().launch()
545
+ # ========== REST OF ORIGINAL CODE (UNCHANGED BELOW) ========== #
546
+ # [Main app configuration, other tabs (TTS, Multistyle, Chat, Credits)]
547
+ # [Keep all original code after this point exactly as i