Spaces:
Running
Running
adapting full app
Browse files- app.py +30 -21
- app_batched.py +1 -2
app.py
CHANGED
@@ -6,10 +6,13 @@ This source code is licensed under the license found in the
|
|
6 |
LICENSE file in the root directory of this source tree.
|
7 |
"""
|
8 |
|
|
|
9 |
import torch
|
10 |
import gradio as gr
|
11 |
from hf_loading import get_pretrained
|
12 |
|
|
|
|
|
13 |
|
14 |
MODEL = None
|
15 |
|
@@ -51,8 +54,11 @@ def predict(model, text, melody, duration, topk, topp, temperature, cfg_coef):
|
|
51 |
else:
|
52 |
output = MODEL.generate(descriptions=[text], progress=False)
|
53 |
|
54 |
-
output = output.detach().cpu().
|
55 |
-
|
|
|
|
|
|
|
56 |
|
57 |
|
58 |
with gr.Blocks() as demo:
|
@@ -60,25 +66,12 @@ with gr.Blocks() as demo:
|
|
60 |
"""
|
61 |
# MusicGen
|
62 |
|
63 |
-
This is the demo for MusicGen, a simple and controllable model for music generation
|
64 |
-
|
65 |
-
Below we present 3 model variations:
|
66 |
-
1. Melody -- a music generation model capable of generating music condition on text and melody inputs. **Note**, you can also use text only.
|
67 |
-
2. Small -- a 300M transformer decoder conditioned on text only.
|
68 |
-
3. Medium -- a 1.5B transformer decoder conditioned on text only.
|
69 |
-
4. Large -- a 3.3B transformer decoder conditioned on text only (might OOM for the longest sequences.)
|
70 |
-
|
71 |
-
When the optional melody conditioning wav is provided, the model will extract
|
72 |
-
a broad melody and try to follow it in the generated samples.
|
73 |
-
|
74 |
-
For skipping queue, you can duplicate this space, and upgrade to GPU in the settings.
|
75 |
<br/>
|
76 |
-
<a href="https://huggingface.co/spaces/musicgen/MusicGen?duplicate=true">
|
77 |
-
<img style="margin-
|
78 |
-
|
79 |
-
|
80 |
-
See [github.com/facebookresearch/audiocraft](https://github.com/facebookresearch/audiocraft)
|
81 |
-
for more details.
|
82 |
"""
|
83 |
)
|
84 |
with gr.Row():
|
@@ -98,7 +91,7 @@ with gr.Blocks() as demo:
|
|
98 |
temperature = gr.Number(label="Temperature", value=1.0, interactive=True)
|
99 |
cfg_coef = gr.Number(label="Classifier Free Guidance", value=3.0, interactive=True)
|
100 |
with gr.Column():
|
101 |
-
output = gr.
|
102 |
submit.click(predict, inputs=[model, text, melody, duration, topk, topp, temperature, cfg_coef], outputs=[output])
|
103 |
gr.Examples(
|
104 |
fn=predict,
|
@@ -132,5 +125,21 @@ with gr.Blocks() as demo:
|
|
132 |
inputs=[text, melody, model],
|
133 |
outputs=[output]
|
134 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
demo.launch()
|
|
|
6 |
LICENSE file in the root directory of this source tree.
|
7 |
"""
|
8 |
|
9 |
+
from tempfile import NamedTemporaryFile
|
10 |
import torch
|
11 |
import gradio as gr
|
12 |
from hf_loading import get_pretrained
|
13 |
|
14 |
+
from audiocraft.data.audio import audio_write
|
15 |
+
|
16 |
|
17 |
MODEL = None
|
18 |
|
|
|
54 |
else:
|
55 |
output = MODEL.generate(descriptions=[text], progress=False)
|
56 |
|
57 |
+
output = output.detach().cpu().float()[0]
|
58 |
+
with NamedTemporaryFile("wb", suffix=".wav", delete=False) as file:
|
59 |
+
audio_write(file.name, output, MODEL.sample_rate, strategy="loudness", add_suffix=False)
|
60 |
+
waveform_video = gr.make_waveform(file.name)
|
61 |
+
return waveform_video
|
62 |
|
63 |
|
64 |
with gr.Blocks() as demo:
|
|
|
66 |
"""
|
67 |
# MusicGen
|
68 |
|
69 |
+
This is the demo for [MusicGen](https://github.com/facebookresearch/audiocraft), a simple and controllable model for music generation
|
70 |
+
presented at: ["Simple and Controllable Music Generation"](https://huggingface.co/papers/2306.05284).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
<br/>
|
72 |
+
<a href="https://huggingface.co/spaces/musicgen/MusicGen?duplicate=true" style="display: inline-block;margin-top: .5em;margin-right: .25em;" target="_blank">
|
73 |
+
<img style="margin-bottom: 0em;display: inline;margin-top: -.25em;" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
|
74 |
+
for longer sequences, more control and no queue.</p>
|
|
|
|
|
|
|
75 |
"""
|
76 |
)
|
77 |
with gr.Row():
|
|
|
91 |
temperature = gr.Number(label="Temperature", value=1.0, interactive=True)
|
92 |
cfg_coef = gr.Number(label="Classifier Free Guidance", value=3.0, interactive=True)
|
93 |
with gr.Column():
|
94 |
+
output = gr.Video(label="Generated Music")
|
95 |
submit.click(predict, inputs=[model, text, melody, duration, topk, topp, temperature, cfg_coef], outputs=[output])
|
96 |
gr.Examples(
|
97 |
fn=predict,
|
|
|
125 |
inputs=[text, melody, model],
|
126 |
outputs=[output]
|
127 |
)
|
128 |
+
gr.Markdown(
|
129 |
+
"""
|
130 |
+
### More details
|
131 |
+
|
132 |
+
By typing a description of the music you want and an optional audio used for melody conditioning,
|
133 |
+
|
134 |
+
We present 4 model variations:
|
135 |
+
1. Melody -- a music generation model capable of generating music condition on text and melody inputs. **Note**, you can also use text only.
|
136 |
+
2. Small -- a 300M transformer decoder conditioned on text only.
|
137 |
+
3. Medium -- a 1.5B transformer decoder conditioned on text only.
|
138 |
+
4. Large -- a 3.3B transformer decoder conditioned on text only (might OOM for the longest sequences.)
|
139 |
+
|
140 |
+
When the optional melody conditioning wav is provided, the model will extract
|
141 |
+
a broad melody and try to follow it in the generated samples.
|
142 |
+
"""
|
143 |
+
)
|
144 |
|
145 |
demo.launch()
|
app_batched.py
CHANGED
@@ -60,7 +60,6 @@ def predict(texts, melodies):
|
|
60 |
audio_write(file.name, output, MODEL.sample_rate, strategy="loudness", add_suffix=False)
|
61 |
waveform_video = gr.make_waveform(file.name)
|
62 |
out_files.append(waveform_video)
|
63 |
-
print(out_files)
|
64 |
return [out_files]
|
65 |
|
66 |
|
@@ -72,7 +71,7 @@ with gr.Blocks() as demo:
|
|
72 |
This is the demo for [MusicGen](https://github.com/facebookresearch/audiocraft), a simple and controllable model for music generation
|
73 |
presented at: ["Simple and Controllable Music Generation"](https://huggingface.co/papers/2306.05284).
|
74 |
<br/>
|
75 |
-
<a href="https://huggingface.co/spaces/
|
76 |
<img style="margin-bottom: 0em;display: inline;margin-top: -.25em;" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
|
77 |
for longer sequences, more control and no queue</p>
|
78 |
"""
|
|
|
60 |
audio_write(file.name, output, MODEL.sample_rate, strategy="loudness", add_suffix=False)
|
61 |
waveform_video = gr.make_waveform(file.name)
|
62 |
out_files.append(waveform_video)
|
|
|
63 |
return [out_files]
|
64 |
|
65 |
|
|
|
71 |
This is the demo for [MusicGen](https://github.com/facebookresearch/audiocraft), a simple and controllable model for music generation
|
72 |
presented at: ["Simple and Controllable Music Generation"](https://huggingface.co/papers/2306.05284).
|
73 |
<br/>
|
74 |
+
<a href="https://huggingface.co/spaces/musicgen/MusicGen?duplicate=true" style="display: inline-block;margin-top: .5em;margin-right: .25em;" target="_blank">
|
75 |
<img style="margin-bottom: 0em;display: inline;margin-top: -.25em;" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
|
76 |
for longer sequences, more control and no queue</p>
|
77 |
"""
|