Spaces:
Running
Running
2B-Studio: DAW-Studio, neue Modelle (YuE2, TangoFlux, AudioGen, AudioLDM2), Lizenz-Badges, HF-Login, Einswarm Schwarz/Gold
c600f78 verified Download studio/model_status.py from 2Btainment/2b-studio: direct link, hf CLI and curl.
- Browser
- Download file 4.63 kB
-
https://huggingface.co/spaces/2Btainment/2b-studio/resolve/main/studio/model_status.py
- Command line
-
hf download hf://spaces/2Btainment/2b-studio/studio/model_status.py
-
curl -L -o model_status.py https://huggingface.co/spaces/2Btainment/2b-studio/resolve/main/studio/model_status.py
4.63 kB
| """Drop-in helpers for studio/ui.py model status (live probe). | |
| Replace _model_status_html usage with model_status_html_live after wiring | |
| AdapterRouter / HealthCache. | |
| """ | |
| from __future__ import annotations | |
| from html import escape | |
| from studio.adapters.health import HealthCache, probe_space | |
| from studio.adapters.router import route_id_for_model | |
| from studio.registry import ModelRegistry | |
| _CACHE = HealthCache(ttl_s=20.0) | |
| _LABEL_DE = { | |
| "live": "Live", | |
| "sleeping": "Schlafend (wird beim Generate geweckt)", | |
| "paused": "Pausiert", | |
| "mock": "Demo-Modus (Mock)", | |
| "broken": "Defekt", | |
| "unauthorized": "Privat — HF_TOKEN fehlt/ungültig", | |
| "private-needs-token": "Privat — HF_TOKEN setzen", | |
| "unreachable": "Nicht erreichbar", | |
| } | |
| def model_status_html_live(model_id: str, registry: ModelRegistry) -> str: | |
| model = registry.get(model_id) | |
| route_id = route_id_for_model(model) | |
| space_ref = model.space_ref or "—" | |
| probe = _CACHE.get(space_ref) if model.space_ref else { | |
| "ok": False, | |
| "label": "unreachable", | |
| "stage": None, | |
| "hardware": None, | |
| } | |
| state = str(probe.get("label")) | |
| if state == "live" and route_id.endswith("-mock"): | |
| state = "mock" | |
| status = _LABEL_DE.get(state, state) | |
| hint = { | |
| "paused": "Dieses Modell ist derzeit pausiert und kann nicht generieren – bitte ein Modell " | |
| "mit Status „Live“ wählen. (Betreiber: Worker im HF-Dashboard neu starten.)", | |
| "sleeping": "Der Worker schläft und wird beim Generieren geweckt – der erste Take dauert " | |
| "dann 1–3 Minuten länger.", | |
| "mock": "Kein HF_TOKEN als Space-Secret gesetzt – dieses Modell liefert nur Test-Audio. " | |
| "Secret HF_TOKEN in den Space-Settings eintragen.", | |
| "unauthorized": "Privater Worker – HF_TOKEN mit Lesezugriff als Space-Secret setzen.", | |
| "private-needs-token": "Privater Worker – HF_TOKEN mit Lesezugriff als Space-Secret setzen.", | |
| }.get(state, "") | |
| hint_html = ( | |
| f'<p class="model-status-hint" data-state="{escape(state)}">{escape(hint)}</p>' if hint else "" | |
| ) | |
| vocals = "Gesang" if model.supports_vocals else "Instrumental" | |
| lyrics = "Lyrics" if model.supports_lyrics else "keine Lyrics" | |
| blockers = ( | |
| f" · Worker-Blocker: {', '.join(model.blockers)}" if model.blockers else "" | |
| ) | |
| hw = probe.get("hardware") or "—" | |
| return f""" | |
| <section class="model-status-card"> | |
| <div><strong>{escape(model.label)}</strong><span>{escape(model.route_label)}</span></div> | |
| <div class="model-status-pills"> | |
| <b data-state="{escape(state)}">{escape(status)}</b> | |
| <span>{vocals}</span><span>{lyrics}</span> | |
| <span>max. {model.max_duration_s} s</span> | |
| <span>HW {escape(str(hw))}</span> | |
| </div> | |
| <small>Worker <code>{escape(space_ref)}</code> · Stage <code>{escape(str(probe.get('stage')))}</code> | |
| · Route <code>{escape(route_id)}</code> · Adapter <code>{escape(model.adapter)}</code> | |
| {escape(blockers)}.</small> | |
| {hint_html} | |
| </section> | |
| """ | |
| def refresh_all_model_labels(registry: ModelRegistry) -> list[tuple[str, str]]: | |
| """Dropdown labels with live suffix: 'MiniMax Music 3 · Live'.""" | |
| out: list[tuple[str, str]] = [] | |
| for model in registry.models: | |
| probe = probe_space(model.space_ref) if model.space_ref else {"label": "?"} | |
| suffix = _LABEL_DE.get(str(probe.get("label")), str(probe.get("label"))) | |
| out.append((f"{model.label} · {suffix} · {model.license_badge_label}", model.id)) | |
| return out | |
| def model_state(model_id: str, registry: ModelRegistry) -> str: | |
| """Kurzzustand eines Modells: live · sleeping · paused · mock · broken · unreachable …""" | |
| model = registry.get(model_id) | |
| if not model.space_ref: | |
| return "unreachable" | |
| state = str(_CACHE.get(model.space_ref).get("label")) | |
| if state == "live" and route_id_for_model(model).endswith("-mock"): | |
| state = "mock" | |
| return state | |
| def is_unusable(state: str) -> bool: | |
| return state in {"paused", "broken", "unauthorized", "private-needs-token", "unreachable"} | |
| def refresh_model_labels_cached(registry: ModelRegistry) -> list[tuple[str, str]]: | |
| """Wie refresh_all_model_labels, aber über den 20-s-Cache (für ↻ Status / Seitenaufruf).""" | |
| out: list[tuple[str, str]] = [] | |
| for model in registry.models: | |
| state = model_state(model.id, registry) | |
| out.append((f"{model.label} · {_LABEL_DE.get(state, state).split(' (')[0]} · {model.license_badge_label}", model.id)) | |
| return out | |