BorisovMaksim commited on
Commit
dc3ceb7
·
1 Parent(s): 08d9656

added demucs to app

Browse files
Files changed (2) hide show
  1. app.py +38 -25
  2. requirements.txt +3 -1
app.py CHANGED
@@ -3,34 +3,47 @@ import ffmpeg
3
  import gradio as gr
4
  from pathlib import Path
5
  from denoisers.SpectralGating import SpectralGating
 
 
 
 
 
6
 
7
- model = SpectralGating()
8
 
9
- def denoising_transform(audio):
10
- src_path = Path(__file__).parent.resolve() / Path("cache_wav/original/{}.wav".format(str(uuid.uuid4())))
11
- tgt_path = Path(__file__).parent.resolve() / Path("cache_wav/denoised/{}.wav".format(str(uuid.uuid4())))
12
- src_path.parent.mkdir(exist_ok=True, parents=True)
13
- tgt_path.parent.mkdir(exist_ok=True, parents=True)
14
- (ffmpeg.input(audio)
15
- .output(src_path.as_posix(), acodec='pcm_s16le', ac=1, ar=22050)
16
- .run()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  )
18
- model.predict(audio, tgt_path)
19
- return tgt_path
20
-
21
-
22
- demo = gr.Interface(
23
- fn=denoising_transform,
24
- inputs=gr.Audio(label="Source Audio", source="microphone", type='filepath'),
25
- outputs=gr.Audio(label="Target Audio", type='filepath'),
26
- examples=[
27
- ["testing/wavs/p232_071.wav"],
28
- ["testing/wavs/p232_284.wav"],
29
- ],
30
- title="Denoising",
31
- interpretation="default",
32
- )
33
 
34
- if __name__ == "__main__":
35
  demo.launch()
36
 
 
 
 
 
3
  import gradio as gr
4
  from pathlib import Path
5
  from denoisers.SpectralGating import SpectralGating
6
+ from huggingface_hub import hf_hub_download
7
+ from denoisers.demucs import Demucs
8
+ import hydra
9
+ from omegaconf import DictConfig
10
+ import torch
11
 
 
12
 
13
+
14
+ @hydra.main(version_base=None, config_path="conf", config_name="config")
15
+ def run_app(cfg: DictConfig):
16
+ model = Demucs(cfg['model'])
17
+ model_path = hf_hub_download(repo_id="BorisovMaksim/demucs", filename="Demucs_original_sr_epoch3.pt")
18
+ checkpoint = torch.load(model_path)
19
+ model.load_state_dict(checkpoint['model_state_dict'])
20
+
21
+ def denoising_transform(audio):
22
+ src_path = Path(__file__).parent.resolve() / Path("cache_wav/original/{}.wav".format(str(uuid.uuid4())))
23
+ tgt_path = Path(__file__).parent.resolve() / Path("cache_wav/denoised/{}.wav".format(str(uuid.uuid4())))
24
+ src_path.parent.mkdir(exist_ok=True, parents=True)
25
+ tgt_path.parent.mkdir(exist_ok=True, parents=True)
26
+ (ffmpeg.input(audio)
27
+ .output(src_path.as_posix(), acodec='pcm_s16le', ac=1, ar=22050)
28
+ .run()
29
+ )
30
+ model.predict(audio, tgt_path)
31
+ return tgt_path
32
+
33
+ demo = gr.Interface(
34
+ fn=denoising_transform,
35
+ inputs=gr.Audio(label="Source Audio", source="microphone", type='filepath'),
36
+ outputs=gr.Audio(label="Target Audio", type='filepath'),
37
+ examples=[
38
+ ["testing/wavs/p232_071.wav"],
39
+ ["testing/wavs/p232_284.wav"],
40
+ ],
41
+ title="Denoising"
42
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
 
44
+
45
  demo.launch()
46
 
47
+ if __name__ == "__main__":
48
+ run_app()
49
+
requirements.txt CHANGED
@@ -1,4 +1,6 @@
1
  ffmpeg-python
2
  noisereduce
3
  torch
4
- torchaudio
 
 
 
1
  ffmpeg-python
2
  noisereduce
3
  torch
4
+ torchaudio
5
+ hydra
6
+ omegaconf