audiogen / app.py
fffiloni's picture
Update app.py
f412a85 verified
raw
history blame
758 Bytes
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()