File size: 34,290 Bytes
eaa1d55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
from core import full_inference_program
import sys, os
import gradio as gr
import regex as re
from assets.i18n.i18n import I18nAuto
import torch
import shutil
import unicodedata

i18n = I18nAuto()

now_dir = os.getcwd()
sys.path.append(now_dir)

model_root = os.path.join(now_dir, "logs")
audio_root = os.path.join(now_dir, "audio_files", "original_files")

model_root_relative = os.path.relpath(model_root, now_dir)
audio_root_relative = os.path.relpath(audio_root, now_dir)

sup_audioext = {
    "wav",
    "mp3",
    "flac",
    "ogg",
    "opus",
    "m4a",
    "mp4",
    "aac",
    "alac",
    "wma",
    "aiff",
    "webm",
    "ac3",
}

names = [
    os.path.join(root, file)
    for root, _, files in os.walk(model_root_relative, topdown=False)
    for file in files
    if (
        file.endswith((".pth", ".onnx"))
        and not (file.startswith("G_") or file.startswith("D_"))
    )
]

indexes_list = [
    os.path.join(root, name)
    for root, _, files in os.walk(model_root_relative, topdown=False)
    for name in files
    if name.endswith(".index") and "trained" not in name
]

audio_paths = [
    os.path.join(root, name)
    for root, _, files in os.walk(audio_root_relative, topdown=False)
    for name in files
    if name.endswith(tuple(sup_audioext))
    and root == audio_root_relative
    and "_output" not in name
]

vocals_model_names = [
    "Mel-Roformer by KimberleyJSN",
    "BS-Roformer by ViperX",
    "MDX23C",
]

karaoke_models_names = [
    "Mel-Roformer Karaoke by aufr33 and viperx",
    "UVR-BVE",
]

denoise_models_names = [
    "Mel-Roformer Denoise Normal by aufr33",
    "Mel-Roformer Denoise Aggressive by aufr33",
    "UVR Denoise",
]

dereverb_models_names = [
    "MDX23C DeReverb by aufr33 and jarredou",
    "UVR-Deecho-Dereverb",
    "MDX Reverb HQ by FoxJoy",
    "BS-Roformer Dereverb by anvuew",
]

deeecho_models_names = ["UVR-Deecho-Normal", "UVR-Deecho-Aggressive"]


def get_indexes():
    indexes_list = [
        os.path.join(dirpath, filename)
        for dirpath, _, filenames in os.walk(model_root_relative)
        for filename in filenames
        if filename.endswith(".index") and "trained" not in filename
    ]

    return indexes_list if indexes_list else ""


def match_index(model_file_value):
    if model_file_value:
        model_folder = os.path.dirname(model_file_value)
        model_name = os.path.basename(model_file_value)
        index_files = get_indexes()
        pattern = r"^(.*?)_"
        match = re.match(pattern, model_name)
        for index_file in index_files:
            if os.path.dirname(index_file) == model_folder:
                return index_file
            elif match and match.group(1) in os.path.basename(index_file):
                return index_file
            elif model_name in os.path.basename(index_file):
                return index_file
    return ""


def output_path_fn(input_audio_path):
    original_name_without_extension = os.path.basename(input_audio_path).rsplit(".", 1)[
        0
    ]
    new_name = original_name_without_extension + "_output.wav"
    output_path = os.path.join(os.path.dirname(input_audio_path), new_name)
    return output_path


def get_number_of_gpus():
    if torch.cuda.is_available():
        num_gpus = torch.cuda.device_count()
        return "-".join(map(str, range(num_gpus)))
    else:
        return "-"


def max_vram_gpu(gpu):
    if torch.cuda.is_available():
        gpu_properties = torch.cuda.get_device_properties(gpu)
        total_memory_gb = round(gpu_properties.total_memory / 1024 / 1024 / 1024)
        return total_memory_gb / 2
    else:
        return "0"


def format_title(title):
    formatted_title = (
        unicodedata.normalize("NFKD", title).encode("ascii", "ignore").decode("utf-8")
    )
    formatted_title = re.sub(r"[\u2500-\u257F]+", "", formatted_title)
    formatted_title = re.sub(r"[^\w\s.-]", "", formatted_title)
    formatted_title = re.sub(r"\s+", "_", formatted_title)
    return formatted_title


def save_to_wav(upload_audio):
    file_path = upload_audio
    formated_name = format_title(os.path.basename(file_path))
    target_path = os.path.join(audio_root_relative, formated_name)

    if os.path.exists(target_path):
        os.remove(target_path)

    os.makedirs(os.path.dirname(target_path), exist_ok=True)
    shutil.copy(file_path, target_path)
    return target_path, output_path_fn(target_path)


def delete_outputs():
    gr.Info(f"Outputs cleared!")
    for root, _, files in os.walk(audio_root_relative, topdown=False):
        for name in files:
            if name.endswith(tuple(sup_audioext)) and name.__contains__("_output"):
                os.remove(os.path.join(root, name))


def change_choices():
    names = [
        os.path.join(root, file)
        for root, _, files in os.walk(model_root_relative, topdown=False)
        for file in files
        if (
            file.endswith((".pth", ".onnx"))
            and not (file.startswith("G_") or file.startswith("D_"))
        )
    ]

    indexes_list = [
        os.path.join(root, name)
        for root, _, files in os.walk(model_root_relative, topdown=False)
        for name in files
        if name.endswith(".index") and "trained" not in name
    ]

    audio_paths = [
        os.path.join(root, name)
        for root, _, files in os.walk(audio_root_relative, topdown=False)
        for name in files
        if name.endswith(tuple(sup_audioext))
        and root == audio_root_relative
        and "_output" not in name
    ]

    return (
        {"choices": sorted(names), "__type__": "update"},
        {"choices": sorted(indexes_list), "__type__": "update"},
        {"choices": sorted(audio_paths), "__type__": "update"},
    )


def full_inference_tab():
    default_weight = names[0] if names else None
    with gr.Row():
        with gr.Row():
            model_file = gr.Dropdown(
                label=i18n("Voice Model"),
                info=i18n("Select the voice model to use for the conversion."),
                choices=sorted(names, key=lambda path: os.path.getsize(path)),
                interactive=True,
                value=default_weight,
                allow_custom_value=True,
            )

            index_file = gr.Dropdown(
                label=i18n("Index File"),
                info=i18n("Select the index file to use for the conversion."),
                choices=get_indexes(),
                value=match_index(default_weight) if default_weight else "",
                interactive=True,
                allow_custom_value=True,
            )
        with gr.Column():
            refresh_button = gr.Button(i18n("Refresh"))
            unload_button = gr.Button(i18n("Unload Voice"))

            unload_button.click(
                fn=lambda: (
                    {"value": "", "__type__": "update"},
                    {"value": "", "__type__": "update"},
                ),
                inputs=[],
                outputs=[model_file, index_file],
            )
            model_file.select(
                fn=lambda model_file_value: match_index(model_file_value),
                inputs=[model_file],
                outputs=[index_file],
            )
    with gr.Tab(i18n("Single")):
        with gr.Column():
            upload_audio = gr.Audio(
                label=i18n("Upload Audio"),
                type="filepath",
                editable=False,
                sources="upload",
            )
            with gr.Row():
                audio = gr.Dropdown(
                    label=i18n("Select Audio"),
                    info=i18n("Select the audio to convert."),
                    choices=sorted(audio_paths),
                    value=audio_paths[0] if audio_paths else "",
                    interactive=True,
                    allow_custom_value=True,
                )
        with gr.Accordion(i18n("Advanced Settings"), open=False):
            with gr.Accordion(i18n("RVC Settings"), open=False):
                output_path = gr.Textbox(
                    label=i18n("Output Path"),
                    placeholder=i18n("Enter output path"),
                    info=i18n(
                        "The path where the output audio will be saved, by default in audio_files/rvc/output.wav"
                    ),
                    value=os.path.join(now_dir, "audio_files", "rvc"),
                    interactive=False,
                    visible=False,
                )
                infer_backing_vocals = gr.Checkbox(
                    label=i18n("Infer Backing Vocals"),
                    info=i18n("Infer the bakcing vocals too."),
                    visible=True,
                    value=False,
                    interactive=True,
                )
                with gr.Row():
                    infer_backing_vocals_model = gr.Dropdown(
                        label=i18n("Backing Vocals Model"),
                        info=i18n(
                            "Select the backing vocals model to use for the conversion."
                        ),
                        choices=sorted(names, key=lambda path: os.path.getsize(path)),
                        interactive=True,
                        value=default_weight,
                        visible=False,
                        allow_custom_value=False,
                    )
                    infer_backing_vocals_index = gr.Dropdown(
                        label=i18n("Backing Vocals Index File"),
                        info=i18n(
                            "Select the backing vocals index file to use for the conversion."
                        ),
                        choices=get_indexes(),
                        value=match_index(default_weight) if default_weight else "",
                        interactive=True,
                        visible=False,
                        allow_custom_value=True,
                    )
                    with gr.Column():
                        refresh_button_infer_backing_vocals = gr.Button(
                            i18n("Refresh"),
                            visible=False,
                        )
                        unload_button_infer_backing_vocals = gr.Button(
                            i18n("Unload Voice"),
                            visible=False,
                        )

                        unload_button_infer_backing_vocals.click(
                            fn=lambda: (
                                {"value": "", "__type__": "update"},
                                {"value": "", "__type__": "update"},
                            ),
                            inputs=[],
                            outputs=[
                                infer_backing_vocals_model,
                                infer_backing_vocals_index,
                            ],
                        )
                        infer_backing_vocals_model.select(
                            fn=lambda model_file_value: match_index(model_file_value),
                            inputs=[infer_backing_vocals_model],
                            outputs=[infer_backing_vocals_index],
                        )
                with gr.Accordion(
                    i18n("RVC Settings for Backing vocals"), open=False, visible=False
                ) as back_rvc_settings:
                    export_format_rvc_back = gr.Radio(
                        label=i18n("Export Format"),
                        info=i18n("Select the format to export the audio."),
                        choices=["WAV", "MP3", "FLAC", "OGG", "M4A"],
                        value="FLAC",
                        interactive=True,
                        visible=False,
                    )
                    split_audio_back = gr.Checkbox(
                        label=i18n("Split Audio"),
                        info=i18n(
                            "Split the audio into chunks for inference to obtain better results in some cases."
                        ),
                        visible=True,
                        value=False,
                        interactive=True,
                    )
                    pitch_extract_back = gr.Radio(
                        label=i18n("Pitch Extractor"),
                        info=i18n("Pitch extract Algorith."),
                        choices=["rmvpe", "crepe", "crepe-tiny", "fcpe"],
                        value="rmvpe",
                        interactive=True,
                    )
                    hop_length_back = gr.Slider(
                        label=i18n("Hop Length"),
                        info=i18n("Hop length for pitch extraction."),
                        minimum=1,
                        maximum=512,
                        step=1,
                        value=64,
                        visible=False,
                    )
                    embedder_model_back = gr.Radio(
                        label=i18n("Embedder Model"),
                        info=i18n("Model used for learning speaker embedding."),
                        choices=[
                            "contentvec",
                            "chinese-hubert-base",
                            "japanese-hubert-base",
                            "korean-hubert-base",
                        ],
                        value="contentvec",
                        interactive=True,
                    )
                    autotune_back = gr.Checkbox(
                        label=i18n("Autotune"),
                        info=i18n(
                            "Apply a soft autotune to your inferences, recommended for singing conversions."
                        ),
                        visible=True,
                        value=False,
                        interactive=True,
                    )
                    pitch_back = gr.Slider(
                        label=i18n("Pitch"),
                        info=i18n("Adjust the pitch of the audio."),
                        minimum=-12,
                        maximum=12,
                        step=1,
                        value=0,
                        interactive=True,
                    )
                    filter_radius_back = gr.Slider(
                        minimum=0,
                        maximum=7,
                        label=i18n("Filter Radius"),
                        info=i18n(
                            "If the number is greater than or equal to three, employing median filtering on the collected tone results has the potential to decrease respiration."
                        ),
                        value=3,
                        step=1,
                        interactive=True,
                    )
                    index_rate_back = gr.Slider(
                        minimum=0,
                        maximum=1,
                        label=i18n("Search Feature Ratio"),
                        info=i18n(
                            "Influence exerted by the index file; a higher value corresponds to greater influence. However, opting for lower values can help mitigate artifacts present in the audio."
                        ),
                        value=0.75,
                        interactive=True,
                    )
                    rms_mix_rate_back = gr.Slider(
                        minimum=0,
                        maximum=1,
                        label=i18n("Volume Envelope"),
                        info=i18n(
                            "Substitute or blend with the volume envelope of the output. The closer the ratio is to 1, the more the output envelope is employed."
                        ),
                        value=0.25,
                        interactive=True,
                    )
                    protect_back = gr.Slider(
                        minimum=0,
                        maximum=0.5,
                        label=i18n("Protect Voiceless Consonants"),
                        info=i18n(
                            "Safeguard distinct consonants and breathing sounds to prevent electro-acoustic tearing and other artifacts. Pulling the parameter to its maximum value of 0.5 offers comprehensive protection. However, reducing this value might decrease the extent of protection while potentially mitigating the indexing effect."
                        ),
                        value=0.33,
                        interactive=True,
                    )
                clear_outputs_infer = gr.Button(
                    i18n("Clear Outputs (Deletes all audios in assets/audios)")
                )
                export_format_rvc = gr.Radio(
                    label=i18n("Export Format"),
                    info=i18n("Select the format to export the audio."),
                    choices=["WAV", "MP3", "FLAC", "OGG", "M4A"],
                    value="FLAC",
                    interactive=True,
                    visible=False,
                )
                split_audio = gr.Checkbox(
                    label=i18n("Split Audio"),
                    info=i18n(
                        "Split the audio into chunks for inference to obtain better results in some cases."
                    ),
                    visible=True,
                    value=False,
                    interactive=True,
                )
                pitch_extract = gr.Radio(
                    label=i18n("Pitch Extractor"),
                    info=i18n("Pitch extract Algorith."),
                    choices=["rmvpe", "crepe", "crepe-tiny", "fcpe"],
                    value="rmvpe",
                    interactive=True,
                )
                hop_length = gr.Slider(
                    label=i18n("Hop Length"),
                    info=i18n("Hop length for pitch extraction."),
                    minimum=1,
                    maximum=512,
                    step=1,
                    value=64,
                    visible=False,
                )
                embedder_model = gr.Radio(
                    label=i18n("Embedder Model"),
                    info=i18n("Model used for learning speaker embedding."),
                    choices=[
                        "contentvec",
                        "chinese-hubert-base",
                        "japanese-hubert-base",
                        "korean-hubert-base",
                    ],
                    value="contentvec",
                    interactive=True,
                )
                autotune = gr.Checkbox(
                    label=i18n("Autotune"),
                    info=i18n(
                        "Apply a soft autotune to your inferences, recommended for singing conversions."
                    ),
                    visible=True,
                    value=False,
                    interactive=True,
                )
                pitch = gr.Slider(
                    label=i18n("Pitch"),
                    info=i18n("Adjust the pitch of the audio."),
                    minimum=-12,
                    maximum=12,
                    step=1,
                    value=0,
                    interactive=True,
                )
                filter_radius = gr.Slider(
                    minimum=0,
                    maximum=7,
                    label=i18n("Filter Radius"),
                    info=i18n(
                        "If the number is greater than or equal to three, employing median filtering on the collected tone results has the potential to decrease respiration."
                    ),
                    value=3,
                    step=1,
                    interactive=True,
                )
                index_rate = gr.Slider(
                    minimum=0,
                    maximum=1,
                    label=i18n("Search Feature Ratio"),
                    info=i18n(
                        "Influence exerted by the index file; a higher value corresponds to greater influence. However, opting for lower values can help mitigate artifacts present in the audio."
                    ),
                    value=0.75,
                    interactive=True,
                )
                rms_mix_rate = gr.Slider(
                    minimum=0,
                    maximum=1,
                    label=i18n("Volume Envelope"),
                    info=i18n(
                        "Substitute or blend with the volume envelope of the output. The closer the ratio is to 1, the more the output envelope is employed."
                    ),
                    value=0.25,
                    interactive=True,
                )
                protect = gr.Slider(
                    minimum=0,
                    maximum=0.5,
                    label=i18n("Protect Voiceless Consonants"),
                    info=i18n(
                        "Safeguard distinct consonants and breathing sounds to prevent electro-acoustic tearing and other artifacts. Pulling the parameter to its maximum value of 0.5 offers comprehensive protection. However, reducing this value might decrease the extent of protection while potentially mitigating the indexing effect."
                    ),
                    value=0.33,
                    interactive=True,
                )
            with gr.Accordion(i18n("Audio Separation Settings"), open=False):
                use_tta = gr.Checkbox(
                    label=i18n("Use TTA"),
                    info=i18n("Use Test Time Augmentation."),
                    visible=True,
                    value=False,
                    interactive=True,
                )
                batch_size = gr.Slider(
                    minimum=1,
                    maximum=24,
                    step=1,
                    label=i18n("Batch Size"),
                    info=i18n("Set the batch size for the separation."),
                    value=1,
                    interactive=True,
                )
                vocal_model = gr.Dropdown(
                    label=i18n("Vocals Model"),
                    info=i18n("Select the vocals model to use for the separation."),
                    choices=sorted(vocals_model_names),
                    interactive=True,
                    value="Mel-Roformer by KimberleyJSN",
                    allow_custom_value=False,
                )
                karaoke_model = gr.Dropdown(
                    label=i18n("Karaoke Model"),
                    info=i18n("Select the karaoke model to use for the separation."),
                    choices=sorted(karaoke_models_names),
                    interactive=True,
                    value="Mel-Roformer Karaoke by aufr33 and viperx",
                    allow_custom_value=False,
                )
                dereverb_model = gr.Dropdown(
                    label=i18n("Dereverb Model"),
                    info=i18n("Select the dereverb model to use for the separation."),
                    choices=sorted(dereverb_models_names),
                    interactive=True,
                    value="UVR-Deecho-Dereverb",
                    allow_custom_value=False,
                )
                deecho = gr.Checkbox(
                    label=i18n("Deeecho"),
                    info=i18n("Apply deeecho to the audio."),
                    visible=True,
                    value=True,
                    interactive=True,
                )
                deeecho_model = gr.Dropdown(
                    label=i18n("Deeecho Model"),
                    info=i18n("Select the deeecho model to use for the separation."),
                    choices=sorted(deeecho_models_names),
                    interactive=True,
                    value="UVR-Deecho-Normal",
                    allow_custom_value=False,
                )
                denoise = gr.Checkbox(
                    label=i18n("Denoise"),
                    info=i18n("Apply denoise to the audio."),
                    visible=True,
                    value=False,
                    interactive=True,
                )
                denoise_model = gr.Dropdown(
                    label=i18n("Denoise Model"),
                    info=i18n("Select the denoise model to use for the separation."),
                    choices=sorted(denoise_models_names),
                    interactive=True,
                    value="Mel-Roformer Denoise Normal by aufr33",
                    allow_custom_value=False,
                    visible=False,
                )
            with gr.Accordion(i18n("Audio post-process Settings"), open=False):
                change_inst_pitch = gr.Slider(
                    label=i18n("Change Instrumental Pitch"),
                    info=i18n("Change the pitch of the instrumental."),
                    minimum=-12,
                    maximum=12,
                    step=1,
                    value=0,
                    interactive=True,
                )
                delete_audios = gr.Checkbox(
                    label=i18n("Delete Audios"),
                    info=i18n("Delete the audios after the conversion."),
                    visible=True,
                    value=True,
                    interactive=True,
                )
                reverb = gr.Checkbox(
                    label=i18n("Reverb"),
                    info=i18n("Apply reverb to the audio."),
                    visible=True,
                    value=False,
                    interactive=True,
                )
                reverb_room_size = gr.Slider(
                    minimum=0,
                    maximum=1,
                    label=i18n("Reverb Room Size"),
                    info=i18n("Set the room size of the reverb."),
                    value=0.5,
                    interactive=True,
                    visible=False,
                )

                reverb_damping = gr.Slider(
                    minimum=0,
                    maximum=1,
                    label=i18n("Reverb Damping"),
                    info=i18n("Set the damping of the reverb."),
                    value=0.5,
                    interactive=True,
                    visible=False,
                )

                reverb_wet_gain = gr.Slider(
                    minimum=0,
                    maximum=1,
                    label=i18n("Reverb Wet Gain"),
                    info=i18n("Set the wet gain of the reverb."),
                    value=0.33,
                    interactive=True,
                    visible=False,
                )

                reverb_dry_gain = gr.Slider(
                    minimum=0,
                    maximum=1,
                    label=i18n("Reverb Dry Gain"),
                    info=i18n("Set the dry gain of the reverb."),
                    value=0.4,
                    interactive=True,
                    visible=False,
                )

                reverb_width = gr.Slider(
                    minimum=0,
                    maximum=1,
                    label=i18n("Reverb Width"),
                    info=i18n("Set the width of the reverb."),
                    value=1.0,
                    interactive=True,
                    visible=False,
                )
                vocals_volume = gr.Slider(
                    label=i18n("Vocals Volume"),
                    info=i18n("Adjust the volume of the vocals."),
                    minimum=-10,
                    maximum=0,
                    step=1,
                    value=-3,
                    interactive=True,
                )
                instrumentals_volume = gr.Slider(
                    label=i18n("Instrumentals Volume"),
                    info=i18n("Adjust the volume of the Instrumentals."),
                    minimum=-10,
                    maximum=0,
                    step=1,
                    value=-3,
                    interactive=True,
                )
                backing_vocals_volume = gr.Slider(
                    label=i18n("Backing Vocals Volume"),
                    info=i18n("Adjust the volume of the backing vocals."),
                    minimum=-10,
                    maximum=0,
                    step=1,
                    value=-3,
                    interactive=True,
                )
                export_format_final = gr.Radio(
                    label=i18n("Export Format"),
                    info=i18n("Select the format to export the audio."),
                    choices=["WAV", "MP3", "FLAC", "OGG", "M4A"],
                    value="FLAC",
                    interactive=True,
                )
            with gr.Accordion(i18n("Device Settings"), open=False):
                devices = gr.Textbox(
                    label=i18n("Device"),
                    info=i18n(
                        "Select the device to use for the conversion. 0 to ∞ separated by - and for CPU leave only an -"
                    ),
                    value=get_number_of_gpus(),
                    interactive=True,
                )

    with gr.Row():
        convert_button = gr.Button(i18n("Convert"))

    with gr.Row():
        vc_output1 = gr.Textbox(
            label=i18n("Output Information"),
            info=i18n("The output information will be displayed here."),
        )
        vc_output2 = gr.Audio(label=i18n("Export Audio"))

    def update_dropdown_visibility(checkbox):
        return gr.update(visible=checkbox)

    def update_reverb_sliders_visibility(reverb_checked):
        return {
            reverb_room_size: gr.update(visible=reverb_checked),
            reverb_damping: gr.update(visible=reverb_checked),
            reverb_wet_gain: gr.update(visible=reverb_checked),
            reverb_dry_gain: gr.update(visible=reverb_checked),
            reverb_width: gr.update(visible=reverb_checked),
        }

    def update_visibility_infer_backing(infer_backing_vocals):
        visible = infer_backing_vocals
        return (
            {"visible": visible, "__type__": "update"},
            {"visible": visible, "__type__": "update"},
            {"visible": visible, "__type__": "update"},
            {"visible": visible, "__type__": "update"},
            {"visible": visible, "__type__": "update"},
        )

    def update_hop_length_visibility(pitch_extract_value):
        return gr.update(visible=pitch_extract_value in ["crepe", "crepe-tiny"])

    refresh_button.click(
        fn=change_choices,
        inputs=[],
        outputs=[model_file, index_file, audio],
    )
    refresh_button_infer_backing_vocals.click(
        fn=change_choices,
        inputs=[],
        outputs=[infer_backing_vocals_model, infer_backing_vocals_index],
    )
    upload_audio.upload(
        fn=save_to_wav,
        inputs=[upload_audio],
        outputs=[audio, output_path],
    )
    clear_outputs_infer.click(
        fn=delete_outputs,
        inputs=[],
        outputs=[],
    )
    convert_button.click(
        full_inference_program,
        inputs=[
            model_file,
            index_file,
            audio,
            output_path,
            export_format_rvc,
            split_audio,
            autotune,
            vocal_model,
            karaoke_model,
            dereverb_model,
            deecho,
            deeecho_model,
            denoise,
            denoise_model,
            reverb,
            vocals_volume,
            instrumentals_volume,
            backing_vocals_volume,
            export_format_final,
            devices,
            pitch,
            filter_radius,
            index_rate,
            rms_mix_rate,
            protect,
            pitch_extract,
            hop_length,
            reverb_room_size,
            reverb_damping,
            reverb_wet_gain,
            reverb_dry_gain,
            reverb_width,
            embedder_model,
            delete_audios,
            use_tta,
            batch_size,
            infer_backing_vocals,
            infer_backing_vocals_model,
            infer_backing_vocals_index,
            change_inst_pitch,
            pitch_back,
            filter_radius_back,
            index_rate_back,
            rms_mix_rate_back,
            protect_back,
            pitch_extract_back,
            hop_length_back,
            export_format_rvc_back,
            split_audio_back,
            autotune_back,
            embedder_model_back,
        ],
        outputs=[vc_output1, vc_output2],
    )

    deecho.change(
        fn=update_dropdown_visibility,
        inputs=deecho,
        outputs=deeecho_model,
    )

    denoise.change(
        fn=update_dropdown_visibility,
        inputs=denoise,
        outputs=denoise_model,
    )

    reverb.change(
        fn=update_reverb_sliders_visibility,
        inputs=reverb,
        outputs=[
            reverb_room_size,
            reverb_damping,
            reverb_wet_gain,
            reverb_dry_gain,
            reverb_width,
        ],
    )
    pitch_extract.change(
        fn=update_hop_length_visibility,
        inputs=pitch_extract,
        outputs=hop_length,
    )

    infer_backing_vocals.change(
        fn=update_visibility_infer_backing,
        inputs=[infer_backing_vocals],
        outputs=[
            infer_backing_vocals_model,
            infer_backing_vocals_index,
            refresh_button_infer_backing_vocals,
            unload_button_infer_backing_vocals,
            back_rvc_settings,
        ],
    )