Update barks.py
Browse filesadded guides for api reqs to render voice
barks.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import os
|
2 |
import torch
|
3 |
import torchaudio
|
@@ -95,7 +96,7 @@ def set_red_hot_chili_peppers_prompt(bpm, drum_beat, synthesizer, rhythmic_steps
|
|
95 |
synth = f", {synthesizer} accents" if synthesizer != "none" else ""
|
96 |
bass = f", {bass_style}" if bass_style != "none" else ", groovy basslines"
|
97 |
guitar = f", {guitar_style} guitar riffs" if guitar_style != "none" else ", syncopated guitar riffs"
|
98 |
-
return f"Instrumental funk rock{bass}{guitar}{drum}{synth}, Red Hot Chili Peppers-inspired vibe with dynamic energy and funky breakdowns, {
|
99 |
|
100 |
def set_nirvana_grunge_prompt(bpm, drum_beat, synthesizer, rhythmic_steps, bass_style, guitar_style):
|
101 |
rhythm = f" with {rhythmic_steps}" if rhythmic_steps != "none" else ("intense rhythmic steps" if bpm > 120 else "grungy rhythmic pulse")
|
@@ -207,7 +208,47 @@ def set_deep_house_prompt(bpm, drum_beat, synthesizer, rhythmic_steps, bass_styl
|
|
207 |
guitar = f", {guitar_style} guitars" if guitar_style != "none" else ""
|
208 |
return f"Instrumental deep house{bass}{guitar}{drum}{synth}, Larry Heard-inspired laid-back groove, {rhythm} at {bpm} BPM."
|
209 |
|
210 |
-
# 5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
def apply_eq(segment):
|
212 |
segment = segment.low_pass_filter(8000)
|
213 |
segment = segment.high_pass_filter(80)
|
@@ -256,7 +297,7 @@ def generate_vocals(vocal_prompt: str, total_duration: int):
|
|
256 |
except Exception as e:
|
257 |
return None, f"❌ Vocal generation failed: {e}"
|
258 |
|
259 |
-
#
|
260 |
def generate_music(instrumental_prompt: str, vocal_prompt: str, cfg_scale: float, top_k: int, top_p: float, temperature: float, total_duration: int, chunk_duration: int, crossfade_duration: int, bpm: int, drum_beat: str, synthesizer: str, rhythmic_steps: str, bass_style: str, guitar_style: str):
|
261 |
global musicgen_model
|
262 |
if not instrumental_prompt.strip():
|
@@ -373,7 +414,7 @@ def generate_music(instrumental_prompt: str, vocal_prompt: str, cfg_scale: float
|
|
373 |
def clear_inputs():
|
374 |
return "", "", 3.0, 250, 0.9, 1.0, 30, 10, 1000, 120, "none", "none", "none", "none", "none"
|
375 |
|
376 |
-
#
|
377 |
css = """
|
378 |
body {
|
379 |
background: linear-gradient(135deg, #0A0A0A 0%, #1C2526 100%);
|
@@ -411,13 +452,13 @@ p {
|
|
411 |
border: 1px solid #A100FF;
|
412 |
color: #E0E0E0;
|
413 |
}
|
414 |
-
.genre-buttons {
|
415 |
display: flex;
|
416 |
justify-content: center;
|
417 |
flex-wrap: wrap;
|
418 |
gap: 15px;
|
419 |
}
|
420 |
-
.genre-btn, button {
|
421 |
background: linear-gradient(45deg, #A100FF, #00FF9F);
|
422 |
border: none;
|
423 |
color: #0A0A0A;
|
@@ -449,7 +490,7 @@ p {
|
|
449 |
}
|
450 |
"""
|
451 |
|
452 |
-
#
|
453 |
with gr.Blocks(css=css) as demo:
|
454 |
gr.Markdown("""
|
455 |
<div class="header-container">
|
@@ -467,12 +508,6 @@ with gr.Blocks(css=css) as demo:
|
|
467 |
lines=4,
|
468 |
elem_classes="textbox"
|
469 |
)
|
470 |
-
vocal_prompt = gr.Textbox(
|
471 |
-
label="Vocal Prompt 🎤",
|
472 |
-
placeholder="Enter song lyrics or vocal description (e.g., 'Upbeat pop, male voice, singing about freedom')",
|
473 |
-
lines=4,
|
474 |
-
elem_classes="textbox"
|
475 |
-
)
|
476 |
with gr.Row(elem_classes="genre-buttons"):
|
477 |
rhcp_btn = gr.Button("Red Hot Chili Peppers 🌶️", elem_classes="genre-btn")
|
478 |
nirvana_btn = gr.Button("Nirvana Grunge 🎸", elem_classes="genre-btn")
|
@@ -485,9 +520,20 @@ with gr.Blocks(css=css) as demo:
|
|
485 |
alternative_rock_btn = gr.Button("Alternative Rock 🎵", elem_classes="genre-btn")
|
486 |
post_punk_btn = gr.Button("Post-Punk 🖤", elem_classes="genre-btn")
|
487 |
indie_rock_btn = gr.Button("Indie Rock 🎤", elem_classes="genre-btn")
|
488 |
-
|
489 |
detroit_techno_btn = gr.Button("Detroit Techno 🎛️", elem_classes="genre-btn")
|
490 |
deep_house_btn = gr.Button("Deep House 🏠", elem_classes="genre-btn")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
491 |
|
492 |
with gr.Column(elem_classes="settings-container"):
|
493 |
gr.Markdown("### ⚙️ API Settings")
|
@@ -608,9 +654,12 @@ with gr.Blocks(css=css) as demo:
|
|
608 |
alternative_rock_btn.click(set_alternative_rock_prompt, inputs=[bpm, drum_beat, synthesizer, rhythmic_steps, bass_style, guitar_style], outputs=instrumental_prompt)
|
609 |
post_punk_btn.click(set_post_punk_prompt, inputs=[bpm, drum_beat, synthesizer, rhythmic_steps, bass_style, guitar_style], outputs=instrumental_prompt)
|
610 |
indie_rock_btn.click(set_indie_rock_prompt, inputs=[bpm, drum_beat, synthesizer, rhythmic_steps, bass_style, guitar_style], outputs=instrumental_prompt)
|
611 |
-
|
612 |
detroit_techno_btn.click(set_detroit_techno_prompt, inputs=[bpm, drum_beat, synthesizer, rhythmic_steps, bass_style, guitar_style], outputs=instrumental_prompt)
|
613 |
deep_house_btn.click(set_deep_house_prompt, inputs=[bpm, drum_beat, synthesizer, rhythmic_steps, bass_style, guitar_style], outputs=instrumental_prompt)
|
|
|
|
|
|
|
614 |
gen_btn.click(
|
615 |
generate_music,
|
616 |
inputs=[instrumental_prompt, vocal_prompt, cfg_scale, top_k, top_p, temperature, total_duration, chunk_duration, crossfade_duration, bpm, drum_beat, synthesizer, rhythmic_steps, bass_style, guitar_style],
|
@@ -622,7 +671,7 @@ with gr.Blocks(css=css) as demo:
|
|
622 |
outputs=[instrumental_prompt, vocal_prompt, cfg_scale, top_k, top_p, temperature, total_duration, chunk_duration, crossfade_duration, bpm, drum_beat, synthesizer, rhythmic_steps, bass_style, guitar_style]
|
623 |
)
|
624 |
|
625 |
-
#
|
626 |
app = demo.launch(
|
627 |
server_name="0.0.0.0",
|
628 |
server_port=9999,
|
@@ -636,4 +685,4 @@ try:
|
|
636 |
fastapi_app.redoc_url = None
|
637 |
fastapi_app.openapi_url = None
|
638 |
except Exception:
|
639 |
-
pass
|
|
|
1 |
+
|
2 |
import os
|
3 |
import torch
|
4 |
import torchaudio
|
|
|
96 |
synth = f", {synthesizer} accents" if synthesizer != "none" else ""
|
97 |
bass = f", {bass_style}" if bass_style != "none" else ", groovy basslines"
|
98 |
guitar = f", {guitar_style} guitar riffs" if guitar_style != "none" else ", syncopated guitar riffs"
|
99 |
+
return f"Instrumental funk rock{bass}{guitar}{drum}{synth}, Red Hot Chili Peppers-inspired vibe with dynamic energy and funky breakdowns, {rhythm} at {bpm} BPM."
|
100 |
|
101 |
def set_nirvana_grunge_prompt(bpm, drum_beat, synthesizer, rhythmic_steps, bass_style, guitar_style):
|
102 |
rhythm = f" with {rhythmic_steps}" if rhythmic_steps != "none" else ("intense rhythmic steps" if bpm > 120 else "grungy rhythmic pulse")
|
|
|
208 |
guitar = f", {guitar_style} guitars" if guitar_style != "none" else ""
|
209 |
return f"Instrumental deep house{bass}{guitar}{drum}{synth}, Larry Heard-inspired laid-back groove, {rhythm} at {bpm} BPM."
|
210 |
|
211 |
+
# 5) VOCAL PROMPT FUNCTIONS
|
212 |
+
def set_upbeat_funk_rock_vocal_prompt():
|
213 |
+
return """[Verse 1, upbeat funk rock, male voice]
|
214 |
+
Cruisin' down the highway, feel the summer breeze,
|
215 |
+
Funky rhythm in my bones, movin' with ease,
|
216 |
+
City lights are callin', gonna dance all night,
|
217 |
+
Livin' for the groove, everything feels right!
|
218 |
+
|
219 |
+
[Chorus, energetic]
|
220 |
+
Oh-oh-oh, let the funk take control,
|
221 |
+
Shake your body, let it free your soul,
|
222 |
+
Oh-oh-oh, we're burnin' up the stage,
|
223 |
+
Funk it up, we're livin' for the rage!"""
|
224 |
+
|
225 |
+
def set_grunge_ballad_vocal_prompt():
|
226 |
+
return """[Verse 1, grunge ballad, male voice, soft]
|
227 |
+
Shadows fall across my heart, I'm lost in the rain,
|
228 |
+
Whispers of a broken dream, carry all my pain,
|
229 |
+
Underneath the weight of time, I’m fading away,
|
230 |
+
Searching for a spark to light another day.
|
231 |
+
|
232 |
+
[Chorus, intense]
|
233 |
+
Scream it out, let the silence break,
|
234 |
+
Feel the fire, for my soul’s sake,
|
235 |
+
Hold me now, through the endless night,
|
236 |
+
In the dark, I’m reaching for the light!"""
|
237 |
+
|
238 |
+
def set_indie_pop_vocal_prompt():
|
239 |
+
return """[Verse 1, indie pop, female voice]
|
240 |
+
Walking through the neon streets, where the city sings,
|
241 |
+
Chasing every fleeting star, on these fragile wings,
|
242 |
+
Heartbeat like a drum machine, pulsing through the air,
|
243 |
+
Every moment’s electric, love is everywhere.
|
244 |
+
|
245 |
+
[Chorus, upbeat]
|
246 |
+
Oh, we’re dancing in the glow, under moonlit skies,
|
247 |
+
Spinning through the colors, with sparks in our eyes,
|
248 |
+
Oh, the night is ours to keep, let the music play,
|
249 |
+
Living for this feeling, we’ll never fade away!"""
|
250 |
+
|
251 |
+
# 6) AUDIO PROCESSING FUNCTIONS
|
252 |
def apply_eq(segment):
|
253 |
segment = segment.low_pass_filter(8000)
|
254 |
segment = segment.high_pass_filter(80)
|
|
|
297 |
except Exception as e:
|
298 |
return None, f"❌ Vocal generation failed: {e}"
|
299 |
|
300 |
+
# 7) GENERATION & I/O FUNCTIONS
|
301 |
def generate_music(instrumental_prompt: str, vocal_prompt: str, cfg_scale: float, top_k: int, top_p: float, temperature: float, total_duration: int, chunk_duration: int, crossfade_duration: int, bpm: int, drum_beat: str, synthesizer: str, rhythmic_steps: str, bass_style: str, guitar_style: str):
|
302 |
global musicgen_model
|
303 |
if not instrumental_prompt.strip():
|
|
|
414 |
def clear_inputs():
|
415 |
return "", "", 3.0, 250, 0.9, 1.0, 30, 10, 1000, 120, "none", "none", "none", "none", "none"
|
416 |
|
417 |
+
# 8) CUSTOM CSS
|
418 |
css = """
|
419 |
body {
|
420 |
background: linear-gradient(135deg, #0A0A0A 0%, #1C2526 100%);
|
|
|
452 |
border: 1px solid #A100FF;
|
453 |
color: #E0E0E0;
|
454 |
}
|
455 |
+
.genre-buttons, .vocal-buttons {
|
456 |
display: flex;
|
457 |
justify-content: center;
|
458 |
flex-wrap: wrap;
|
459 |
gap: 15px;
|
460 |
}
|
461 |
+
.genre-btn, .vocal-btn, button {
|
462 |
background: linear-gradient(45deg, #A100FF, #00FF9F);
|
463 |
border: none;
|
464 |
color: #0A0A0A;
|
|
|
490 |
}
|
491 |
"""
|
492 |
|
493 |
+
# 9) BUILD WITH BLOCKS
|
494 |
with gr.Blocks(css=css) as demo:
|
495 |
gr.Markdown("""
|
496 |
<div class="header-container">
|
|
|
508 |
lines=4,
|
509 |
elem_classes="textbox"
|
510 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
511 |
with gr.Row(elem_classes="genre-buttons"):
|
512 |
rhcp_btn = gr.Button("Red Hot Chili Peppers 🌶️", elem_classes="genre-btn")
|
513 |
nirvana_btn = gr.Button("Nirvana Grunge 🎸", elem_classes="genre-btn")
|
|
|
520 |
alternative_rock_btn = gr.Button("Alternative Rock 🎵", elem_classes="genre-btn")
|
521 |
post_punk_btn = gr.Button("Post-Punk 🖤", elem_classes="genre-btn")
|
522 |
indie_rock_btn = gr.Button("Indie Rock 🎤", elem_classes="genre-btn")
|
523 |
+
funk_rock_btn = gr.Button("Funk Rock 🕺", elem_classes="genre-btn")
|
524 |
detroit_techno_btn = gr.Button("Detroit Techno 🎛️", elem_classes="genre-btn")
|
525 |
deep_house_btn = gr.Button("Deep House 🏠", elem_classes="genre-btn")
|
526 |
+
|
527 |
+
vocal_prompt = gr.Textbox(
|
528 |
+
label="Vocal Prompt 🎤",
|
529 |
+
placeholder="Click a vocal button or type your own vocal prompt (e.g., '[Verse, upbeat pop, male voice] Lyrics...')",
|
530 |
+
lines=4,
|
531 |
+
elem_classes="textbox"
|
532 |
+
)
|
533 |
+
with gr.Row(elem_classes="vocal-buttons"):
|
534 |
+
funk_vocal_btn = gr.Button("Upbeat Funk Rock 🎵", elem_classes="vocal-btn")
|
535 |
+
grunge_vocal_btn = gr.Button("Grunge Ballad 🎸", elem_classes="vocal-btn")
|
536 |
+
indie_vocal_btn = gr.Button("Indie Pop 🎤", elem_classes="vocal-btn")
|
537 |
|
538 |
with gr.Column(elem_classes="settings-container"):
|
539 |
gr.Markdown("### ⚙️ API Settings")
|
|
|
654 |
alternative_rock_btn.click(set_alternative_rock_prompt, inputs=[bpm, drum_beat, synthesizer, rhythmic_steps, bass_style, guitar_style], outputs=instrumental_prompt)
|
655 |
post_punk_btn.click(set_post_punk_prompt, inputs=[bpm, drum_beat, synthesizer, rhythmic_steps, bass_style, guitar_style], outputs=instrumental_prompt)
|
656 |
indie_rock_btn.click(set_indie_rock_prompt, inputs=[bpm, drum_beat, synthesizer, rhythmic_steps, bass_style, guitar_style], outputs=instrumental_prompt)
|
657 |
+
funk_rock_btn.click(set_funk_rock_prompt, inputs=[bpm, drum_beat, synthesizer, rhythmic_steps, bass_style, guitar_style], outputs=instrumental_prompt)
|
658 |
detroit_techno_btn.click(set_detroit_techno_prompt, inputs=[bpm, drum_beat, synthesizer, rhythmic_steps, bass_style, guitar_style], outputs=instrumental_prompt)
|
659 |
deep_house_btn.click(set_deep_house_prompt, inputs=[bpm, drum_beat, synthesizer, rhythmic_steps, bass_style, guitar_style], outputs=instrumental_prompt)
|
660 |
+
funk_vocal_btn.click(set_upbeat_funk_rock_vocal_prompt, inputs=[], outputs=vocal_prompt)
|
661 |
+
grunge_vocal_btn.click(set_grunge_ballad_vocal_prompt, inputs=[], outputs=vocal_prompt)
|
662 |
+
indie_vocal_btn.click(set_indie_pop_vocal_prompt, inputs=[], outputs=vocal_prompt)
|
663 |
gen_btn.click(
|
664 |
generate_music,
|
665 |
inputs=[instrumental_prompt, vocal_prompt, cfg_scale, top_k, top_p, temperature, total_duration, chunk_duration, crossfade_duration, bpm, drum_beat, synthesizer, rhythmic_steps, bass_style, guitar_style],
|
|
|
671 |
outputs=[instrumental_prompt, vocal_prompt, cfg_scale, top_k, top_p, temperature, total_duration, chunk_duration, crossfade_duration, bpm, drum_beat, synthesizer, rhythmic_steps, bass_style, guitar_style]
|
672 |
)
|
673 |
|
674 |
+
# 10) TURN OFF OPENAPI/DOCS
|
675 |
app = demo.launch(
|
676 |
server_name="0.0.0.0",
|
677 |
server_port=9999,
|
|
|
685 |
fastapi_app.redoc_url = None
|
686 |
fastapi_app.openapi_url = None
|
687 |
except Exception:
|
688 |
+
pass
|