Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import huggingface_hub
|
| 3 |
import numpy as np
|
| 4 |
import pandas as pd
|
|
@@ -64,6 +65,7 @@ def check_for_wav_in_outputs():
|
|
| 64 |
else:
|
| 65 |
return None
|
| 66 |
|
|
|
|
| 67 |
def infer(prompt_in, chords, duration, bpms):
|
| 68 |
|
| 69 |
# check if 'outputs' dir exists and empty it if necessary
|
|
@@ -91,11 +93,12 @@ def infer(prompt_in, chords, duration, bpms):
|
|
| 91 |
wav = []
|
| 92 |
for i in range(num_samples//bs):
|
| 93 |
print(f"starting {i} batch...")
|
| 94 |
-
temp = musicgen.generate_with_chords_and_beats(
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
| 99 |
wav.extend(temp.cpu())
|
| 100 |
|
| 101 |
# save and display generated audio
|
|
@@ -114,6 +117,9 @@ css="""
|
|
| 114 |
max-width: 800px;
|
| 115 |
margin: 0 auto;
|
| 116 |
}
|
|
|
|
|
|
|
|
|
|
| 117 |
"""
|
| 118 |
|
| 119 |
with gr.Blocks(css=css) as demo:
|
|
@@ -123,7 +129,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 123 |
with gr.Column():
|
| 124 |
prompt_in = gr.Textbox(label="Music description", value="A laid-back blues shuffle with a relaxed tempo, warm guitar tones, and a comfortable groove, perfect for a slow dance or a night in. Instruments: electric guitar, bass, drums.")
|
| 125 |
chords = gr.Textbox(label="Chords progression", value='C G A:min F')
|
| 126 |
-
duration = gr.Slider(label="Sample duration", minimum=4, maximum=30, step=1, value=
|
| 127 |
bpms = gr.Slider(label="BPMs", minimum=50, maximum=220, step=1, value=120)
|
| 128 |
submit_btn = gr.Button("Submit")
|
| 129 |
wav_out = gr.Audio(label="Wav Result")
|
|
@@ -141,6 +147,7 @@ with gr.Blocks(css=css) as demo:
|
|
| 141 |
)
|
| 142 |
gr.Examples(
|
| 143 |
label = "Chords progression examples",
|
|
|
|
| 144 |
examples = ['C G A:min F',
|
| 145 |
'A:min F C G',
|
| 146 |
'C F G F',
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import spaces
|
| 3 |
import huggingface_hub
|
| 4 |
import numpy as np
|
| 5 |
import pandas as pd
|
|
|
|
| 65 |
else:
|
| 66 |
return None
|
| 67 |
|
| 68 |
+
@spaces.GPU()
|
| 69 |
def infer(prompt_in, chords, duration, bpms):
|
| 70 |
|
| 71 |
# check if 'outputs' dir exists and empty it if necessary
|
|
|
|
| 93 |
wav = []
|
| 94 |
for i in range(num_samples//bs):
|
| 95 |
print(f"starting {i} batch...")
|
| 96 |
+
temp = musicgen.generate_with_chords_and_beats(
|
| 97 |
+
descriptions[i*bs:(i+1)*bs],
|
| 98 |
+
chords[i*bs:(i+1)*bs],
|
| 99 |
+
bpms[i*bs:(i+1)*bs],
|
| 100 |
+
meters[i*bs:(i+1)*bs]
|
| 101 |
+
)
|
| 102 |
wav.extend(temp.cpu())
|
| 103 |
|
| 104 |
# save and display generated audio
|
|
|
|
| 117 |
max-width: 800px;
|
| 118 |
margin: 0 auto;
|
| 119 |
}
|
| 120 |
+
#chords-examples button{
|
| 121 |
+
font-size: 20px;
|
| 122 |
+
}
|
| 123 |
"""
|
| 124 |
|
| 125 |
with gr.Blocks(css=css) as demo:
|
|
|
|
| 129 |
with gr.Column():
|
| 130 |
prompt_in = gr.Textbox(label="Music description", value="A laid-back blues shuffle with a relaxed tempo, warm guitar tones, and a comfortable groove, perfect for a slow dance or a night in. Instruments: electric guitar, bass, drums.")
|
| 131 |
chords = gr.Textbox(label="Chords progression", value='C G A:min F')
|
| 132 |
+
duration = gr.Slider(label="Sample duration", minimum=4, maximum=30, step=1, value=30)
|
| 133 |
bpms = gr.Slider(label="BPMs", minimum=50, maximum=220, step=1, value=120)
|
| 134 |
submit_btn = gr.Button("Submit")
|
| 135 |
wav_out = gr.Audio(label="Wav Result")
|
|
|
|
| 147 |
)
|
| 148 |
gr.Examples(
|
| 149 |
label = "Chords progression examples",
|
| 150 |
+
elem_id = "chords-examples",
|
| 151 |
examples = ['C G A:min F',
|
| 152 |
'A:min F C G',
|
| 153 |
'C F G F',
|