File size: 2,214 Bytes
b711fb4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95991a4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from audio_denoiser.AudioDenoiser import AudioDenoiser
from timeit import default_timer as timer
from datetime import datetime
import gradio as gr
from torchaudio import AudioMetaData
import torch
import tempfile
import os,pytz

tz = pytz.timezone('Asia/Singapore')
theme='remilia/Ghostly'
device = torch.device('cuda:0') if torch.cuda.is_available() else torch.device('cpu')


def denoiser(win, auto_scale):
    if win is None:
      gr.Warning('Audio does not exist. Please ensure that the audio has been successfully uploaded.')
      return None,None
    
    startTime=timer()
    denoiser = AudioDenoiser(device=device)
    temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.wav')
    wout = temp_file.name
    temp_file.close() 
    try:
      denoiser.process_audio_file(win, wout, auto_scale)
    except RuntimeError as e:
      gr.Warning(str(e))
      return None,None
    
    endTime=timer()
    info=(f'🆗Completion time: {round(endTime-startTime,4)}s')
    now=datetime.now(tz).strftime('%H:%M:%S')
    print(f'{now}-{info}')
    return wout,info

examples = [
    ["sample/exp1.wav", "sample/exp1_d.wav"],
    ["sample/exp2.wav", "sample/exp2_d.wav"]
]
with gr.Blocks(theme=theme) as app:
    gr.HTML('''
    <h1 style="font-size: 25px;">Audio Denoiser</h1>
    <p style="margin-bottom: 10px; font-size: 100%">
 
Originating from the project: <a href='https://github.com/jose-solorzano/audio-denoiser'>audio-denoiser</a><br>
model: <a href='https://huggingface.co/jose-h-solorzano/audio-denoiser-512-32-v1'>jose-h-solorzano/audio-denoiser-512-32-v1</a><br>

    </p>''')
    audio_in = gr.Audio(type="filepath", label="Upload Audio")
    btn=gr.Button(value='💥Remove Noise',variant="primary")
    scale = gr.Checkbox(
                label="Auto Scale",
                info='Recommended for low-volume input audio',
                value=True,
            )
    audio_out = gr.Audio(type="filepath", label="Denoised Audio")
    info=gr.Textbox(label='info')

    btn.click(
      denoiser,
      inputs=[audio_in, scale],
      outputs=[audio_out,info])

    examples = gr.Examples(examples=examples, inputs=audio_in, outputs=audio_out, fn=denoiser)

     

app.launch(share=True)