fffiloni commited on
Commit
36f9d2b
·
verified ·
1 Parent(s): 6a185ac

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torchaudio
3
+ from audiocraft.models import AudioGen
4
+ from audiocraft.data.audio import audio_write
5
+
6
+ model = AudioGen.get_pretrained('facebook/audiogen-medium')
7
+
8
+ def infer(prompt):
9
+
10
+ model.set_generation_params(duration=5) # generate 5 seconds.
11
+ descriptions = [prompt]
12
+ wav = model.generate(descriptions) # generates 3 samples.
13
+
14
+ for idx, one_wav in enumerate(wav):
15
+ # Will save under {idx}.wav, with loudness normalization at -14 db LUFS.
16
+ audio_write(f'{idx}', one_wav.cpu(), model.sample_rate, strategy="loudness", loudness_compressor=True)
17
+
18
+ return "0.wav"
19
+
20
+ gr.Interface(
21
+ fn = infer,
22
+ inputs = gr.Textbox(),
23
+ outputs = gr.Audio()
24
+ ).launch()