File size: 1,530 Bytes
6f3415e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import torch
from functions import *
from unet import UNet
from custom_scaler import min_max_scaler

model = UNet()
model_state_dict = torch.load(r"model.pth", map_location="cpu")
model.load_state_dict(model_state_dict["model_state_dict"])

scaler = min_max_scaler()
scaler.fit()

with gr.Blocks() as demo:
    with gr.Row():
        gr.Markdown(
    """
    # Speech enhancement demonstration
    
    Hello!
    
    This is a demo for a speech enhancement model trained to reduce background noice to ensure inteligibility of a single speaker.
    
    Feel free to upload your own audio file or try one of our example files to see how it works!
    
    """
        )
    with gr.Row():
        with gr.Column():
            audio_path = gr.Audio(sources=["upload", "microphone"], type="filepath", label="Upload your song here", format="wav")
        with gr.Column():
            enhanced_audio = gr.Audio(sources=None, label="Enhanced audio will be found here", format="wav")
    with gr.Row():
        files = gr.FileExplorer(label="Example files", file_count="single", root_dir=r"examples", interactive=True)
        files.change(fn=return_input, inputs=files, outputs=audio_path)
        files.change(fn=return_input, inputs=None, outputs=enhanced_audio)
    with gr.Row():
        submit_audio = gr.Button(value="Submit audio for enhancement")
        submit_audio.click(fn=lambda x: predict(x, model, scaler), inputs=audio_path, outputs=enhanced_audio, trigger_mode="once")

demo.launch(share=True)