File size: 1,589 Bytes
fa90792
 
 
 
 
7ac1a1c
fa90792
 
 
 
 
 
7ac1a1c
fa90792
7ac1a1c
fa90792
 
 
 
 
 
 
 
 
 
 
 
7ac1a1c
fa90792
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from audiosr import super_resolution, build_model
import torch
import gc # free up memory
import spaces

@spaces.GPU(duration=300)
def inference(audio_file, model_name, guidance_scale, ddim_steps, seed):
    audiosr = build_model(model_name=model_name)
    
    if torch.cuda.is_avaible():
        torch.cuda.empty_cache() # empty cuda cache

    gc.collect()

    # set random seed when seed input value is 0
    if seed == 0:
        import random
        seed = random.randint(1, 2**32-1)
    
    waveform = super_resolution(
        audiosr,
        audio_file,
        seed,
        guidance_scale=guidance_scale,
        ddim_steps=ddim_steps
    )

    if torch.cuda.is_avaible():
        torch.cuda.empty_cache()

    gc.collect()
    
    return (48000, waveform)

iface = gr.Interface(
    fn=inference, 
    inputs=[
        gr.Audio(type="filepath", label="Input Audio"),
        gr.Dropdown(["basic", "speech"], value="basic", label="Model"),
        gr.Slider(1, 10, value=3.5, step=0.1, label="Guidance Scale", info="Guidance scale (Large => better quality and relavancy to text; Small => better diversity)"),  
        gr.Slider(1, 100, value=50, step=1, label="DDIM Steps", info="The sampling step for DDIM"),
        gr.Number(value=42, precision=0, label="Seed", info="Changing this value (any integer number) will lead to a different generation result, put 0 for a random one.")
    ],
    outputs=gr.Audio(type="numpy", label="Output Audio"),
    title="AudioSR",
    description="Audio Super Resolution with AudioSR"
)

iface.launch(share=False)