File size: 758 Bytes
36f9d2b
f412a85
36f9d2b
 
 
 
 
 
f412a85
36f9d2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import spaces
import torchaudio
from audiocraft.models import AudioGen
from audiocraft.data.audio import audio_write

model = AudioGen.get_pretrained('facebook/audiogen-medium')

@spaces.GPU(enable_queue=True)
def infer(prompt):
    
    model.set_generation_params(duration=5)  # generate 5 seconds.
    descriptions = [prompt]
    wav = model.generate(descriptions)  # generates 3 samples.

    for idx, one_wav in enumerate(wav):
        # Will save under {idx}.wav, with loudness normalization at -14 db LUFS.
        audio_write(f'{idx}', one_wav.cpu(), model.sample_rate, strategy="loudness", loudness_compressor=True)

    return "0.wav"

gr.Interface(
    fn = infer,
    inputs = gr.Textbox(),
    outputs = gr.Audio()
).launch()