Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -2,23 +2,30 @@ import gradio as gr
|
|
2 |
import torchaudio
|
3 |
from audiocraft.models import AudioGen
|
4 |
from audiocraft.data.audio import audio_write
|
|
|
5 |
model = AudioGen.get_pretrained('facebook/audiogen-medium')
|
6 |
-
|
|
|
|
|
7 |
model.set_generation_params(duration=duration) # generate 5 seconds.
|
8 |
descriptions = [prompt]
|
9 |
wav = model.generate(descriptions) # generates n samples (referring to the number n of prompts in descriptions)
|
10 |
-
|
11 |
-
|
|
|
12 |
audio_write(f'{idx}', one_wav.cpu(), model.sample_rate, strategy="loudness", loudness_compressor=True)
|
|
|
13 |
return "0.wav"
|
|
|
14 |
css="""
|
15 |
#col-container{
|
16 |
margin: 0 auto;
|
17 |
max-width: 640px;
|
18 |
}
|
19 |
"""
|
20 |
-
|
21 |
-
with gr.
|
|
|
22 |
gr.HTML("""
|
23 |
<h2 style="text-align: center;">
|
24 |
AudioGen: Textually-guided audio generation
|
@@ -26,14 +33,17 @@ with gr.Column(elem_id="col-container"):
|
|
26 |
<p style="text-align: center;">
|
27 |
</p>
|
28 |
""")
|
29 |
-
|
30 |
-
|
|
|
31 |
duration = gr.Slider(label="Duration", minimum=5, maximum=120, step=5, value=5)
|
32 |
submit_btn = gr.Button("Submit")
|
33 |
audio_o = gr.Audio(label="AudioGen result")
|
|
|
34 |
submit_btn.click(
|
35 |
fn=infer,
|
36 |
inputs=[prompt_in, duration],
|
37 |
outputs=[audio_o]
|
38 |
)
|
|
|
39 |
demo.queue().launch(debug=True)
|
|
|
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, duration):
|
9 |
+
|
10 |
model.set_generation_params(duration=duration) # generate 5 seconds.
|
11 |
descriptions = [prompt]
|
12 |
wav = model.generate(descriptions) # generates n samples (referring to the number n of prompts in descriptions)
|
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 |
css="""
|
21 |
#col-container{
|
22 |
margin: 0 auto;
|
23 |
max-width: 640px;
|
24 |
}
|
25 |
"""
|
26 |
+
|
27 |
+
with gr.Blocks(css=css) as demo:
|
28 |
+
with gr.Column(elem_id="col-container"):
|
29 |
gr.HTML("""
|
30 |
<h2 style="text-align: center;">
|
31 |
AudioGen: Textually-guided audio generation
|
|
|
33 |
<p style="text-align: center;">
|
34 |
</p>
|
35 |
""")
|
36 |
+
|
37 |
+
prompt_in = gr.Textbox(label="audio prompt")
|
38 |
+
with gr.Row():
|
39 |
duration = gr.Slider(label="Duration", minimum=5, maximum=120, step=5, value=5)
|
40 |
submit_btn = gr.Button("Submit")
|
41 |
audio_o = gr.Audio(label="AudioGen result")
|
42 |
+
|
43 |
submit_btn.click(
|
44 |
fn=infer,
|
45 |
inputs=[prompt_in, duration],
|
46 |
outputs=[audio_o]
|
47 |
)
|
48 |
+
|
49 |
demo.queue().launch(debug=True)
|