Spaces:
Build error
Build error
Small UI improvements, Examples (#2)
Browse files- Small UI improvements, Examples (e5d77745845e4c35a9692eed99d9c1f6b79af38a)
Co-authored-by: Radamés Ajna <[email protected]>
README.md
CHANGED
|
@@ -5,6 +5,7 @@ colorFrom: gray
|
|
| 5 |
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
app_file: app.py
|
|
|
|
| 8 |
pinned: false
|
| 9 |
license: apache-2.0
|
| 10 |
---
|
|
|
|
| 5 |
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
app_file: app.py
|
| 8 |
+
sdk_version: 3.17.1
|
| 9 |
pinned: false
|
| 10 |
license: apache-2.0
|
| 11 |
---
|
app.py
CHANGED
|
@@ -1,10 +1,7 @@
|
|
| 1 |
import math
|
| 2 |
import tempfile
|
| 3 |
from typing import Optional, Tuple, Union
|
| 4 |
-
|
| 5 |
-
import gradio
|
| 6 |
-
import gradio.inputs
|
| 7 |
-
import gradio.outputs
|
| 8 |
import markdown
|
| 9 |
import matplotlib.pyplot as plt
|
| 10 |
import numpy as np
|
|
@@ -100,7 +97,9 @@ def load_audio_gradio(
|
|
| 100 |
return audio, meta
|
| 101 |
|
| 102 |
|
| 103 |
-
def demo_fn(speech_upl: str, noise_type: str, snr: int):
|
|
|
|
|
|
|
| 104 |
sr = config("sr", 48000, int, section="df")
|
| 105 |
logger.info(f"Got parameters speech_upl: {speech_upl}, noise: {noise_type}, snr: {snr}")
|
| 106 |
snr = int(snr)
|
|
@@ -145,8 +144,8 @@ def demo_fn(speech_upl: str, noise_type: str, snr: int):
|
|
| 145 |
ax_enh.clear()
|
| 146 |
noisy_im = spec_im(sample, sr=sr, figure=fig_noisy, ax=ax_noisy)
|
| 147 |
enh_im = spec_im(enhanced, sr=sr, figure=fig_enh, ax=ax_enh)
|
| 148 |
-
# noisy_wav =
|
| 149 |
-
# enh_wav =
|
| 150 |
return noisy_wav, noisy_im, enhanced_wav, enh_im
|
| 151 |
|
| 152 |
|
|
@@ -247,39 +246,57 @@ def spec_im(
|
|
| 247 |
return Image.frombytes("RGB", figure.canvas.get_width_height(), figure.canvas.tostring_rgb())
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import math
|
| 2 |
import tempfile
|
| 3 |
from typing import Optional, Tuple, Union
|
| 4 |
+
import gradio as gr
|
|
|
|
|
|
|
|
|
|
| 5 |
import markdown
|
| 6 |
import matplotlib.pyplot as plt
|
| 7 |
import numpy as np
|
|
|
|
| 97 |
return audio, meta
|
| 98 |
|
| 99 |
|
| 100 |
+
def demo_fn(speech_upl: str, noise_type: str, snr: int, mic_input: str):
|
| 101 |
+
if (mic_input):
|
| 102 |
+
speech_upl = mic_input
|
| 103 |
sr = config("sr", 48000, int, section="df")
|
| 104 |
logger.info(f"Got parameters speech_upl: {speech_upl}, noise: {noise_type}, snr: {snr}")
|
| 105 |
snr = int(snr)
|
|
|
|
| 144 |
ax_enh.clear()
|
| 145 |
noisy_im = spec_im(sample, sr=sr, figure=fig_noisy, ax=ax_noisy)
|
| 146 |
enh_im = spec_im(enhanced, sr=sr, figure=fig_enh, ax=ax_enh)
|
| 147 |
+
# noisy_wav = gr.make_waveform(noisy_fn, bar_count=200)
|
| 148 |
+
# enh_wav = gr.make_waveform(enhanced_fn, bar_count=200)
|
| 149 |
return noisy_wav, noisy_im, enhanced_wav, enh_im
|
| 150 |
|
| 151 |
|
|
|
|
| 246 |
return Image.frombytes("RGB", figure.canvas.get_width_height(), figure.canvas.tostring_rgb())
|
| 247 |
|
| 248 |
|
| 249 |
+
def toggle(choice):
|
| 250 |
+
if choice == "mic":
|
| 251 |
+
return gr.update(visible=True, value=None), gr.update(visible=False, value=None)
|
| 252 |
+
else:
|
| 253 |
+
return gr.update(visible=False, value=None), gr.update(visible=True, value=None)
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
with gr.Blocks() as demo:
|
| 257 |
+
with gr.Row():
|
| 258 |
+
gr.Markdown("## DeepFilterNet2 Demo")
|
| 259 |
+
gr.Markdown("This demo denoises audio files using DeepFilterNet. Try it with your own voice!")
|
| 260 |
+
with gr.Row():
|
| 261 |
+
with gr.Column():
|
| 262 |
+
radio = gr.Radio(["mic", "file"], value="file",
|
| 263 |
+
label="How would you like to upload your audio?")
|
| 264 |
+
mic_input = gr.Mic(label="Input", type="filepath", visible=False)
|
| 265 |
+
audio_file = gr.Audio(
|
| 266 |
+
type="filepath", label="Input", visible=True)
|
| 267 |
+
inputs = [
|
| 268 |
+
audio_file,
|
| 269 |
+
gr.Dropdown(
|
| 270 |
+
label="Add background noise",
|
| 271 |
+
choices=list(NOISES.keys()),
|
| 272 |
+
value="None",
|
| 273 |
+
),
|
| 274 |
+
gr.Dropdown(
|
| 275 |
+
label="Noise Level (SNR)",
|
| 276 |
+
choices=["-5", "0", "10", "20"],
|
| 277 |
+
value="10",
|
| 278 |
+
),
|
| 279 |
+
mic_input
|
| 280 |
+
]
|
| 281 |
+
btn = gr.Button("Generate")
|
| 282 |
+
with gr.Column():
|
| 283 |
+
outputs = [
|
| 284 |
+
# gr.Video(type="filepath", label="Noisy audio"),
|
| 285 |
+
gr.Audio(type="filepath", label="Noisy audio"),
|
| 286 |
+
gr.Image(label="Noisy spectrogram"),
|
| 287 |
+
# gr.Video(type="filepath", label="Enhanced audio"),
|
| 288 |
+
gr.Audio(type="filepath", label="Enhanced audio"),
|
| 289 |
+
gr.Image(label="Enhanced spectrogram"),
|
| 290 |
+
]
|
| 291 |
+
btn.click(fn=demo_fn, inputs=inputs, outputs=outputs)
|
| 292 |
+
radio.change(toggle, radio, [mic_input, audio_file])
|
| 293 |
+
gr.Examples([
|
| 294 |
+
["./samples/p232_013_clean.wav", "Kitchen", "10"],
|
| 295 |
+
["./samples/p232_013_clean.wav", "Cafe", "10"],
|
| 296 |
+
["./samples/p232_019_clean.wav", "Cafe", "10"],
|
| 297 |
+
["./samples/p232_019_clean.wav", "River", "10"]],
|
| 298 |
+
fn=demo_fn, inputs=inputs, outputs=outputs, cache_examples=True),
|
| 299 |
+
gr.Markdown(open("usage.md").read())
|
| 300 |
+
|
| 301 |
+
|
| 302 |
+
demo.launch(enable_queue=True)
|