Spaces:
Runtime error
Runtime error
Hendrik Schroeter
commited on
wip
Browse files- app.py +60 -4
- requirements.txt +2 -0
app.py
CHANGED
@@ -1,7 +1,63 @@
|
|
1 |
-
import gradio
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
return "Hello " + name + "!!"
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
iface.launch()
|
|
|
1 |
+
import gradio
|
2 |
+
import gradio.inputs
|
3 |
+
import gradio.outputs
|
4 |
+
import torch
|
5 |
+
from df.enhance import enhance, init_df
|
6 |
|
7 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
8 |
|
9 |
+
|
10 |
+
def mix_at_snr(clean, noise, snr, eps=1e-10):
|
11 |
+
"""Mix clean and noise signal at a given SNR.
|
12 |
+
|
13 |
+
Args:
|
14 |
+
clean: 1D Tensor with the clean signal to mix.
|
15 |
+
noise: 1D Tensor of shape.
|
16 |
+
snr: Signal to noise ratio.
|
17 |
+
|
18 |
+
Returns:
|
19 |
+
clean: 1D Tensor with gain changed according to the snr.
|
20 |
+
noise: 1D Tensor with the combined noise channels.
|
21 |
+
mix: 1D Tensor with added clean and noise signals.
|
22 |
+
|
23 |
+
"""
|
24 |
+
clean = torch.as_tensor(clean)
|
25 |
+
noise = torch.as_tensor(noise)
|
26 |
+
E_speech = torch.mean(clean.pow(2)) + eps
|
27 |
+
E_noise = torch.mean(noise.pow(2))
|
28 |
+
K = torch.sqrt((E_noise / E_speech) * 10 ** (snr / 10) + eps)
|
29 |
+
noise = noise / K
|
30 |
+
mixture = clean + noise
|
31 |
+
assert torch.isfinite(mixture)
|
32 |
+
return clean, noise, mixture
|
33 |
+
|
34 |
+
|
35 |
+
def mix_and_denoise(speech, noise, snr):
|
36 |
+
model, df, _ = init_df()
|
37 |
+
speech, noise, noisy = mix_at_snr(speech, noise, snr)
|
38 |
+
enhanced = enhance(model.to(device=device).eval(), df, noisy)
|
39 |
+
return speech, noisy, enhanced
|
40 |
+
|
41 |
+
|
42 |
+
inputs = [
|
43 |
+
gradio.inputs.Audio(
|
44 |
+
source="microphone", type="filepath", optional=True, label="Speech"
|
45 |
+
),
|
46 |
+
gradio.inputs.Audio(
|
47 |
+
source="microphone", type="filepath", optional=True, label="Noise"
|
48 |
+
),
|
49 |
+
gradio.inputs.Slider(minimum=-10, maximum=40, step=5, default=10),
|
50 |
+
]
|
51 |
+
examples = [
|
52 |
+
[],
|
53 |
+
["samples/noise_freesound_2530.wav", "samples/noise_freesound_573577.wav"],
|
54 |
+
]
|
55 |
+
outputs = [
|
56 |
+
gradio.outputs.Audio(label="Clean"),
|
57 |
+
gradio.outputs.Audio(label="Noisy"),
|
58 |
+
gradio.outputs.Audio(label="Enhanced"),
|
59 |
+
]
|
60 |
+
iface = gradio.Interface(
|
61 |
+
fn=mix_and_denoise, inputs=inputs, outputs=outputs, examples=examples
|
62 |
+
)
|
63 |
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
deepfilternet
|
2 |
+
gradio
|