Spaces:
Running
on
A10G
Running
on
A10G
Synced repo using 'sync_with_huggingface' Github Action
Browse files
app.py
CHANGED
@@ -158,7 +158,7 @@ class Pipeline:
|
|
158 |
self,
|
159 |
prompt,
|
160 |
input_audio=None,
|
161 |
-
scale=
|
162 |
continuation=False,
|
163 |
batch_size=1,
|
164 |
duration=15,
|
@@ -174,8 +174,6 @@ class Pipeline:
|
|
174 |
continuation_end=None,
|
175 |
):
|
176 |
print("Prompt:", prompt)
|
177 |
-
if scale == "closest":
|
178 |
-
scale = None
|
179 |
|
180 |
set_generation_params = lambda duration: self.model.set_generation_params(
|
181 |
duration=duration,
|
@@ -198,13 +196,16 @@ class Pipeline:
|
|
198 |
# Save a copy of the original input audio
|
199 |
original_input_audio = input_audio.clone()
|
200 |
print("Input audio shape:", input_audio.shape)
|
201 |
-
if scale
|
202 |
-
|
203 |
-
|
|
|
|
|
|
|
|
|
|
|
204 |
else:
|
205 |
-
print("
|
206 |
-
input_audio = run_autotune(input_audio, sr, correction_method="scale", scale=scale)
|
207 |
-
print(f"...Done running pitch correction. Shape after is {input_audio.shape}.\n")
|
208 |
input_audio = input_audio[None] if input_audio.dim() == 2 else input_audio
|
209 |
|
210 |
continuation_start = 0 if not continuation_start else continuation_start
|
@@ -290,14 +291,22 @@ class Pipeline:
|
|
290 |
return to_return
|
291 |
|
292 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
def main(model_id="nateraw/musicgen-songstarter-v0.2", max_batch_size=4, share=False, debug=False):
|
294 |
pipeline = Pipeline(model_id, max_batch_size)
|
295 |
interface = gr.Interface(
|
296 |
fn=pipeline.__call__,
|
297 |
inputs=[
|
298 |
-
gr.Textbox(label="Prompt", placeholder="Enter your prompt here..."),
|
299 |
gr.Audio(
|
300 |
-
sources=["microphone"],
|
301 |
waveform_options=gr.WaveformOptions(
|
302 |
waveform_color="#01C6FF",
|
303 |
waveform_progress_color="#0066B4",
|
@@ -306,7 +315,7 @@ def main(model_id="nateraw/musicgen-songstarter-v0.2", max_batch_size=4, share=F
|
|
306 |
),
|
307 |
type="filepath",
|
308 |
),
|
309 |
-
gr.Dropdown(["closest", "A:maj", "A:min", "Bb:maj", "Bb:min", "B:maj", "B:min", "C:maj", "C:min", "Db:maj", "Db:min", "D:maj", "D:min", "Eb:maj", "Eb:min", "E:maj", "E:min", "F:maj", "F:min", "Gb:maj", "Gb:min", "G:maj", "G:min", "Ab:maj", "Ab:min"], label="Scale for pitch correction. Set to 'closest' if you don't know.", value="closest"),
|
310 |
gr.Checkbox(label="Is Continuation", value=False),
|
311 |
gr.Slider(label="Batch Size", value=1, minimum=1, maximum=pipeline.max_batch_size, step=1),
|
312 |
gr.Slider(label="Duration", value=15, minimum=4, maximum=30),
|
@@ -321,7 +330,7 @@ def main(model_id="nateraw/musicgen-songstarter-v0.2", max_batch_size=4, share=F
|
|
321 |
],
|
322 |
outputs=[gr.Audio(label=("Input " if i == 0 else "") + f"Audio {i}") for i in range(pipeline.max_batch_size + 1)],
|
323 |
title="🎶 Generate song ideas with musicgen-songstarter-v0.2 🎶",
|
324 |
-
description=
|
325 |
examples=[
|
326 |
["synth, dark, hip hop, melody, trap", "./nate_is_singing_Gb_minor.wav", "Gb:min", False, 1, 7, True, 1.0, 250, 0.0, 3.0, "./samples", "loudness", -1],
|
327 |
["music, mallets, bells, melody, dancehall, african, afropop & afrobeats", "./nate_is_singing_Gb_minor.wav", "Gb:min", False, 1, 7, True, 1.0, 250, 0.0, 4.5, "./samples", "loudness", -1],
|
|
|
158 |
self,
|
159 |
prompt,
|
160 |
input_audio=None,
|
161 |
+
scale="closest",
|
162 |
continuation=False,
|
163 |
batch_size=1,
|
164 |
duration=15,
|
|
|
174 |
continuation_end=None,
|
175 |
):
|
176 |
print("Prompt:", prompt)
|
|
|
|
|
177 |
|
178 |
set_generation_params = lambda duration: self.model.set_generation_params(
|
179 |
duration=duration,
|
|
|
196 |
# Save a copy of the original input audio
|
197 |
original_input_audio = input_audio.clone()
|
198 |
print("Input audio shape:", input_audio.shape)
|
199 |
+
if scale != "none":
|
200 |
+
if scale == "closest":
|
201 |
+
print("Running pitch correction for 'closest' pitch")
|
202 |
+
input_audio = run_autotune(input_audio, sr, correction_method="closest")
|
203 |
+
else:
|
204 |
+
print("Running pitch correction for 'scale' pitch")
|
205 |
+
input_audio = run_autotune(input_audio, sr, correction_method="scale", scale=scale)
|
206 |
+
print(f"...Done running pitch correction. Shape after is {input_audio.shape}.\n")
|
207 |
else:
|
208 |
+
print("Skipping pitch correction, as 'scale' was set to none")
|
|
|
|
|
209 |
input_audio = input_audio[None] if input_audio.dim() == 2 else input_audio
|
210 |
|
211 |
continuation_start = 0 if not continuation_start else continuation_start
|
|
|
291 |
return to_return
|
292 |
|
293 |
|
294 |
+
_description = """\
|
295 |
+
Hum an idea ➡️ get an AI generated music sample. Check out the model [here](https://huggingface.co/nateraw/musicgen-songstarter-v0.2) and the source code [here](https://github.com/nateraw/singing-songstarter).
|
296 |
+
|
297 |
+
The input audio will be pitch corrected unless you set `scale` to `"none"`. Set `scale` to `"closest"` to correct to nearest note (if unsure, use this). \
|
298 |
+
Ideally, you figure out what key you're singing in and set `scale` to that, so it corrects to only notes in that scale. \
|
299 |
+
It is incredibly important the audio passed to the model (which you'll get back as the first output) is clean in order to get good results. 🗑 in = 🗑 out.
|
300 |
+
|
301 |
+
Enjoy ❤️"""
|
302 |
def main(model_id="nateraw/musicgen-songstarter-v0.2", max_batch_size=4, share=False, debug=False):
|
303 |
pipeline = Pipeline(model_id, max_batch_size)
|
304 |
interface = gr.Interface(
|
305 |
fn=pipeline.__call__,
|
306 |
inputs=[
|
307 |
+
gr.Textbox(label="Prompt", placeholder="Enter your prompt here...", value="synth, hip hop, melody, dark"),
|
308 |
gr.Audio(
|
309 |
+
sources=["microphone", "upload"],
|
310 |
waveform_options=gr.WaveformOptions(
|
311 |
waveform_color="#01C6FF",
|
312 |
waveform_progress_color="#0066B4",
|
|
|
315 |
),
|
316 |
type="filepath",
|
317 |
),
|
318 |
+
gr.Dropdown(["closest", "none", "A:maj", "A:min", "Bb:maj", "Bb:min", "B:maj", "B:min", "C:maj", "C:min", "Db:maj", "Db:min", "D:maj", "D:min", "Eb:maj", "Eb:min", "E:maj", "E:min", "F:maj", "F:min", "Gb:maj", "Gb:min", "G:maj", "G:min", "Ab:maj", "Ab:min"], label="Scale for pitch correction. Set to 'closest' if you don't know.", value="closest"),
|
319 |
gr.Checkbox(label="Is Continuation", value=False),
|
320 |
gr.Slider(label="Batch Size", value=1, minimum=1, maximum=pipeline.max_batch_size, step=1),
|
321 |
gr.Slider(label="Duration", value=15, minimum=4, maximum=30),
|
|
|
330 |
],
|
331 |
outputs=[gr.Audio(label=("Input " if i == 0 else "") + f"Audio {i}") for i in range(pipeline.max_batch_size + 1)],
|
332 |
title="🎶 Generate song ideas with musicgen-songstarter-v0.2 🎶",
|
333 |
+
description=_description,
|
334 |
examples=[
|
335 |
["synth, dark, hip hop, melody, trap", "./nate_is_singing_Gb_minor.wav", "Gb:min", False, 1, 7, True, 1.0, 250, 0.0, 3.0, "./samples", "loudness", -1],
|
336 |
["music, mallets, bells, melody, dancehall, african, afropop & afrobeats", "./nate_is_singing_Gb_minor.wav", "Gb:min", False, 1, 7, True, 1.0, 250, 0.0, 4.5, "./samples", "loudness", -1],
|