Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torchaudio
|
| 3 |
+
from audiocraft.models import MAGNeT
|
| 4 |
+
from audiocraft. data. audio import audio_write
|
| 5 |
+
|
| 6 |
+
model = MAGNeT.get_pretrained('facebook/magnet-small-10secs')
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def infer(description):
|
| 10 |
+
descriptions = ['disco beat', 'energetic EDM']
|
| 11 |
+
|
| 12 |
+
wav = model.generate(descriptions)
|
| 13 |
+
|
| 14 |
+
for idx, one_wav in enumerate(wav):
|
| 15 |
+
print(idx)
|
| 16 |
+
audio_write(f'{idx}',
|
| 17 |
+
one_wav.cpu(),
|
| 18 |
+
model.sample_rate,
|
| 19 |
+
strategy="loudness",
|
| 20 |
+
loudness_compressor=True)
|
| 21 |
+
|
| 22 |
+
return "done"
|
| 23 |
+
|
| 24 |
+
gr.Interface(
|
| 25 |
+
fn = infer,
|
| 26 |
+
inputs = gr.Textbox(value="gogo"),
|
| 27 |
+
outputs = gr.Textbox()
|
| 28 |
+
).launch()
|