Small UI improvements, Examples

#2
by radames - opened
Files changed (2) hide show
  1. README.md +1 -0
  2. app.py +60 -43
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 = gradio.make_waveform(noisy_fn, bar_count=200)
149
- # enh_wav = gradio.make_waveform(enhanced_fn, bar_count=200)
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
- inputs = [
251
- gradio.Audio(
252
- label="Upload audio sample",
253
- source="upload",
254
- type="filepath",
255
- ),
256
- gradio.Dropdown(
257
- label="Add background noise",
258
- choices=list(NOISES.keys()),
259
- value="None",
260
- ),
261
- gradio.Dropdown(
262
- label="Noise Level (SNR)",
263
- choices=["-5", "0", "10", "20"],
264
- value="10",
265
- ),
266
- ]
267
- outputs = [
268
- # gradio.Video(type="filepath", label="Noisy audio"),
269
- gradio.Audio(type="filepath", label="Noisy audio"),
270
- gradio.Image(label="Noisy spectrogram"),
271
- # gradio.Video(type="filepath", label="Enhanced audio"),
272
- gradio.Audio(type="filepath", label="Enhanced audio"),
273
- gradio.Image(label="Enhanced spectrogram"),
274
- ]
275
- description = "This demo denoises audio files using DeepFilterNet. Try it with your own voice!"
276
- iface = gradio.Interface(
277
- fn=demo_fn,
278
- title="DeepFilterNet2 Demo",
279
- inputs=inputs,
280
- outputs=outputs,
281
- description=description,
282
- allow_flagging="never",
283
- article=markdown.markdown(open("usage.md").read()),
284
- )
285
- iface.launch(debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)