Update barks.py
Browse files
barks.py
CHANGED
|
@@ -240,17 +240,53 @@ Oh-oh-oh, we're burnin' up the stage,
|
|
| 240 |
Funk it up, we're livin' for the rage!"""
|
| 241 |
|
| 242 |
def set_grunge_ballad_vocal_prompt():
|
| 243 |
-
return """[Verse 1,
|
| 244 |
Shadows fall across my heart, I'm lost in the rain,
|
| 245 |
-
Whispers of a broken dream, carry all my pain
|
| 246 |
Underneath the weight of time, I’m fading away,
|
| 247 |
Searching for a spark to light another day.
|
| 248 |
|
| 249 |
-
[Chorus,
|
| 250 |
Scream it out, let the silence break,
|
| 251 |
-
Feel the fire, for my soul’s sake
|
| 252 |
Hold me now, through the endless night,
|
| 253 |
-
In the dark, I’m reaching for the light!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
|
| 255 |
def set_indie_pop_vocal_prompt():
|
| 256 |
return """[Verse 1, indie pop, female voice]
|
|
@@ -276,13 +312,24 @@ def apply_fade(segment, fade_in_duration=1000, fade_out_duration=1000):
|
|
| 276 |
segment = segment.fade_out(fade_out_duration)
|
| 277 |
return segment
|
| 278 |
|
| 279 |
-
def generate_vocals(vocal_prompt: str, total_duration: int):
|
| 280 |
global bark_model, bark_processor
|
| 281 |
if not vocal_prompt.strip():
|
| 282 |
return None, "⚠️ Please enter a valid vocal prompt!"
|
| 283 |
|
| 284 |
try:
|
| 285 |
print("Generating vocals with Bark...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
# Process vocal prompt with attention mask, relying on default padding
|
| 287 |
inputs = bark_processor(
|
| 288 |
vocal_prompt,
|
|
@@ -323,7 +370,7 @@ def generate_vocals(vocal_prompt: str, total_duration: int):
|
|
| 323 |
return None, f"❌ Vocal generation failed: {e}"
|
| 324 |
|
| 325 |
# 7) GENERATION & I/O FUNCTIONS
|
| 326 |
-
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):
|
| 327 |
global musicgen_model
|
| 328 |
if not instrumental_prompt.strip():
|
| 329 |
return None, "⚠️ Please enter a valid instrumental prompt!"
|
|
@@ -399,7 +446,7 @@ def generate_music(instrumental_prompt: str, vocal_prompt: str, cfg_scale: float
|
|
| 399 |
|
| 400 |
# Generate vocals if provided
|
| 401 |
if vocal_prompt.strip():
|
| 402 |
-
vocal_segment, vocal_status = generate_vocals(vocal_prompt, total_duration)
|
| 403 |
if vocal_segment is None:
|
| 404 |
return None, vocal_status
|
| 405 |
print("Mixing vocals with instrumental...")
|
|
@@ -430,7 +477,7 @@ def generate_music(instrumental_prompt: str, vocal_prompt: str, cfg_scale: float
|
|
| 430 |
|
| 431 |
# Function to clear inputs
|
| 432 |
def clear_inputs():
|
| 433 |
-
return "", "", 3.0, 250, 0.9, 1.0, 30, 5, 1000, 120, "none", "none", "none", "none", "none"
|
| 434 |
|
| 435 |
# 8) CUSTOM CSS
|
| 436 |
css = """
|
|
@@ -552,6 +599,13 @@ with gr.Blocks(css=css) as demo:
|
|
| 552 |
funk_vocal_btn = gr.Button("Upbeat Funk Rock 🎵", elem_classes="vocal-btn")
|
| 553 |
grunge_vocal_btn = gr.Button("Grunge Ballad 🎸", elem_classes="vocal-btn")
|
| 554 |
indie_vocal_btn = gr.Button("Indie Pop 🎤", elem_classes="vocal-btn")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 555 |
|
| 556 |
with gr.Column(elem_classes="settings-container"):
|
| 557 |
gr.Markdown("### ⚙️ API Settings")
|
|
@@ -680,13 +734,13 @@ with gr.Blocks(css=css) as demo:
|
|
| 680 |
indie_vocal_btn.click(set_indie_pop_vocal_prompt, inputs=[], outputs=vocal_prompt)
|
| 681 |
gen_btn.click(
|
| 682 |
generate_music,
|
| 683 |
-
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],
|
| 684 |
outputs=[out_audio, status]
|
| 685 |
)
|
| 686 |
clr_btn.click(
|
| 687 |
clear_inputs,
|
| 688 |
inputs=None,
|
| 689 |
-
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]
|
| 690 |
)
|
| 691 |
|
| 692 |
# 10) TURN OFF OPENAPI/DOCS
|
|
|
|
| 240 |
Funk it up, we're livin' for the rage!"""
|
| 241 |
|
| 242 |
def set_grunge_ballad_vocal_prompt():
|
| 243 |
+
return """[Verse 1 – Soft, Grunge Ballad, male voice]
|
| 244 |
Shadows fall across my heart, I'm lost in the rain,
|
| 245 |
+
Whispers of a broken dream, carry all my pain.
|
| 246 |
Underneath the weight of time, I’m fading away,
|
| 247 |
Searching for a spark to light another day.
|
| 248 |
|
| 249 |
+
[Chorus – Intense, male voice]
|
| 250 |
Scream it out, let the silence break,
|
| 251 |
+
Feel the fire, for my soul’s sake.
|
| 252 |
Hold me now, through the endless night,
|
| 253 |
+
In the dark, I’m reaching for the light!
|
| 254 |
+
|
| 255 |
+
[Verse 2 – Building Intensity, male voice]
|
| 256 |
+
Cracks appear in my reflection, truth I can't deny,
|
| 257 |
+
Memories like ghosts surround, no matter how I try.
|
| 258 |
+
Each step forward feels like I'm walking through the past,
|
| 259 |
+
Chasing echoes of a peace that never seems to last.
|
| 260 |
+
|
| 261 |
+
[Chorus – Intensified, male voice]
|
| 262 |
+
Scream it out, let the silence break,
|
| 263 |
+
Feel the fire, for my soul’s sake.
|
| 264 |
+
Hold me now, through the endless night,
|
| 265 |
+
In the dark, I’m reaching for the light!
|
| 266 |
+
|
| 267 |
+
[Bridge – Emotional Climax, male voice]
|
| 268 |
+
I’ve been down this road before,
|
| 269 |
+
Locked behind a closing door.
|
| 270 |
+
But even in the blackest shade,
|
| 271 |
+
A flicker of hope refuses to fade.
|
| 272 |
+
|
| 273 |
+
[Verse 3 – Reflective, male voice]
|
| 274 |
+
Rain-soaked streets and neon signs,
|
| 275 |
+
Mark the path of these troubled times.
|
| 276 |
+
Yet amidst the storm and strife,
|
| 277 |
+
I find fragments of a former life.
|
| 278 |
+
|
| 279 |
+
[Chorus – Final, Powerful, male voice]
|
| 280 |
+
Scream it out, let the silence break,
|
| 281 |
+
Feel the fire, for my soul’s sake.
|
| 282 |
+
Hold me now, through the endless night,
|
| 283 |
+
In the dark, I’m reaching for the light!
|
| 284 |
+
|
| 285 |
+
[Outro – Soft, Resolute, male voice]
|
| 286 |
+
Though shadows linger and nights are long,
|
| 287 |
+
Within my soul, I find a song.
|
| 288 |
+
A melody of hope, burning bright,
|
| 289 |
+
Guiding me onward, into the light."""
|
| 290 |
|
| 291 |
def set_indie_pop_vocal_prompt():
|
| 292 |
return """[Verse 1, indie pop, female voice]
|
|
|
|
| 312 |
segment = segment.fade_out(fade_out_duration)
|
| 313 |
return segment
|
| 314 |
|
| 315 |
+
def generate_vocals(vocal_prompt: str, total_duration: int, speaker_preset: str):
|
| 316 |
global bark_model, bark_processor
|
| 317 |
if not vocal_prompt.strip():
|
| 318 |
return None, "⚠️ Please enter a valid vocal prompt!"
|
| 319 |
|
| 320 |
try:
|
| 321 |
print("Generating vocals with Bark...")
|
| 322 |
+
# Apply speaker preset if specified
|
| 323 |
+
if speaker_preset != "default":
|
| 324 |
+
vocal_prompt = f"[{speaker_preset}] {vocal_prompt}"
|
| 325 |
+
|
| 326 |
+
# Check token length
|
| 327 |
+
tokens = bark_processor.tokenize(vocal_prompt)
|
| 328 |
+
token_ids = bark_processor.convert_tokens_to_ids(tokens)
|
| 329 |
+
if len(token_ids) > 512:
|
| 330 |
+
print("WARNING: Vocal prompt exceeds 512 tokens; truncating to avoid errors.")
|
| 331 |
+
vocal_prompt = bark_processor.decode(token_ids[:512])
|
| 332 |
+
|
| 333 |
# Process vocal prompt with attention mask, relying on default padding
|
| 334 |
inputs = bark_processor(
|
| 335 |
vocal_prompt,
|
|
|
|
| 370 |
return None, f"❌ Vocal generation failed: {e}"
|
| 371 |
|
| 372 |
# 7) GENERATION & I/O FUNCTIONS
|
| 373 |
+
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, speaker_preset: str):
|
| 374 |
global musicgen_model
|
| 375 |
if not instrumental_prompt.strip():
|
| 376 |
return None, "⚠️ Please enter a valid instrumental prompt!"
|
|
|
|
| 446 |
|
| 447 |
# Generate vocals if provided
|
| 448 |
if vocal_prompt.strip():
|
| 449 |
+
vocal_segment, vocal_status = generate_vocals(vocal_prompt, total_duration, speaker_preset)
|
| 450 |
if vocal_segment is None:
|
| 451 |
return None, vocal_status
|
| 452 |
print("Mixing vocals with instrumental...")
|
|
|
|
| 477 |
|
| 478 |
# Function to clear inputs
|
| 479 |
def clear_inputs():
|
| 480 |
+
return "", "", 3.0, 250, 0.9, 1.0, 30, 5, 1000, 120, "none", "none", "none", "none", "none", "default"
|
| 481 |
|
| 482 |
# 8) CUSTOM CSS
|
| 483 |
css = """
|
|
|
|
| 599 |
funk_vocal_btn = gr.Button("Upbeat Funk Rock 🎵", elem_classes="vocal-btn")
|
| 600 |
grunge_vocal_btn = gr.Button("Grunge Ballad 🎸", elem_classes="vocal-btn")
|
| 601 |
indie_vocal_btn = gr.Button("Indie Pop 🎤", elem_classes="vocal-btn")
|
| 602 |
+
|
| 603 |
+
speaker_preset = gr.Dropdown(
|
| 604 |
+
label="Bark Speaker Preset 🎙️",
|
| 605 |
+
choices=["default", "v2/en_speaker_6", "v2/en_speaker_9"],
|
| 606 |
+
value="default",
|
| 607 |
+
info="Select a speaker preset to influence vocal style (e.g., male or female voice). Note: Bark is primarily a speech model; singing styles are limited and best controlled via prompt cues (e.g., [soft], [intense])."
|
| 608 |
+
)
|
| 609 |
|
| 610 |
with gr.Column(elem_classes="settings-container"):
|
| 611 |
gr.Markdown("### ⚙️ API Settings")
|
|
|
|
| 734 |
indie_vocal_btn.click(set_indie_pop_vocal_prompt, inputs=[], outputs=vocal_prompt)
|
| 735 |
gen_btn.click(
|
| 736 |
generate_music,
|
| 737 |
+
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, speaker_preset],
|
| 738 |
outputs=[out_audio, status]
|
| 739 |
)
|
| 740 |
clr_btn.click(
|
| 741 |
clear_inputs,
|
| 742 |
inputs=None,
|
| 743 |
+
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, speaker_preset]
|
| 744 |
)
|
| 745 |
|
| 746 |
# 10) TURN OFF OPENAPI/DOCS
|