import os import tempfile # IMPORTANT: `import spaces` must come BEFORE `import torch` on ZeroGPU import spaces import torch import numpy as np import librosa import soundfile as sf import gradio as gr from diffusers import AceStepPipeline # Official Diffusers-format Base model (required for Vocal2BGM / `complete` task). # Lighter 2B alternative if ever needed: "Runware/acestep-v15-base-diffusers" MODEL_ID = os.environ.get("MODEL_ID", "ACE-Step/acestep-v15-xl-base-diffusers") # Load pipeline at module scope so ZeroGPU packs weights at startup pipe = AceStepPipeline.from_pretrained( MODEL_ID, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True, ) pipe = pipe.to("cuda") pipe.vae.enable_tiling() TRACK_CHOICES = [ "drums", "bass", "guitar", "keyboard", "strings", "synth", "percussion", "brass", "woodwinds", "backing_vocals", ] LANGUAGE_CHOICES = [ "en", "hi", "zh", "ja", "ko", "es", "fr", "de", "it", "pt", "ru", "ar" ] STYLE_PRESETS = { "🎹 Cozy Piano & Strings": "emotional acoustic piano, warm soft strings, intimate studio ballad", "🌸 Dreamy City Pop": "sparkling retro synth, groovy electric bass, crisp city-pop drums, dreamy chords", "🎸 Lo-Fi Acoustic": "warm fingerpicked acoustic guitar, dusty lo-fi chill drums, soft Rhodes keys", "✨ Ethereal Synthwave": "lush analog pads, shimmering arpeggios, punchy electronic drums, dreamy reverb", "🎻 Cinematic Orchestral": "sweeping cinematic strings, gentle harp, warm brass swell, expressive percussion", } def load_stereo_48k(audio_path: str, target_sr: int = 48000) -> tuple[torch.Tensor, float]: """Load any audio file, resample to 48kHz, and convert to stereo [2, samples] float32 tensor.""" y, _ = librosa.load(audio_path, sr=target_sr, mono=False) if y.ndim == 1: y = np.stack([y, y], axis=0) elif y.shape[0] == 1: y = np.repeat(y, 2, axis=0) elif y.shape[0] > 2: y = y[:2, :] peak = float(np.max(np.abs(y))) if peak > 1.0: y = y / peak duration_sec = y.shape[-1] / float(target_sr) tensor = torch.from_numpy(np.ascontiguousarray(y)).float() return tensor, duration_sec # ============================================================================== # PURE CPU HELPERS (NO @spaces.GPU — ZERO DAILY QUOTA USED) # ============================================================================== def build_status_html(mode: str, message: str) -> str: """Render an animated tech-pink status pill (pure HTML/CSS, zero GPU).""" badge_class = { "idle": "status-pill status-idle", "ready": "status-pill status-ready", "done": "status-pill status-done", }.get(mode, "status-pill status-idle") return f"""
{message}
""" def update_generate_readiness(vocal_audio_path: str | None, style_prompt: str | None): """Enable Generate ONLY when both vocal audio and style text exist (CPU-only).""" has_audio = bool(vocal_audio_path) has_style = bool(style_prompt and style_prompt.strip()) if has_audio and has_style: return ( gr.update(interactive=True, value="🌸 Generate Background Music ✨"), build_status_html("ready", "READY // Click Generate to run on ZeroGPU 🩷"), ) elif has_audio and not has_style: return ( gr.update(interactive=False, value="🌸 Type a Music Style to Unlock"), build_status_html("idle", "GPU STANDBY // Vocals loaded — now describe a style ✍️"), ) elif not has_audio and has_style: return ( gr.update(interactive=False, value="🌸 Upload Singing Audio to Unlock"), build_status_html("idle", "GPU STANDBY // Style ready — now upload or record vocals 🎤"), ) else: return ( gr.update(interactive=False, value="🌸 Upload Audio & Type Style to Unlock"), build_status_html("idle", "GPU STANDBY // Zero quota used while browsing & typing 🌸"), ) def apply_style_preset(preset_label: str) -> str: """Fill style prompt from a cute preset chip (CPU-only).""" return STYLE_PRESETS.get(preset_label, "") # ============================================================================== # GPU GENERATION (THE ONLY FUNCTION WITH @spaces.GPU) # ============================================================================== @spaces.GPU(duration=120) def generate_bgm( vocal_audio_path: str, style_prompt: str, lyrics: str, selected_instruments: list[str], vocal_language: str, bpm: int, keyscale: str, timesignature: str, num_inference_steps: int, guidance_scale: float, shift: float, seed: int, ) -> tuple[str, str]: if not vocal_audio_path: raise gr.Error("🌸 Please upload or record a vocal audio track first!") if not style_prompt or not style_prompt.strip(): raise gr.Error("🌸 Please type a background music style first!") src_audio, src_duration = load_stereo_48k(vocal_audio_path, target_sr=pipe.sample_rate) if src_duration < 2.0: raise gr.Error("🌸 Vocal clip is too short (< 2 seconds). Please provide at least 5–10 seconds of singing.") if seed < 0: actual_seed = int(torch.randint(0, 2**31 - 1, (1,)).item()) else: actual_seed = int(seed) generator = torch.Generator(device="cuda").manual_seed(actual_seed) output = pipe( prompt=style_prompt.strip(), lyrics=lyrics.strip() if lyrics else "", task_type="complete", complete_track_classes=selected_instruments if selected_instruments else None, src_audio=src_audio, audio_duration=None, vocal_language=vocal_language, bpm=int(bpm) if bpm and int(bpm) > 0 else None, keyscale=keyscale.strip() if keyscale and keyscale.strip() else None, timesignature=timesignature.strip() if timesignature and timesignature.strip() else None, num_inference_steps=int(num_inference_steps), guidance_scale=float(guidance_scale), shift=float(shift), generator=generator, ) audio = output.audios[0] audio_np = audio.T.cpu().float().numpy() with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp: out_path = tmp.name sf.write(out_path, audio_np, pipe.sample_rate) status_html = build_status_html( "done", f"BLOOMED ✨ // {src_duration:.1f}s • Seed {actual_seed} • {num_inference_steps} steps 🌸", ) return out_path, status_html # ============================================================================== # COZY TECHY PINK THEME + ANIMATIONS (PURE CSS + SVG) # ============================================================================== pink_theme = gr.themes.Soft( primary_hue="pink", secondary_hue="rose", neutral_hue="slate", font=[gr.themes.GoogleFont("Quicksand"), "ui-sans-serif", "sans-serif"], font_mono=[gr.themes.GoogleFont("JetBrains Mono"), "ui-monospace", "monospace"], ) CUSTOM_CSS = """ /* Force crisp white + cozy sakura-pink light aesthetic regardless of OS dark mode */ :root, .dark, body, .gradio-container { --bg-white: #ffffff; --pink-50: #fff5fa; --pink-100: #ffe6f2; --pink-200: #ffc7e2; --pink-300: #ff99cb; --pink-400: #ff66b2; --pink-500: #ff3b9a; --pink-600: #e61e80; --ink-main: #4a2338; --ink-soft: #8f5c78; --body-background-fill: #ffffff !important; --background-fill-primary: #ffffff !important; --background-fill-secondary: #fff7fb !important; --block-background-fill: rgba(255, 255, 255, 0.94) !important; --block-border-color: #ffd1e8 !important; --block-label-background-fill: #fff0f7 !important; --block-label-text-color: #d6287e !important; --body-text-color: #4a2338 !important; --body-text-color-subdued: #8f5c78 !important; --input-background-fill: #ffffff !important; --input-border-color: #ffc8e3 !important; --input-border-color-focus: #ff4da6 !important; --color-accent: #ff4da6 !important; --color-accent-soft: #ffe8f3 !important; } body, .gradio-container { background-color: #ffffff !important; background-image: radial-gradient(circle at 12% 10%, rgba(255, 178, 217, 0.22) 0%, transparent 32%), radial-gradient(circle at 88% 18%, rgba(255, 198, 226, 0.24) 0%, transparent 28%), radial-gradient(circle at 50% 92%, rgba(255, 214, 235, 0.20) 0%, transparent 36%), radial-gradient(rgba(255, 105, 180, 0.16) 1px, transparent 1px) !important; background-size: 100% 100%, 100% 100%, 100% 100%, 24px 24px !important; color: var(--ink-main) !important; overflow-x: hidden !important; } .gradio-container { max-width: 1180px !important; margin: 0 auto !important; padding: 18px 20px 44px !important; position: relative; } /* ---------------- Floating Sakura Petals (Pure CSS) ---------------- */ .sakura-stage { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 9999; } .petal { position: absolute; top: -40px; font-size: 18px; opacity: 0.72; user-select: none; filter: drop-shadow(0 2px 4px rgba(255, 105, 180, 0.25)); animation: sakuraFall var(--dur, 14s) linear infinite; animation-delay: var(--delay, 0s); } .p1 { left: 6%; --dur: 13s; --delay: -2s; font-size: 16px; } .p2 { left: 19%; --dur: 17s; --delay: -7s; font-size: 20px; } .p3 { left: 34%; --dur: 14s; --delay: -4s; font-size: 14px; } .p4 { left: 52%; --dur: 18s; --delay: -11s; font-size: 19px; } .p5 { left: 68%; --dur: 15s; --delay: -5s; font-size: 15px; } .p6 { left: 82%; --dur: 16s; --delay: -9s; font-size: 21px; } .p7 { left: 93%; --dur: 12.5s; --delay: -1s; font-size: 15px; } @keyframes sakuraFall { 0% { transform: translateY(-40px) translateX(0px) rotate(0deg) scale(0.9); opacity: 0; } 10% { opacity: 0.78; } 50% { transform: translateY(50vh) translateX(32px) rotate(190deg) scale(1.05); } 90% { opacity: 0.65; } 100% { transform: translateY(108vh) translateX(-24px) rotate(380deg) scale(0.88); opacity: 0; } } /* ---------------- Tech-Pink Hero Banner ---------------- */ .hero-card { position: relative; background: linear-gradient(135deg, #ffffff 0%, #fff4fa 55%, #ffeaf5 100%); border: 1.5px solid #ffb8dc; border-radius: 24px; padding: 24px 28px; margin-bottom: 18px; box-shadow: 0 12px 34px rgba(255, 77, 166, 0.12), inset 0 0 0 1px rgba(255, 255, 255, 0.9); overflow: hidden; animation: fadeSlideDown 0.7s cubic-bezier(0.22, 1, 0.36, 1) both; } /* Tech cyber corner brackets */ .hero-card::before, .hero-card::after { content: ""; position: absolute; width: 22px; height: 22px; border-color: #ff4da6; border-style: solid; pointer-events: none; animation: cornerGlow 2.8s ease-in-out infinite; } .hero-card::before { top: 10px; left: 10px; border-width: 2.5px 0 0 2.5px; border-top-left-radius: 8px; } .hero-card::after { bottom: 10px; right: 10px; border-width: 0 2.5px 2.5px 0; border-bottom-right-radius: 8px; } @keyframes cornerGlow { 0%, 100% { opacity: 0.55; filter: drop-shadow(0 0 2px #ff85c2); } 50% { opacity: 1; filter: drop-shadow(0 0 7px #ff3b9a); } } /* Sweeping holo scanline */ .hero-scan { position: absolute; top: 0; left: -40%; width: 35%; height: 100%; background: linear-gradient(90deg, transparent, rgba(255, 130, 195, 0.16), transparent); transform: skewX(-18deg); animation: holoSweep 5.5s ease-in-out infinite; pointer-events: none; } @keyframes holoSweep { 0% { left: -45%; } 45% { left: 125%; } 100% { left: 125%; } } .hero-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px; position: relative; z-index: 2; } .hero-title-wrap { display: flex; align-items: center; gap: 14px; } .flower-badge { width: 52px; height: 52px; border-radius: 16px; background: linear-gradient(135deg, #ff7eb9, #ff3b9a); display: flex; align-items: center; justify-content: center; font-size: 26px; box-shadow: 0 8px 20px rgba(255, 59, 154, 0.30); animation: gentleFloat 3.4s ease-in-out infinite; } .flower-spin { display: inline-block; animation: softSpin 12s linear infinite; } @keyframes gentleFloat { 0%, 100% { transform: translateY(0px) rotate(0deg); } 50% { transform: translateY(-5px) rotate(3deg); } } @keyframes softSpin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } .hero-title { margin: 0 !important; font-size: 1.75rem !important; font-weight: 800 !important; background: linear-gradient(90deg, #d61c78 0%, #ff4da6 55%, #ff85c0 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; letter-spacing: -0.02em; } .hero-sub { margin: 4px 0 0 !important; color: #7e4b67 !important; font-size: 0.96rem !important; font-weight: 600; } /* Equalizer bars */ .eq-bars { display: flex; align-items: flex-end; gap: 4px; height: 30px; padding: 6px 12px; background: #ffffff; border: 1px solid #ffc7e2; border-radius: 14px; box-shadow: 0 4px 14px rgba(255, 105, 180, 0.12); } .eq-bar { width: 4px; border-radius: 4px; background: linear-gradient(180deg, #ff3b9a, #ffa6d2); animation: eqDance 1.1s ease-in-out infinite; } .eq-bar:nth-child(1) { height: 10px; animation-delay: 0.0s; } .eq-bar:nth-child(2) { height: 22px; animation-delay: 0.15s; } .eq-bar:nth-child(3) { height: 15px; animation-delay: 0.30s; } .eq-bar:nth-child(4) { height: 26px; animation-delay: 0.45s; } .eq-bar:nth-child(5) { height: 18px; animation-delay: 0.60s; } .eq-bar:nth-child(6) { height: 24px; animation-delay: 0.25s; } .eq-bar:nth-child(7) { height: 12px; animation-delay: 0.50s; } @keyframes eqDance { 0%, 100% { transform: scaleY(0.45); opacity: 0.7; } 50% { transform: scaleY(1.0); opacity: 1; } } .tech-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; position: relative; z-index: 2; } .tech-chip { font-family: 'JetBrains Mono', monospace; font-size: 0.74rem; font-weight: 600; color: #c91871; background: rgba(255, 255, 255, 0.9); border: 1px solid #ffb8dc; border-radius: 999px; padding: 4px 11px; transition: transform 0.25s ease, box-shadow 0.25s ease; } .tech-chip:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(255, 77, 166, 0.20); } /* ---------------- Panels / Cards & Entrances ---------------- */ .cozy-panel { background: rgba(255, 255, 255, 0.94) !important; border: 1.5px solid #ffd1e8 !important; border-radius: 22px !important; padding: 18px !important; box-shadow: 0 10px 28px rgba(255, 105, 180, 0.08) !important; transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease !important; animation: fadeSlideUp 0.75s cubic-bezier(0.22, 1, 0.36, 1) both; } .cozy-panel:hover { border-color: #ff99cc !important; box-shadow: 0 14px 34px rgba(255, 77, 166, 0.14) !important; } @keyframes fadeSlideDown { from { opacity: 0; transform: translateY(-16px); } to { opacity: 1; transform: translateY(0); } } @keyframes fadeSlideUp { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } } .section-heading { display: flex; align-items: center; justify-content: space-between; font-weight: 700; font-size: 1.02rem; color: #c91871; padding-bottom: 8px; margin-bottom: 6px; border-bottom: 1.5px dashed #ffc7e2; } /* ---------------- Inputs, Textboxes, Audio ---------------- */ textarea, input[type="text"], input[type="number"], select { background: #ffffff !important; border: 1.5px solid #ffd1e8 !important; border-radius: 14px !important; color: #4a2338 !important; transition: all 0.25s ease !important; } textarea:focus, input[type="text"]:focus, input[type="number"]:focus { border-color: #ff4da6 !important; box-shadow: 0 0 0 4px rgba(255, 77, 166, 0.14) !important; transform: translateY(-1px); } /* Checkbox instrument pills */ .instrument-group label { background: #fff8fc !important; border: 1.5px solid #ffd1e8 !important; border-radius: 999px !important; padding: 6px 13px !important; color: #6d3654 !important; font-weight: 600 !important; transition: all 0.22s cubic-bezier(0.34, 1.56, 0.64, 1) !important; } .instrument-group label:hover { transform: translateY(-2px) scale(1.03); border-color: #ff66b2 !important; box-shadow: 0 4px 12px rgba(255, 102, 178, 0.18); } .instrument-group label.selected, .instrument-group input:checked + span { color: #c91871 !important; } /* ---------------- Quick Style Preset Buttons ---------------- */ .preset-btn button, button.preset-btn { background: #fff5fa !important; border: 1.5px solid #ffbfe0 !important; color: #c91871 !important; border-radius: 999px !important; font-size: 0.82rem !important; font-weight: 700 !important; padding: 6px 12px !important; transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) !important; box-shadow: 0 3px 10px rgba(255, 105, 180, 0.08) !important; } .preset-btn button:hover, button.preset-btn:hover { background: linear-gradient(135deg, #ffe3f1, #ffd0e8) !important; border-color: #ff4da6 !important; transform: translateY(-2px) scale(1.04) !important; box-shadow: 0 6px 16px rgba(255, 77, 166, 0.22) !important; } .preset-btn button:active, button.preset-btn:active { transform: scale(0.96) !important; } /* ---------------- Techy Pink Primary Generate Button ---------------- */ .gen-btn button, button.gen-btn { position: relative !important; overflow: hidden !important; border-radius: 16px !important; font-weight: 800 !important; font-size: 1.05rem !important; letter-spacing: 0.02em !important; padding: 14px 20px !important; border: 1.5px solid #ff66b2 !important; background: linear-gradient(135deg, #ff70b8 0%, #ff3b9a 55%, #ff5cac 100%) !important; color: #ffffff !important; box-shadow: 0 10px 26px rgba(255, 59, 154, 0.30) !important; transition: all 0.28s cubic-bezier(0.34, 1.56, 0.64, 1) !important; } .gen-btn button:not(:disabled), button.gen-btn:not(:disabled) { animation: buttonPulse 2.4s ease-in-out infinite; } .gen-btn button:not(:disabled)::after, button.gen-btn:not(:disabled)::after { content: ""; position: absolute; top: -50%; left: -60%; width: 45%; height: 200%; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.42), transparent); transform: rotate(25deg); animation: btnShine 3.6s ease-in-out infinite; } .gen-btn button:hover:not(:disabled), button.gen-btn:hover:not(:disabled) { transform: translateY(-3px) scale(1.015) !important; box-shadow: 0 14px 32px rgba(255, 59, 154, 0.42) !important; } .gen-btn button:active:not(:disabled), button.gen-btn:active:not(:disabled) { transform: translateY(0px) scale(0.98) !important; } .gen-btn button:disabled, button.gen-btn:disabled { background: #fff0f7 !important; border: 1.5px dashed #ffb8dc !important; color: #c2789d !important; box-shadow: none !important; cursor: not-allowed !important; opacity: 0.9 !important; } @keyframes buttonPulse { 0%, 100% { box-shadow: 0 8px 22px rgba(255, 59, 154, 0.26); } 50% { box-shadow: 0 10px 30px rgba(255, 59, 154, 0.45), 0 0 0 5px rgba(255, 112, 184, 0.16); } } @keyframes btnShine { 0% { left: -65%; } 40% { left: 135%; } 100% { left: 135%; } } /* ---------------- Status Pill ---------------- */ .status-pill { display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-radius: 14px; font-family: 'JetBrains Mono', monospace; font-size: 0.80rem; font-weight: 600; border: 1.5px solid #ffd1e8; background: #fff9fc; color: #8f476b; transition: all 0.3s ease; } .status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; } .status-idle .status-dot { background: #ff99cb; box-shadow: 0 0 8px #ffb8dc; animation: idleBlink 2.2s ease-in-out infinite; } .status-ready { border-color: #ff66b2; background: linear-gradient(90deg, #fff2f8, #ffffff); color: #cc1b73; } .status-ready .status-dot { background: #ff3b9a; box-shadow: 0 0 10px #ff3b9a; animation: readyPing 1.3s ease-in-out infinite; } .status-done { border-color: #ff4da6; background: linear-gradient(90deg, #ffeaf4, #fff9fc); color: #b81466; } .status-done .status-dot { background: #ff2e93; box-shadow: 0 0 12px #ff2e93; } @keyframes idleBlink { 0%, 100% { opacity: 0.5; transform: scale(0.9); } 50% { opacity: 1; transform: scale(1.15); } } @keyframes readyPing { 0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 59, 154, 0.5); } 50% { transform: scale(1.2); box-shadow: 0 0 0 6px rgba(255, 59, 154, 0); } } /* Floral Footer Divider */ .floral-footer { text-align: center; margin-top: 18px; padding: 12px; color: #a86b8b; font-size: 0.86rem; font-weight: 600; } .floral-footer .flower-bob { display: inline-block; animation: gentleFloat 2.8s ease-in-out infinite; } """ HEADER_HTML = """
🌸

ACE-Step 1.5 • Sakura Vocal2BGM Studio

Sing dry vocals, pick a cozy vibe, and bloom synchronized backing music ✨🩷

MODEL // XL-BASE-1.5 MODE // VOCAL2BGM AUDIO // 48kHz STEREO ZERO-GPU // CLICK-ONLY GUARDED 🌸
""" DECO_FLOWER_CARD = """
🌸 Cozy Quota Shield Active:
Typing, animations, presets & audio uploads run 100% locally / on CPU. ZeroGPU only turns on after you click Generate.
💐
""" with gr.Blocks(title="🌸 ACE-Step 1.5 Sakura Vocal2BGM") as demo: gr.HTML(HEADER_HTML) with gr.Row(equal_height=False): with gr.Column(scale=1, elem_classes=["cozy-panel"]): gr.HTML('
🎤 01 // Vocal Input & Style🌸
') vocal_input = gr.Audio( label="Upload or Record Dry Singing Audio", type="filepath", sources=["upload", "microphone"], ) style_prompt = gr.Textbox( label="Background Music Style Prompt (Required to Unlock Generate)", placeholder="e.g., emotional acoustic piano, warm soft strings, subtle cello, cozy studio mix", value="", lines=2, ) gr.HTML('
✨ Quick Cozy Presets (CPU-only, no GPU used):
') with gr.Row(): preset_buttons = [ gr.Button(label, size="sm", elem_classes=["preset-btn"]) for label in STYLE_PRESETS.keys() ] instruments = gr.CheckboxGroup( label="Instruments to Layer (Optional — empty = auto arrangement)", choices=TRACK_CHOICES, value=["drums", "bass", "keyboard", "strings"], elem_classes=["instrument-group"], ) lyrics_box = gr.Textbox( label="Lyrics (Optional — helps vocal melody alignment)", placeholder="[verse]\nWrite your lyrics here...", lines=2, ) with gr.Accordion("🎛️ Tech Audio & Diffusion Controls", open=False): with gr.Row(): vocal_language = gr.Dropdown( label="Vocal Language", choices=LANGUAGE_CHOICES, value="en", ) bpm = gr.Number( label="BPM (0 = Auto-detect)", value=0, precision=0, minimum=0, maximum=300, ) with gr.Row(): keyscale = gr.Textbox( label="Key / Scale (blank = Auto)", placeholder="e.g., C major, A minor", value="", ) timesignature = gr.Textbox( label="Time Signature (blank = Auto)", placeholder="e.g., 4 (for 4/4), 3 (for 3/4)", value="", ) with gr.Row(): steps = gr.Slider( label="Inference Steps (30–60 recommended)", minimum=15, maximum=80, step=1, value=45, ) guidance_scale = gr.Slider( label="Guidance Scale", minimum=1.0, maximum=12.0, step=0.5, value=7.0, ) with gr.Row(): shift = gr.Slider( label="Timestep Shift", minimum=1.0, maximum=5.0, step=0.5, value=3.0, ) seed = gr.Number( label="Seed (-1 = Random)", value=-1, precision=0, ) generate_btn = gr.Button( "🌸 Upload Audio & Type Style to Unlock", variant="primary", interactive=False, elem_classes=["gen-btn"], ) with gr.Column(scale=1, elem_classes=["cozy-panel"]): gr.HTML('
🎧 02 // Generated Accompaniment🩷
') readiness_status = gr.HTML( value=build_status_html( "idle", "GPU STANDBY // Zero quota used while browsing & typing 🌸", ) ) audio_output = gr.Audio( label="Final Mix (Your Vocals + Generated Backing Track)", type="filepath", ) gr.HTML(DECO_FLOWER_CARD) gr.HTML( """ """ ) # Pure CPU event listeners (queue=False, NO @spaces.GPU -> zero GPU quota used) for btn in preset_buttons: btn.click( fn=apply_style_preset, inputs=[btn], outputs=[style_prompt], queue=False, show_progress="hidden", ) vocal_input.change( fn=update_generate_readiness, inputs=[vocal_input, style_prompt], outputs=[generate_btn, readiness_status], queue=False, show_progress="hidden", ) style_prompt.change( fn=update_generate_readiness, inputs=[vocal_input, style_prompt], outputs=[generate_btn, readiness_status], queue=False, show_progress="hidden", ) # ONLY this click triggers ZeroGPU (@spaces.GPU) generate_btn.click( fn=generate_bgm, inputs=[ vocal_input, style_prompt, lyrics_box, instruments, vocal_language, bpm, keyscale, timesignature, steps, guidance_scale, shift, seed, ], outputs=[audio_output, readiness_status], ) if __name__ == "__main__": demo.queue().launch(theme=pink_theme, css=CUSTOM_CSS)