Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,69 +1,69 @@
|
|
| 1 |
-
from audio_denoiser.AudioDenoiser import AudioDenoiser
|
| 2 |
-
from timeit import default_timer as timer
|
| 3 |
-
from datetime import datetime
|
| 4 |
-
import gradio as gr
|
| 5 |
-
from torchaudio import AudioMetaData
|
| 6 |
-
import torch
|
| 7 |
-
import tempfile
|
| 8 |
-
import os,pytz
|
| 9 |
-
|
| 10 |
-
tz = pytz.timezone('Asia/Singapore')
|
| 11 |
-
theme='remilia/Ghostly'
|
| 12 |
-
device = torch.device('cuda:0') if torch.cuda.is_available() else torch.device('cpu')
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
def denoiser(win, auto_scale):
|
| 16 |
-
if win is None:
|
| 17 |
-
gr.Warning('Audio does not exist. Please ensure that the audio has been successfully uploaded.')
|
| 18 |
-
return None,None
|
| 19 |
-
|
| 20 |
-
startTime=timer()
|
| 21 |
-
denoiser = AudioDenoiser(device=device)
|
| 22 |
-
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.wav')
|
| 23 |
-
wout = temp_file.name
|
| 24 |
-
temp_file.close()
|
| 25 |
-
try:
|
| 26 |
-
denoiser.process_audio_file(win, wout, auto_scale)
|
| 27 |
-
except RuntimeError as e:
|
| 28 |
-
gr.Warning(str(e))
|
| 29 |
-
return None,None
|
| 30 |
-
|
| 31 |
-
endTime=timer()
|
| 32 |
-
info=(f'🆗Completion time: {round(endTime-startTime,4)}s')
|
| 33 |
-
now=datetime.now(tz).strftime('%H:%M:%S')
|
| 34 |
-
print(f'{now}-{info}')
|
| 35 |
-
return wout,info
|
| 36 |
-
|
| 37 |
-
examples = [
|
| 38 |
-
["sample/exp1.wav", "sample/exp1_d.wav"],
|
| 39 |
-
["sample/exp2.wav", "sample/exp2_d.wav"]
|
| 40 |
-
]
|
| 41 |
-
with gr.Blocks(theme=theme) as app:
|
| 42 |
-
gr.HTML('''
|
| 43 |
-
<h1 style="font-size: 25px;">Audio Denoiser</h1>
|
| 44 |
-
<p style="margin-bottom: 10px; font-size: 100%">
|
| 45 |
-
|
| 46 |
-
Originating from the project: <a href='https://github.com/jose-solorzano/audio-denoiser'>audio-denoiser</a><br>
|
| 47 |
-
model: <a href='https://huggingface.co/jose-h-solorzano/audio-denoiser-512-32-v1'>jose-h-solorzano/audio-denoiser-512-32-v1</a><br>
|
| 48 |
-
|
| 49 |
-
</p>''')
|
| 50 |
-
audio_in = gr.Audio(type="filepath", label="Upload Audio")
|
| 51 |
-
btn=gr.Button(value='💥Remove Noise')
|
| 52 |
-
scale = gr.Checkbox(
|
| 53 |
-
label="Auto Scale",
|
| 54 |
-
info='Recommended for low-volume input audio',
|
| 55 |
-
value=True,
|
| 56 |
-
)
|
| 57 |
-
audio_out = gr.Audio(type="filepath", label="Denoised Audio")
|
| 58 |
-
info=gr.Textbox(label='info')
|
| 59 |
-
|
| 60 |
-
btn.click(
|
| 61 |
-
denoiser,
|
| 62 |
-
inputs=[audio_in, scale],
|
| 63 |
-
outputs=[audio_out,info])
|
| 64 |
-
|
| 65 |
-
examples = gr.Examples(examples=examples, inputs=audio_in, outputs=audio_out, fn=denoiser)
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
app.launch(share=True)
|
|
|
|
| 1 |
+
from audio_denoiser.AudioDenoiser import AudioDenoiser
|
| 2 |
+
from timeit import default_timer as timer
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from torchaudio import AudioMetaData
|
| 6 |
+
import torch
|
| 7 |
+
import tempfile
|
| 8 |
+
import os,pytz
|
| 9 |
+
|
| 10 |
+
tz = pytz.timezone('Asia/Singapore')
|
| 11 |
+
theme='remilia/Ghostly'
|
| 12 |
+
device = torch.device('cuda:0') if torch.cuda.is_available() else torch.device('cpu')
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def denoiser(win, auto_scale):
|
| 16 |
+
if win is None:
|
| 17 |
+
gr.Warning('Audio does not exist. Please ensure that the audio has been successfully uploaded.')
|
| 18 |
+
return None,None
|
| 19 |
+
|
| 20 |
+
startTime=timer()
|
| 21 |
+
denoiser = AudioDenoiser(device=device)
|
| 22 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.wav')
|
| 23 |
+
wout = temp_file.name
|
| 24 |
+
temp_file.close()
|
| 25 |
+
try:
|
| 26 |
+
denoiser.process_audio_file(win, wout, auto_scale)
|
| 27 |
+
except RuntimeError as e:
|
| 28 |
+
gr.Warning(str(e))
|
| 29 |
+
return None,None
|
| 30 |
+
|
| 31 |
+
endTime=timer()
|
| 32 |
+
info=(f'🆗Completion time: {round(endTime-startTime,4)}s')
|
| 33 |
+
now=datetime.now(tz).strftime('%H:%M:%S')
|
| 34 |
+
print(f'{now}-{info}')
|
| 35 |
+
return wout,info
|
| 36 |
+
|
| 37 |
+
examples = [
|
| 38 |
+
["sample/exp1.wav", "sample/exp1_d.wav"],
|
| 39 |
+
["sample/exp2.wav", "sample/exp2_d.wav"]
|
| 40 |
+
]
|
| 41 |
+
with gr.Blocks(theme=theme) as app:
|
| 42 |
+
gr.HTML('''
|
| 43 |
+
<h1 style="font-size: 25px;">Audio Denoiser</h1>
|
| 44 |
+
<p style="margin-bottom: 10px; font-size: 100%">
|
| 45 |
+
|
| 46 |
+
Originating from the project: <a href='https://github.com/jose-solorzano/audio-denoiser'>audio-denoiser</a><br>
|
| 47 |
+
model: <a href='https://huggingface.co/jose-h-solorzano/audio-denoiser-512-32-v1'>jose-h-solorzano/audio-denoiser-512-32-v1</a><br>
|
| 48 |
+
|
| 49 |
+
</p>''')
|
| 50 |
+
audio_in = gr.Audio(type="filepath", label="Upload Audio")
|
| 51 |
+
btn=gr.Button(value='💥Remove Noise',variant="primary")
|
| 52 |
+
scale = gr.Checkbox(
|
| 53 |
+
label="Auto Scale",
|
| 54 |
+
info='Recommended for low-volume input audio',
|
| 55 |
+
value=True,
|
| 56 |
+
)
|
| 57 |
+
audio_out = gr.Audio(type="filepath", label="Denoised Audio")
|
| 58 |
+
info=gr.Textbox(label='info')
|
| 59 |
+
|
| 60 |
+
btn.click(
|
| 61 |
+
denoiser,
|
| 62 |
+
inputs=[audio_in, scale],
|
| 63 |
+
outputs=[audio_out,info])
|
| 64 |
+
|
| 65 |
+
examples = gr.Examples(examples=examples, inputs=audio_in, outputs=audio_out, fn=denoiser)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
|
| 69 |
app.launch(share=True)
|