ongudidan commited on
Commit
3d3121f
·
1 Parent(s): fb3ee9b

refactor: simplify Gradio UI layout, remove custom styling, and update demo components

Browse files
Files changed (1) hide show
  1. app.py +50 -91
app.py CHANGED
@@ -373,141 +373,100 @@ def toggle(choice):
373
  return gr.update(visible=False, value=None), gr.update(visible=True, value=None)
374
 
375
 
376
- theme = gr.themes.Soft(
377
- primary_hue="blue",
378
- secondary_hue="indigo",
379
- neutral_hue="slate",
380
- font=[gr.themes.GoogleFont("Inter"), "ui-sans-serif", "sans-serif"],
381
- )
382
-
383
- css = """
384
- .gradio-container {
385
- max-width: 1150px !important;
386
- }
387
- .generate-btn {
388
- background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important;
389
- color: white !important;
390
- border: none !important;
391
- font-weight: 600 !important;
392
- transition: all 0.2s ease-in-out !important;
393
- box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.2) !important;
394
- }
395
- .generate-btn:hover {
396
- background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%) !important;
397
- transform: translateY(-1px) !important;
398
- box-shadow: 0 6px 15px rgba(37, 99, 235, 0.35) !important;
399
- }
400
- """
401
-
402
- with gr.Blocks(theme=theme, css=css) as demo:
403
  with gr.Row():
404
  gr.Markdown(
405
  """
406
- # 🎙️ DeepFilterNet Audio Studio
407
- Enhance voice recordings using **DeepFilterNet2** — an ultra-fast, real-time speech enhancement model.
408
- Adjust settings below to clean up background noise and customize vocal EQ characteristics.
409
  """
410
  )
411
  with gr.Row():
412
  with gr.Column():
413
- gr.Markdown("### 📂 1. Audio Source")
414
  radio = gr.Radio(
415
- ["mic", "file"], value="file", label="Input Method"
416
  )
417
- mic_input = gr.Mic(label="Record Voice", type="filepath", visible=False)
418
- audio_file = gr.Audio(type="filepath", label="Upload Audio File", visible=True)
419
-
420
- gr.Markdown("### 🔊 2. Noise Simulation (Optional)")
421
- with gr.Group():
422
- noise_select = gr.Dropdown(
423
- label="Add Background Noise",
424
  choices=list(NOISES.keys()),
425
  value="None",
426
- )
427
- snr_select = gr.Dropdown(
428
- label="Simulated Noise Level (SNR)",
429
  choices=["-5", "0", "10", "20"],
430
  value="10",
431
- )
432
-
433
- gr.Markdown("### ⚙️ 3. Denoising Settings")
434
- with gr.Group():
435
- atten_slider = gr.Slider(
436
  minimum=6,
437
  maximum=35,
438
  step=1,
439
  value=15,
440
- label="Max Attenuation (dB) - lower keeps natural room tone, higher reduces more noise",
441
- )
442
- blend_slider = gr.Slider(
443
  minimum=50,
444
  maximum=100,
445
  step=5,
446
  value=90,
447
- label="Voice Naturalness Mix (%) - blends original signal back to preserve transients",
448
- )
449
-
450
- with gr.Accordion("🎨 4. Advanced Vocal EQ & Presence", open=False):
451
- post_process_cb = gr.Checkbox(
452
  label="Enable Post-Processing EQ & Filters",
453
  value=True,
454
- )
455
- low_cut_slider = gr.Slider(
456
  minimum=20,
457
  maximum=200,
458
  step=10,
459
  value=80,
460
- label="Low-Cut Filter Cutoff (Hz) - removes sub-bass rumble/AC hum",
461
- )
462
- bass_slider = gr.Slider(
463
  minimum=-10,
464
  maximum=10,
465
  step=1,
466
  value=0,
467
- label="Voice Bass Boost (dB) at 150Hz - adds body/warmth to thin voices",
468
- )
469
- treble_slider = gr.Slider(
470
  minimum=-10,
471
  maximum=10,
472
  step=1,
473
  value=3,
474
- label="Voice Treble Boost (dB) at 6kHz - adds sibilance/crispness",
475
- )
476
-
477
- inputs = [
478
- radio,
479
- audio_file,
480
- noise_select,
481
- snr_select,
482
- atten_slider,
483
- blend_slider,
484
- post_process_cb,
485
- low_cut_slider,
486
- bass_slider,
487
- treble_slider,
488
  mic_input,
489
  ]
490
- btn = gr.Button("Generate Denoised Audio", elem_classes="generate-btn")
491
  with gr.Column():
492
- gr.Markdown("### 📊 Results & Visualization")
493
  outputs = [
494
- gr.Audio(type="filepath", label="Noisy Audio (Input)"),
495
- gr.Image(label="Noisy Spectrogram"),
496
- gr.Audio(type="filepath", label="Enhanced Audio (Output)"),
497
- gr.Image(label="Enhanced Spectrogram"),
 
 
498
  ]
499
  btn.click(fn=demo_fn, inputs=inputs, outputs=outputs, api_name='denoise')
500
  radio.change(toggle, radio, [mic_input, audio_file])
501
  gr.Examples(
502
- examples=[
503
- ["./samples/p232_013_clean.wav", "Kitchen", "10"],
504
- ["./samples/p232_013_clean.wav", "Cafe", "10"],
505
- ["./samples/p232_019_clean.wav", "Cafe", "10"],
506
- ["./samples/p232_019_clean.wav", "River", "10"],
507
  ],
508
- inputs=[audio_file, noise_select, snr_select],
509
- label="💡 Quick Start Demo Examples (Click to load)",
510
- )
 
 
511
  gr.Markdown(open("usage.md").read())
512
 
513
  cleanup_tmp()
 
373
  return gr.update(visible=False, value=None), gr.update(visible=True, value=None)
374
 
375
 
376
+ with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
377
  with gr.Row():
378
  gr.Markdown(
379
  """
380
+ ## DeepFilterNet2 Demo\
381
+
382
+ This demo denoises audio files using DeepFilterNet. Try it with your own voice!
383
  """
384
  )
385
  with gr.Row():
386
  with gr.Column():
 
387
  radio = gr.Radio(
388
+ ["mic", "file"], value="file", label="How would you like to upload your audio?"
389
  )
390
+ mic_input = gr.Mic(label="Input", type="filepath", visible=False)
391
+ audio_file = gr.Audio(type="filepath", label="Input", visible=True)
392
+ inputs = [
393
+ radio,
394
+ audio_file,
395
+ gr.Dropdown(
396
+ label="Add background noise",
397
  choices=list(NOISES.keys()),
398
  value="None",
399
+ ),
400
+ gr.Dropdown(
401
+ label="Noise Level (SNR)",
402
  choices=["-5", "0", "10", "20"],
403
  value="10",
404
+ ),
405
+ gr.Slider(
 
 
 
406
  minimum=6,
407
  maximum=35,
408
  step=1,
409
  value=15,
410
+ label="Max Attenuation (dB) - lower is more natural/clear, higher reduces more noise",
411
+ ),
412
+ gr.Slider(
413
  minimum=50,
414
  maximum=100,
415
  step=5,
416
  value=90,
417
+ label="Voice Naturalness Mix (%) - 100% is fully denoised, 90% blends back some original voice",
418
+ ),
419
+ gr.Checkbox(
 
 
420
  label="Enable Post-Processing EQ & Filters",
421
  value=True,
422
+ ),
423
+ gr.Slider(
424
  minimum=20,
425
  maximum=200,
426
  step=10,
427
  value=80,
428
+ label="Low-Cut Filter Cutoff (Hz) - cuts muddy AC rumble/handling noise",
429
+ ),
430
+ gr.Slider(
431
  minimum=-10,
432
  maximum=10,
433
  step=1,
434
  value=0,
435
+ label="Voice Bass EQ Boost (dB) at 150Hz - adds warmth",
436
+ ),
437
+ gr.Slider(
438
  minimum=-10,
439
  maximum=10,
440
  step=1,
441
  value=3,
442
+ label="Voice Treble EQ Boost (dB) at 6kHz - adds crispness/air",
443
+ ),
 
 
 
 
 
 
 
 
 
 
 
 
444
  mic_input,
445
  ]
446
+ btn = gr.Button("Generate")
447
  with gr.Column():
 
448
  outputs = [
449
+ # gr.Video(type="filepath", label="Noisy audio"),
450
+ gr.Audio(type="filepath", label="Noisy audio"),
451
+ gr.Image(label="Noisy spectrogram"),
452
+ # gr.Video(type="filepath", label="Enhanced audio"),
453
+ gr.Audio(type="filepath", label="Enhanced audio"),
454
+ gr.Image(label="Enhanced spectrogram"),
455
  ]
456
  btn.click(fn=demo_fn, inputs=inputs, outputs=outputs, api_name='denoise')
457
  radio.change(toggle, radio, [mic_input, audio_file])
458
  gr.Examples(
459
+ [
460
+ ["file", "./samples/p232_013_clean.wav", "Kitchen", "10", 15, 90, True, 80, 0, 3, None],
461
+ ["file", "./samples/p232_013_clean.wav", "Cafe", "10", 15, 90, True, 80, 0, 3, None],
462
+ ["file", "./samples/p232_019_clean.wav", "Cafe", "10", 15, 90, True, 80, 0, 3, None],
463
+ ["file", "./samples/p232_019_clean.wav", "River", "10", 15, 90, True, 80, 0, 3, None],
464
  ],
465
+ fn=demo_fn,
466
+ inputs=inputs,
467
+ outputs=outputs,
468
+ cache_examples=True,
469
+ ),
470
  gr.Markdown(open("usage.md").read())
471
 
472
  cleanup_tmp()