Hendrik Schroeter commited on
Commit
3db022a
1 Parent(s): 21fe9a1

Move to pillow due to buggy gradio plot

Browse files
Files changed (2) hide show
  1. app.py +9 -17
  2. requirements.txt +1 -0
app.py CHANGED
@@ -8,6 +8,7 @@ import gradio.outputs
8
  import markdown
9
  import matplotlib.pyplot as plt
10
  import numpy as np
 
11
  import torch
12
  from loguru import logger
13
  from torch import Tensor
@@ -144,9 +145,9 @@ def demo_fn(speech_upl: str, noise_type: str, snr: int):
144
  ax_enh.clear()
145
  return (
146
  gradio.make_waveform(noisy_fn, bar_count=200),
147
- spec_figure(sample, sr=sr, figure=fig_noisy, ax=ax_noisy),
148
  gradio.make_waveform(enhanced_fn, bar_count=200),
149
- spec_figure(enhanced, sr=sr, figure=fig_enh, ax=ax_enh),
150
  )
151
 
152
 
@@ -208,16 +209,15 @@ def specshow(
208
  return im
209
 
210
 
211
- def spec_figure(
212
  audio: torch.Tensor,
213
  figsize=(15, 5),
214
  colorbar=False,
215
  colorbar_format=None,
216
  figure=None,
217
- return_im=False,
218
  labels=True,
219
  **kwargs,
220
- ) -> plt.Figure:
221
  audio = torch.as_tensor(audio)
222
  if labels:
223
  kwargs.setdefault("xlabel", "Time [s]")
@@ -244,17 +244,11 @@ def spec_figure(
244
  colorbar_format = "%+2.0f dB"
245
  ckwargs = {"ax": kwargs["ax"]}
246
  plt.colorbar(im, format=colorbar_format, **ckwargs)
247
- if return_im:
248
- return im
249
- return figure
250
 
251
 
252
  inputs = [
253
- # gradio.inputs.Audio(
254
- # label="Record your own voice",
255
- # source="microphone",
256
- # type="numpy",
257
- # ),
258
  gradio.Audio(
259
  label="Upload audio sample",
260
  source="upload",
@@ -273,11 +267,9 @@ inputs = [
273
  ]
274
  outputs = [
275
  gradio.Video(type="filepath", label="Noisy audio"),
276
- # gradio.Audio(type="filepath", label="Noisy audio"),
277
- gradio.Plot(label="Noisy spectrogram"),
278
  gradio.Video(type="filepath", label="Noisy audio"),
279
- # gradio.Audio(type="filepath", label="Enhanced audio"),
280
- gradio.Plot(label="Enhanced spectrogram"),
281
  ]
282
  description = "This demo denoises audio files using DeepFilterNet. Try it with your own voice!"
283
  iface = gradio.Interface(
 
8
  import markdown
9
  import matplotlib.pyplot as plt
10
  import numpy as np
11
+ from PIL import Image
12
  import torch
13
  from loguru import logger
14
  from torch import Tensor
 
145
  ax_enh.clear()
146
  return (
147
  gradio.make_waveform(noisy_fn, bar_count=200),
148
+ spec_im(sample, sr=sr, figure=fig_noisy, ax=ax_noisy),
149
  gradio.make_waveform(enhanced_fn, bar_count=200),
150
+ spec_im(enhanced, sr=sr, figure=fig_enh, ax=ax_enh),
151
  )
152
 
153
 
 
209
  return im
210
 
211
 
212
+ def spec_im(
213
  audio: torch.Tensor,
214
  figsize=(15, 5),
215
  colorbar=False,
216
  colorbar_format=None,
217
  figure=None,
 
218
  labels=True,
219
  **kwargs,
220
+ ) -> Image:
221
  audio = torch.as_tensor(audio)
222
  if labels:
223
  kwargs.setdefault("xlabel", "Time [s]")
 
244
  colorbar_format = "%+2.0f dB"
245
  ckwargs = {"ax": kwargs["ax"]}
246
  plt.colorbar(im, format=colorbar_format, **ckwargs)
247
+ figure.canvas.draw()
248
+ return Image.frombytes("RGB", figure.canvas.get_width_height(), figure.canvas.tostring_rgb())
 
249
 
250
 
251
  inputs = [
 
 
 
 
 
252
  gradio.Audio(
253
  label="Upload audio sample",
254
  source="upload",
 
267
  ]
268
  outputs = [
269
  gradio.Video(type="filepath", label="Noisy audio"),
270
+ gradio.Image(label="Noisy spectrogram"),
 
271
  gradio.Video(type="filepath", label="Noisy audio"),
272
+ gradio.Image(label="Enhanced spectrogram"),
 
273
  ]
274
  description = "This demo denoises audio files using DeepFilterNet. Try it with your own voice!"
275
  iface = gradio.Interface(
requirements.txt CHANGED
@@ -4,3 +4,4 @@ deepfilternet==0.4.0
4
  matplotlib==3.6
5
  markdown==3.4
6
  gradio==3.17
 
 
4
  matplotlib==3.6
5
  markdown==3.4
6
  gradio==3.17
7
+ Pillow==9.3