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
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
import gradio as gr
from command import *


def downloader_conf():
    return gr.Checkbox(
        False,
        label="URL-to-Audio",
        # info="",
        container=False,
    )


def url_media_conf():
    return gr.Textbox(
        value="",
        label="Enter URL",
        placeholder="www.youtube.com/watch?v=g_9rPvbENUw",
        visible=False,
        lines=1,
    )


def url_button_conf():
    return gr.Button(
        "Go",
        variant="secondary",
        visible=False,
    )


def show_components_downloader(value_active):
    return gr.update(
        visible=value_active
    ), gr.update(
        visible=value_active
    )


def audio_conf():
    return gr.File(
        label="Audio file",
        # file_count="multiple",
        type="filepath",
        container=True,
    )


def stem_conf():
    return gr.Radio(
        choices=["vocal", "background"],
        value="vocal",
        label="Stem",
        # info="",
    )


def main_conf():
    return gr.Checkbox(
        False,
        label="Main",
        # info="",
    )


def dereverb_conf():
    return gr.Checkbox(
        False,
        label="Dereverb",
        # info="",
        visible=True,
    )


def vocal_effects_conf():
    return gr.Checkbox(
        False,
        label="Vocal Effects",
        # info="",
        visible=True,
    )


def background_effects_conf():
    return gr.Checkbox(
        False,
        label="Background Effects",
        # info="",
        visible=False,
    )


def vocal_reverb_room_size_conf():
    return gr.Number(
        0.15,
        label="Vocal Reverb Room Size",
        minimum=0.0,
        maximum=1.0,
        step=0.05,
        visible=True,
    )


def vocal_reverb_damping_conf():
    return gr.Number(
        0.7,
        label="Vocal Reverb Damping",
        minimum=0.0,
        maximum=1.0,
        step=0.01,
        visible=True,
    )


def vocal_reverb_wet_level_conf():
    return gr.Number(
        0.2,
        label="Vocal Reverb Wet Level",
        minimum=0.0,
        maximum=1.0,
        step=0.05,
        visible=True,
    )


def vocal_reverb_dryness_level_conf():
    return gr.Number(
        0.8,
        label="Vocal Reverb Dryness Level",
        minimum=0.0,
        maximum=1.0,
        step=0.05,
        visible=True,
    )


def vocal_delay_seconds_conf():
    return gr.Number(
        0.,
        label="Vocal Delay Seconds",
        minimum=0.0,
        maximum=1.0,
        step=0.01,
        visible=True,
    )


def vocal_delay_mix_conf():
    return gr.Number(
        0.,
        label="Vocal Delay Mix",
        minimum=0.0,
        maximum=1.0,
        step=0.01,
        visible=True,
    )


def vocal_compressor_threshold_db_conf():
    return gr.Number(
        -15,
        label="Vocal Compressor Threshold (dB)",
        minimum=-60,
        maximum=0,
        step=1,
        visible=True,
    )


def vocal_compressor_ratio_conf():
    return gr.Number(
        4.,
        label="Vocal Compressor Ratio",
        minimum=0,
        maximum=20,
        step=0.1,
        visible=True,
    )


def vocal_compressor_attack_ms_conf():
    return gr.Number(
        1.0,
        label="Vocal Compressor Attack (ms)",
        minimum=0,
        maximum=1000,
        step=1,
        visible=True,
    )


def vocal_compressor_release_ms_conf():
    return gr.Number(
        100,
        label="Vocal Compressor Release (ms)",
        minimum=0,
        maximum=3000,
        step=1,
        visible=True,
    )


def vocal_gain_db_conf():
    return gr.Number(
        0,
        label="Vocal Gain (dB)",
        minimum=-40,
        maximum=40,
        step=1,
        visible=True,
    )


def background_highpass_freq_conf():
    return gr.Number(
        120,
        label="Background Highpass Frequency (Hz)",
        minimum=0,
        maximum=1000,
        step=1,
        visible=True,
    )


def background_lowpass_freq_conf():
    return gr.Number(
        11000,
        label="Background Lowpass Frequency (Hz)",
        minimum=0,
        maximum=20000,
        step=1,
        visible=True,
    )


def background_reverb_room_size_conf():
    return gr.Number(
        0.1,
        label="Background Reverb Room Size",
        minimum=0.0,
        maximum=1.0,
        step=0.1,
        visible=True,
    )


def background_reverb_damping_conf():
    return gr.Number(
        0.5,
        label="Background Reverb Damping",
        minimum=0.0,
        maximum=1.0,
        step=0.1,
        visible=True,
    )


def background_reverb_wet_level_conf():
    return gr.Number(
        0.25,
        label="Background Reverb Wet Level",
        minimum=0.0,
        maximum=1.0,
        step=0.05,
        visible=True,
    )


def background_compressor_threshold_db_conf():
    return gr.Number(
        -15,
        label="Background Compressor Threshold (dB)",
        minimum=-60,
        maximum=0,
        step=1,
        visible=True,
    )


def background_compressor_ratio_conf():
    return gr.Number(
        4.,
        label="Background Compressor Ratio",
        minimum=0,
        maximum=20,
        step=0.1,
        visible=True,
    )


def background_compressor_attack_ms_conf():
    return gr.Number(
        15,
        label="Background Compressor Attack (ms)",
        minimum=0,
        maximum=1000,
        step=1,
        visible=True,
    )


def background_compressor_release_ms_conf():
    return gr.Number(
        60,
        label="Background Compressor Release (ms)",
        minimum=0,
        maximum=3000,
        step=1,
        visible=True,
    )


def background_gain_db_conf():
    return gr.Number(
        0,
        label="Background Gain (dB)",
        minimum=-40,
        maximum=40,
        step=1,
        visible=True,
    )


def button_conf():
    return gr.Button(
        "Inference",
        variant="primary",
    )


def output_conf():
    return gr.File(
        label="Result",
        file_count="multiple",
        interactive=False,
    )


def show_vocal_components(value_name):

    if value_name == "vocal":
        return gr.update(visible=True), gr.update(
            visible=True
        ), gr.update(visible=True), gr.update(
            visible=False
        )
    else:
        return gr.update(visible=False), gr.update(
            visible=False
        ), gr.update(visible=False), gr.update(
            visible=True
        )


def get_gui(theme):
    with gr.Blocks(theme="hev832/Applio") as app:
        gr.Markdown(title)
        with gr.Accordion("read this", open=False):
            gr.Markdown(description)

        downloader_gui = downloader_conf()
        with gr.Row():
            with gr.Column(scale=2):
                url_media_gui = url_media_conf()
            with gr.Column(scale=1):
                url_button_gui = url_button_conf()

        downloader_gui.change(
            show_components_downloader,
            [downloader_gui],
            [url_media_gui, url_button_gui]
        )

        aud = audio_conf()

        url_button_gui.click(
            audio_downloader,
            [url_media_gui],
            [aud]
        )

        with gr.Column():
            with gr.Row():
                stem_gui = stem_conf()

        with gr.Column():
            with gr.Row():
                main_gui = main_conf()
                dereverb_gui = dereverb_conf()
                vocal_effects_gui = vocal_effects_conf()
                background_effects_gui = background_effects_conf()

            # with gr.Column():
            with gr.Accordion("Vocal Effects Parameters", open=False): # with gr.Row():
                # gr.Label("Vocal Effects Parameters")
                with gr.Row():
                    vocal_reverb_room_size_gui = vocal_reverb_room_size_conf()
                    vocal_reverb_damping_gui = vocal_reverb_damping_conf()
                    vocal_reverb_dryness_gui = vocal_reverb_dryness_level_conf()
                    vocal_reverb_wet_level_gui = vocal_reverb_wet_level_conf()
                    vocal_delay_seconds_gui = vocal_delay_seconds_conf()
                    vocal_delay_mix_gui = vocal_delay_mix_conf()
                    vocal_compressor_threshold_db_gui = vocal_compressor_threshold_db_conf()
                    vocal_compressor_ratio_gui = vocal_compressor_ratio_conf()
                    vocal_compressor_attack_ms_gui = vocal_compressor_attack_ms_conf()
                    vocal_compressor_release_ms_gui = vocal_compressor_release_ms_conf()
                    vocal_gain_db_gui = vocal_gain_db_conf()

            with gr.Accordion("Background Effects Parameters", open=False): # with gr.Row():
                # gr.Label("Background Effects Parameters")
                with gr.Row():
                    background_highpass_freq_gui = background_highpass_freq_conf()
                    background_lowpass_freq_gui = background_lowpass_freq_conf()
                    background_reverb_room_size_gui = background_reverb_room_size_conf()
                    background_reverb_damping_gui = background_reverb_damping_conf()
                    background_reverb_wet_level_gui = background_reverb_wet_level_conf()
                    background_compressor_threshold_db_gui = background_compressor_threshold_db_conf()
                    background_compressor_ratio_gui = background_compressor_ratio_conf()
                    background_compressor_attack_ms_gui = background_compressor_attack_ms_conf()
                    background_compressor_release_ms_gui = background_compressor_release_ms_conf()
                    background_gain_db_gui = background_gain_db_conf()

            stem_gui.change(
                show_vocal_components,
                [stem_gui],
                [main_gui, dereverb_gui, vocal_effects_gui, background_effects_gui],
            )

        button_base = button_conf()
        output_base = output_conf()

        button_base.click(
            sound_separate,
            inputs=[
                aud,
                stem_gui,
                main_gui,
                dereverb_gui,
                vocal_effects_gui,
                background_effects_gui,
                vocal_reverb_room_size_gui, vocal_reverb_damping_gui, vocal_reverb_dryness_gui, vocal_reverb_wet_level_gui,
                vocal_delay_seconds_gui, vocal_delay_mix_gui, vocal_compressor_threshold_db_gui, vocal_compressor_ratio_gui,
                vocal_compressor_attack_ms_gui, vocal_compressor_release_ms_gui, vocal_gain_db_gui,
                background_highpass_freq_gui, background_lowpass_freq_gui, background_reverb_room_size_gui,
                background_reverb_damping_gui, background_reverb_wet_level_gui, background_compressor_threshold_db_gui,
                background_compressor_ratio_gui, background_compressor_attack_ms_gui, background_compressor_release_ms_gui,
                background_gain_db_gui,
            ],
            outputs=[output_base],
        )

        

    return app


if __name__ == "__main__":

    for id_model in UVR_MODELS:
        download_manager(
            os.path.join(MDX_DOWNLOAD_LINK, id_model), mdxnet_models_dir
        )

    app = get_gui(theme)

    app.queue(default_concurrency_limit=40)

    app.launch(
        max_threads=40,
        share=True,
        show_error=True,
        quiet=False,
        debug=True,
    )