yoyolicoris commited on
Commit
d922102
·
1 Parent(s): b6e65c7

feat: enhance UI with additional filter controls and improved slider labels

Browse files
Files changed (1) hide show
  1. app.py +211 -280
app.py CHANGED
@@ -393,99 +393,151 @@ with gr.Blocks() as demo:
393
  peq_plot = gr.Plot(
394
  plot_eq(), label="PEQ Frequency Response", elem_id="peq-plot"
395
  )
396
- with gr.Row():
397
- with gr.Column():
398
- _ = gr.Markdown("Peak filter 1")
399
- pk1 = fx[0]
400
- pk1_freq = gr.Slider(
401
- minimum=33,
402
- maximum=5400,
403
- value=pk1.params.freq.item(),
404
- interactive=True,
405
- )
406
- pk1_gain = gr.Slider(
407
- minimum=-24,
408
- maximum=24,
409
- value=pk1.params.gain.item(),
410
- interactive=True,
411
- )
412
- pk1_q = gr.Slider(
413
- minimum=0.2,
414
- maximum=20,
415
- value=pk1.params.Q.item(),
416
- interactive=True,
417
- )
418
- with gr.Column():
419
- _ = gr.Markdown("Peak filter 2")
420
- pk2 = fx[1]
421
- pk2_freq = gr.Slider(
422
- minimum=200,
423
- maximum=17500,
424
- value=pk2.params.freq.item(),
425
- interactive=True,
426
- )
427
- pk2_gain = gr.Slider(
428
- minimum=-24,
429
- maximum=24,
430
- value=pk2.params.gain.item(),
431
- interactive=True,
432
- )
433
- pk2_q = gr.Slider(
434
- minimum=0.2,
435
- maximum=20,
436
- value=pk2.params.Q.item(),
437
- interactive=True,
438
- )
439
- with gr.Row():
440
- with gr.Column():
441
- _ = gr.Markdown("Low Shelf")
442
- ls = fx[2]
443
- ls_freq = gr.Slider(
444
- minimum=30,
445
- maximum=200,
446
- value=ls.params.freq.item(),
447
- interactive=True,
448
- )
449
- ls_gain = gr.Slider(
450
- minimum=-24,
451
- maximum=24,
452
- value=ls.params.gain.item(),
453
- interactive=True,
454
- )
455
- with gr.Column():
456
- _ = gr.Markdown("High Shelf")
457
- hs = fx[3]
458
- hs_freq = gr.Slider(
459
- minimum=750,
460
- maximum=8300,
461
- value=hs.params.freq.item(),
462
- interactive=True,
463
- )
464
- hs_gain = gr.Slider(
465
- minimum=-24,
466
- maximum=24,
467
- value=hs.params.gain.item(),
468
- interactive=True,
469
- )
470
-
471
- comp_plot = gr.Plot(
472
- plot_comp(), label="Compressor Curve", elem_id="comp-plot"
473
  )
474
- delay_plot = gr.Plot(
475
- plot_delay(), label="Delay Frequency Response", elem_id="delay-plot"
 
 
 
 
476
  )
477
- reverb_plot = gr.Plot(
478
- plot_reverb(), label="Reverb Tone Correction PEQ", elem_id="reverb-plot"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
479
  )
480
- t60_plot = gr.Plot(plot_t60(), label="Reverb T60", elem_id="t60-plot")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
481
 
482
  with gr.Row():
483
  json_output = gr.JSON(
484
  model2json(), label="Effect Settings", max_height=800, open=True
485
  )
486
 
 
 
 
487
  for eq, s, attr_name in zip(
488
- [fx[0]] * 3 + [fx[1]] * 3 + [fx[2]] * 2 + [fx[3]] * 2,
 
 
 
 
 
489
  [
490
  pk1_freq,
491
  pk1_gain,
@@ -497,163 +549,110 @@ with gr.Blocks() as demo:
497
  ls_gain,
498
  hs_freq,
499
  hs_gain,
 
 
 
 
500
  ],
501
- ["freq", "gain", "Q"] * 2 + ["freq", "gain"] * 2,
502
  ):
503
  s.input(
504
  lambda *args, eq=eq, attr_name=attr_name: chain_functions( # chain_functions(
505
  lambda args: (upatePEQ(eq, attr_name, args[0]), args[1]),
506
  lambda args: (fx2z(), args[1]),
507
- lambda args: [plot_eq()]
508
- + z[:NUMBER_OF_PCS].tolist()
509
- + [z[args[1] - 1].item(), model2json()],
510
  )(
511
  args
512
  ),
513
  inputs=[s, extra_pc_dropdown],
514
- outputs=[peq_plot] + sliders + [extra_slider, json_output],
515
  )
516
 
517
  render_button.click(
518
- lambda *args: (
519
- lambda x: (
520
- x,
521
- model2json(),
522
- plot_eq(),
523
- plot_comp(),
524
- plot_delay(),
525
- plot_reverb(),
526
- plot_t60(),
527
- )
528
- )(inference(*args)),
529
  inputs=[
530
  audio_input,
531
- # random_rest_checkbox,
532
- ]
533
- # + sliders,
534
- ,
535
  outputs=[
536
  audio_output,
537
- json_output,
538
- peq_plot,
539
- comp_plot,
540
- delay_plot,
541
- reverb_plot,
542
- t60_plot,
543
  ],
544
  )
545
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
546
  random_button.click(
547
- # lambda *xs: [
548
- # chain_functions(
549
- # partial(max, SLIDER_MIN),
550
- # partial(min, SLIDER_MAX),
551
- # )(normalvariate(0, 1))
552
- # for _ in range(len(xs))
553
- # ],
554
- # lambda i: (lambda x: x[:NUMBER_OF_PCS].tolist() + [x[i - 1].item()])(
555
- # z.normal_(0, 1).clip_(SLIDER_MIN, SLIDER_MAX)
556
- # ),
557
  chain_functions(
558
  lambda i: (z.normal_(0, 1).clip_(SLIDER_MIN, SLIDER_MAX), i),
559
- lambda args: args + (z2fx(),),
560
- lambda args: args[0][:NUMBER_OF_PCS].tolist()
561
- + [
562
- args[0][args[1] - 1].item(),
563
- model2json(),
564
- plot_eq(),
565
- plot_comp(),
566
- plot_delay(),
567
- plot_reverb(),
568
- plot_t60(),
569
- ]
570
- + [
571
- pk1.params.freq.item(),
572
- pk1.params.gain.item(),
573
- pk1.params.Q.item(),
574
- pk2.params.freq.item(),
575
- pk2.params.gain.item(),
576
- pk2.params.Q.item(),
577
- ls.params.freq.item(),
578
- ls.params.gain.item(),
579
- hs.params.freq.item(),
580
- hs.params.gain.item(),
581
- ],
582
  ),
583
  inputs=extra_pc_dropdown,
584
- outputs=sliders
585
- + [
586
- extra_slider,
587
- json_output,
588
- peq_plot,
589
- comp_plot,
590
- delay_plot,
591
- reverb_plot,
592
- t60_plot,
593
- ]
594
- + [
595
- pk1_freq,
596
- pk1_gain,
597
- pk1_q,
598
- pk2_freq,
599
- pk2_gain,
600
- pk2_q,
601
- ls_freq,
602
- ls_gain,
603
- hs_freq,
604
- hs_gain,
605
- ],
606
  )
607
  reset_button.click(
608
  # lambda: (lambda _: [0 for _ in range(NUMBER_OF_PCS + 1)])(z.zero_()),
609
  lambda: chain_functions(
610
  lambda _: z.zero_(),
611
  lambda _: z2fx(),
612
- lambda _: [0 for _ in range(NUMBER_OF_PCS + 1)]
613
- + [
614
- model2json(),
615
- plot_eq(),
616
- plot_comp(),
617
- plot_delay(),
618
- plot_reverb(),
619
- plot_t60(),
620
- ]
621
- + [
622
- pk1.params.freq.item(),
623
- pk1.params.gain.item(),
624
- pk1.params.Q.item(),
625
- pk2.params.freq.item(),
626
- pk2.params.gain.item(),
627
- pk2.params.Q.item(),
628
- ls.params.freq.item(),
629
- ls.params.gain.item(),
630
- hs.params.freq.item(),
631
- hs.params.gain.item(),
632
- ],
633
  )(None),
634
- # inputs=sliders + [extra_slider],
635
- outputs=sliders
636
- + [
637
- extra_slider,
638
- json_output,
639
- peq_plot,
640
- comp_plot,
641
- delay_plot,
642
- reverb_plot,
643
- t60_plot,
644
- ]
645
- + [
646
- pk1_freq,
647
- pk1_gain,
648
- pk1_q,
649
- pk2_freq,
650
- pk2_gain,
651
- pk2_q,
652
- ls_freq,
653
- ls_gain,
654
- hs_freq,
655
- hs_gain,
656
- ],
657
  )
658
 
659
  def update_z(s, i):
@@ -665,87 +664,19 @@ with gr.Blocks() as demo:
665
  chain_functions(
666
  partial(update_z, i=i),
667
  lambda _: z2fx(),
668
- lambda _: (
669
- model2json(),
670
- plot_eq(),
671
- plot_comp(),
672
- plot_delay(),
673
- plot_reverb(),
674
- plot_t60(),
675
- pk1.params.freq.item(),
676
- pk1.params.gain.item(),
677
- pk1.params.Q.item(),
678
- pk2.params.freq.item(),
679
- pk2.params.gain.item(),
680
- pk2.params.Q.item(),
681
- ls.params.freq.item(),
682
- ls.params.gain.item(),
683
- hs.params.freq.item(),
684
- hs.params.gain.item(),
685
- ),
686
  ),
687
  inputs=slider,
688
- outputs=[
689
- json_output,
690
- peq_plot,
691
- comp_plot,
692
- delay_plot,
693
- reverb_plot,
694
- t60_plot,
695
- pk1_freq,
696
- pk1_gain,
697
- pk1_q,
698
- pk2_freq,
699
- pk2_gain,
700
- pk2_q,
701
- ls_freq,
702
- ls_gain,
703
- hs_freq,
704
- hs_gain,
705
- ],
706
  )
707
  extra_slider.input(
708
  lambda *xs: chain_functions(
709
  lambda args: update_z(args[0], args[1] - 1),
710
  lambda _: z2fx(),
711
- lambda _: (
712
- model2json(),
713
- plot_eq(),
714
- plot_comp(),
715
- plot_delay(),
716
- plot_reverb(),
717
- plot_t60(),
718
- pk1.params.freq.item(),
719
- pk1.params.gain.item(),
720
- pk1.params.Q.item(),
721
- pk2.params.freq.item(),
722
- pk2.params.gain.item(),
723
- pk2.params.Q.item(),
724
- ls.params.freq.item(),
725
- ls.params.gain.item(),
726
- hs.params.freq.item(),
727
- hs.params.gain.item(),
728
- ),
729
  )(xs),
730
  inputs=[extra_slider, extra_pc_dropdown],
731
- outputs=[
732
- json_output,
733
- peq_plot,
734
- comp_plot,
735
- delay_plot,
736
- reverb_plot,
737
- t60_plot,
738
- pk1_freq,
739
- pk1_gain,
740
- pk1_q,
741
- pk2_freq,
742
- pk2_gain,
743
- pk2_q,
744
- ls_freq,
745
- ls_gain,
746
- hs_freq,
747
- hs_gain,
748
- ],
749
  )
750
 
751
  extra_pc_dropdown.input(
 
393
  peq_plot = gr.Plot(
394
  plot_eq(), label="PEQ Frequency Response", elem_id="peq-plot"
395
  )
396
+ with gr.Row():
397
+ with gr.Column(min_width=160):
398
+ _ = gr.Markdown("High Pass")
399
+ hp = fx[5]
400
+ hp_freq = gr.Slider(
401
+ minimum=16,
402
+ maximum=5300,
403
+ value=hp.params.freq.item(),
404
+ interactive=True,
405
+ label="Frequency (Hz)",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406
  )
407
+ hp_q = gr.Slider(
408
+ minimum=0.5,
409
+ maximum=10,
410
+ value=hp.params.Q.item(),
411
+ interactive=True,
412
+ label="Q",
413
  )
414
+
415
+ with gr.Column(min_width=160):
416
+ _ = gr.Markdown("Low Shelf")
417
+ ls = fx[2]
418
+ ls_freq = gr.Slider(
419
+ minimum=30,
420
+ maximum=200,
421
+ value=ls.params.freq.item(),
422
+ interactive=True,
423
+ label="Frequency (Hz)",
424
+ )
425
+ ls_gain = gr.Slider(
426
+ minimum=-12,
427
+ maximum=12,
428
+ value=ls.params.gain.item(),
429
+ interactive=True,
430
+ label="Gain (dB)",
431
  )
432
+
433
+ with gr.Column(min_width=160):
434
+ _ = gr.Markdown("Peak filter 1")
435
+ pk1 = fx[0]
436
+ pk1_freq = gr.Slider(
437
+ minimum=33,
438
+ maximum=5400,
439
+ value=pk1.params.freq.item(),
440
+ interactive=True,
441
+ label="Frequency (Hz)",
442
+ )
443
+ pk1_gain = gr.Slider(
444
+ minimum=-12,
445
+ maximum=12,
446
+ value=pk1.params.gain.item(),
447
+ interactive=True,
448
+ label="Gain (dB)",
449
+ )
450
+ pk1_q = gr.Slider(
451
+ minimum=0.2,
452
+ maximum=20,
453
+ value=pk1.params.Q.item(),
454
+ interactive=True,
455
+ label="Q",
456
+ )
457
+ with gr.Column(min_width=160):
458
+ _ = gr.Markdown("Peak filter 2")
459
+ pk2 = fx[1]
460
+ pk2_freq = gr.Slider(
461
+ minimum=200,
462
+ maximum=17500,
463
+ value=pk2.params.freq.item(),
464
+ interactive=True,
465
+ label="Frequency (Hz)",
466
+ )
467
+ pk2_gain = gr.Slider(
468
+ minimum=-12,
469
+ maximum=12,
470
+ value=pk2.params.gain.item(),
471
+ interactive=True,
472
+ label="Gain (dB)",
473
+ )
474
+ pk2_q = gr.Slider(
475
+ minimum=0.2,
476
+ maximum=20,
477
+ value=pk2.params.Q.item(),
478
+ interactive=True,
479
+ label="Q",
480
+ )
481
+
482
+ with gr.Column(min_width=160):
483
+ _ = gr.Markdown("High Shelf")
484
+ hs = fx[3]
485
+ hs_freq = gr.Slider(
486
+ minimum=750,
487
+ maximum=8300,
488
+ value=hs.params.freq.item(),
489
+ interactive=True,
490
+ label="Frequency (Hz)",
491
+ )
492
+ hs_gain = gr.Slider(
493
+ minimum=-12,
494
+ maximum=12,
495
+ value=hs.params.gain.item(),
496
+ interactive=True,
497
+ label="Gain (dB)",
498
+ )
499
+ with gr.Column(min_width=160):
500
+ _ = gr.Markdown("Low Pass")
501
+ lp = fx[4]
502
+ lp_freq = gr.Slider(
503
+ minimum=200,
504
+ maximum=18000,
505
+ value=lp.params.freq.item(),
506
+ interactive=True,
507
+ label="Frequency (Hz)",
508
+ )
509
+ lp_q = gr.Slider(
510
+ minimum=0.5,
511
+ maximum=10,
512
+ value=lp.params.Q.item(),
513
+ interactive=True,
514
+ label="Q",
515
+ )
516
+
517
+ comp_plot = gr.Plot(plot_comp(), label="Compressor Curve", elem_id="comp-plot")
518
+ delay_plot = gr.Plot(
519
+ plot_delay(), label="Delay Frequency Response", elem_id="delay-plot"
520
+ )
521
+ reverb_plot = gr.Plot(
522
+ plot_reverb(), label="Reverb Tone Correction PEQ", elem_id="reverb-plot"
523
+ )
524
+ t60_plot = gr.Plot(plot_t60(), label="Reverb T60", elem_id="t60-plot")
525
 
526
  with gr.Row():
527
  json_output = gr.JSON(
528
  model2json(), label="Effect Settings", max_height=800, open=True
529
  )
530
 
531
+ update_pc = lambda i: z[:NUMBER_OF_PCS].tolist() + [z[i - 1].item()]
532
+ update_pc_outputs = sliders + [extra_slider]
533
+
534
  for eq, s, attr_name in zip(
535
+ [fx[0]] * 3
536
+ + [fx[1]] * 3
537
+ + [fx[2]] * 2
538
+ + [fx[3]] * 2
539
+ + [fx[4]] * 2
540
+ + [fx[5]] * 2,
541
  [
542
  pk1_freq,
543
  pk1_gain,
 
549
  ls_gain,
550
  hs_freq,
551
  hs_gain,
552
+ lp_freq,
553
+ lp_q,
554
+ hp_freq,
555
+ hp_q,
556
  ],
557
+ ["freq", "gain", "Q"] * 2 + ["freq", "gain"] * 2 + ["freq", "Q"] * 2,
558
  ):
559
  s.input(
560
  lambda *args, eq=eq, attr_name=attr_name: chain_functions( # chain_functions(
561
  lambda args: (upatePEQ(eq, attr_name, args[0]), args[1]),
562
  lambda args: (fx2z(), args[1]),
563
+ lambda args: args[1],
564
+ lambda i: update_pc(i) + [model2json(), plot_eq()],
 
565
  )(
566
  args
567
  ),
568
  inputs=[s, extra_pc_dropdown],
569
+ outputs=update_pc_outputs + [json_output, peq_plot],
570
  )
571
 
572
  render_button.click(
573
+ # lambda *args: (
574
+ # lambda x: (
575
+ # x,
576
+ # model2json(),
577
+ # )
578
+ # )(inference(*args)),
579
+ inference,
 
 
 
 
580
  inputs=[
581
  audio_input,
582
+ ],
 
 
 
583
  outputs=[
584
  audio_output,
 
 
 
 
 
 
585
  ],
586
  )
587
 
588
+ update_fx = lambda: [
589
+ pk1.params.freq.item(),
590
+ pk1.params.gain.item(),
591
+ pk1.params.Q.item(),
592
+ pk2.params.freq.item(),
593
+ pk2.params.gain.item(),
594
+ pk2.params.Q.item(),
595
+ ls.params.freq.item(),
596
+ ls.params.gain.item(),
597
+ hs.params.freq.item(),
598
+ hs.params.gain.item(),
599
+ lp.params.freq.item(),
600
+ lp.params.Q.item(),
601
+ hp.params.freq.item(),
602
+ hp.params.Q.item(),
603
+ ]
604
+ update_fx_outputs = [
605
+ pk1_freq,
606
+ pk1_gain,
607
+ pk1_q,
608
+ pk2_freq,
609
+ pk2_gain,
610
+ pk2_q,
611
+ ls_freq,
612
+ ls_gain,
613
+ hs_freq,
614
+ hs_gain,
615
+ lp_freq,
616
+ lp_q,
617
+ hp_freq,
618
+ hp_q,
619
+ ]
620
+ update_plots = lambda: [
621
+ plot_eq(),
622
+ plot_comp(),
623
+ plot_delay(),
624
+ plot_reverb(),
625
+ plot_t60(),
626
+ ]
627
+ update_plots_outputs = [
628
+ peq_plot,
629
+ comp_plot,
630
+ delay_plot,
631
+ reverb_plot,
632
+ t60_plot,
633
+ ]
634
+
635
+ update_all = lambda i: update_pc(i) + update_fx() + update_plots()
636
+ update_all_outputs = update_pc_outputs + update_fx_outputs + update_plots_outputs
637
+
638
  random_button.click(
 
 
 
 
 
 
 
 
 
 
639
  chain_functions(
640
  lambda i: (z.normal_(0, 1).clip_(SLIDER_MIN, SLIDER_MAX), i),
641
+ lambda args: (z2fx(), args[1]),
642
+ lambda args: args[1],
643
+ update_all,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
644
  ),
645
  inputs=extra_pc_dropdown,
646
+ outputs=update_all_outputs,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
647
  )
648
  reset_button.click(
649
  # lambda: (lambda _: [0 for _ in range(NUMBER_OF_PCS + 1)])(z.zero_()),
650
  lambda: chain_functions(
651
  lambda _: z.zero_(),
652
  lambda _: z2fx(),
653
+ lambda _: update_all(NUMBER_OF_PCS),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
654
  )(None),
655
+ outputs=update_all_outputs,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
656
  )
657
 
658
  def update_z(s, i):
 
664
  chain_functions(
665
  partial(update_z, i=i),
666
  lambda _: z2fx(),
667
+ lambda _: update_fx() + update_plots() + [model2json()],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
668
  ),
669
  inputs=slider,
670
+ outputs=update_fx_outputs + update_plots_outputs + [json_output],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
671
  )
672
  extra_slider.input(
673
  lambda *xs: chain_functions(
674
  lambda args: update_z(args[0], args[1] - 1),
675
  lambda _: z2fx(),
676
+ lambda _: update_fx() + update_plots() + [model2json()],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
677
  )(xs),
678
  inputs=[extra_slider, extra_pc_dropdown],
679
+ outputs=update_fx_outputs + update_plots_outputs + [json_output],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
680
  )
681
 
682
  extra_pc_dropdown.input(