Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -24,21 +24,21 @@ def load_model(version):
|
|
24 |
return MusicGen.get_pretrained(version)
|
25 |
|
26 |
|
27 |
-
def predict(
|
28 |
text = img_to_text(uploaded_image, 'best', 4, fn_index=1)[0]
|
29 |
global MODEL
|
30 |
topk = int(topk)
|
31 |
-
if MODEL is None or MODEL.name !=
|
32 |
-
MODEL = load_model(
|
33 |
|
34 |
if duration > MODEL.lm.cfg.dataset.segment_duration:
|
35 |
raise gr.Error("MusicGen currently supports durations of up to 30 seconds!")
|
36 |
MODEL.set_generation_params(
|
37 |
use_sampling=True,
|
38 |
-
top_k=
|
39 |
-
top_p=
|
40 |
-
temperature=
|
41 |
-
cfg_coef=
|
42 |
duration=duration,
|
43 |
)
|
44 |
|
@@ -84,18 +84,18 @@ with gr.Blocks() as demo:
|
|
84 |
melody = gr.Audio(source="upload", type="numpy", label="Melody Condition (optional)", interactive=True)
|
85 |
with gr.Row():
|
86 |
submit = gr.Button("Submit")
|
87 |
-
with gr.Row():
|
88 |
-
|
89 |
with gr.Row():
|
90 |
duration = gr.Slider(minimum=1, maximum=30, value=10, label="Duration", interactive=True)
|
91 |
-
with gr.Row():
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
with gr.Column():
|
97 |
output = gr.Audio(label="Generated Music")
|
98 |
-
submit.click(predict, inputs=[
|
99 |
|
100 |
gr.Markdown(
|
101 |
"""
|
@@ -104,7 +104,7 @@ with gr.Blocks() as demo:
|
|
104 |
The model will generate a short music extract based on the image you provided.
|
105 |
You can generate up to 30 seconds of audio.
|
106 |
|
107 |
-
|
108 |
1. Melody -- a music generation model capable of generating music condition on text and melody inputs. **Note**, you can also use text only.
|
109 |
2. Small -- a 300M transformer decoder conditioned on text only.
|
110 |
3. Medium -- a 1.5B transformer decoder conditioned on text only.
|
|
|
24 |
return MusicGen.get_pretrained(version)
|
25 |
|
26 |
|
27 |
+
def predict(uploaded_image, melody, duration):
|
28 |
text = img_to_text(uploaded_image, 'best', 4, fn_index=1)[0]
|
29 |
global MODEL
|
30 |
topk = int(topk)
|
31 |
+
if MODEL is None or MODEL.name != "melody":
|
32 |
+
MODEL = load_model("melody")
|
33 |
|
34 |
if duration > MODEL.lm.cfg.dataset.segment_duration:
|
35 |
raise gr.Error("MusicGen currently supports durations of up to 30 seconds!")
|
36 |
MODEL.set_generation_params(
|
37 |
use_sampling=True,
|
38 |
+
top_k=250,
|
39 |
+
top_p=0,
|
40 |
+
temperature=1.0,
|
41 |
+
cfg_coef=3.0,
|
42 |
duration=duration,
|
43 |
)
|
44 |
|
|
|
84 |
melody = gr.Audio(source="upload", type="numpy", label="Melody Condition (optional)", interactive=True)
|
85 |
with gr.Row():
|
86 |
submit = gr.Button("Submit")
|
87 |
+
#with gr.Row():
|
88 |
+
# model = gr.Radio(["melody", "medium", "small", "large"], label="Model", value="melody", interactive=True)
|
89 |
with gr.Row():
|
90 |
duration = gr.Slider(minimum=1, maximum=30, value=10, label="Duration", interactive=True)
|
91 |
+
#with gr.Row():
|
92 |
+
# topk = gr.Number(label="Top-k", value=250, interactive=True)
|
93 |
+
# topp = gr.Number(label="Top-p", value=0, interactive=True)
|
94 |
+
# temperature = gr.Number(label="Temperature", value=1.0, interactive=True)
|
95 |
+
# cfg_coef = gr.Number(label="Classifier Free Guidance", value=3.0, interactive=True)
|
96 |
with gr.Column():
|
97 |
output = gr.Audio(label="Generated Music")
|
98 |
+
submit.click(predict, inputs=[uploaded_image, melody, duration, topk, topp, temperature, cfg_coef], outputs=[output])
|
99 |
|
100 |
gr.Markdown(
|
101 |
"""
|
|
|
104 |
The model will generate a short music extract based on the image you provided.
|
105 |
You can generate up to 30 seconds of audio.
|
106 |
|
107 |
+
This demo is set to use only the Melody model
|
108 |
1. Melody -- a music generation model capable of generating music condition on text and melody inputs. **Note**, you can also use text only.
|
109 |
2. Small -- a 300M transformer decoder conditioned on text only.
|
110 |
3. Medium -- a 1.5B transformer decoder conditioned on text only.
|