Spaces:
Running
Running
Download studio/studio_room/html_ui.py from 2Btainment/2b-studio: direct link, hf CLI and curl.
- Browser
- Download file 4.87 kB
-
https://huggingface.co/spaces/2Btainment/2b-studio/resolve/main/studio/studio_room/html_ui.py
- Command line
-
hf download hf://spaces/2Btainment/2b-studio/studio/studio_room/html_ui.py
-
curl -L -o html_ui.py https://huggingface.co/spaces/2Btainment/2b-studio/resolve/main/studio/studio_room/html_ui.py
4.87 kB
| """HTML-Bausteine für Honeycomb, Chips und Empty State (Toxic Look).""" | |
| from __future__ import annotations | |
| from html import escape | |
| from typing import Any | |
| from studio.studio_room.catalog import WabeSpec | |
| def empty_state_html() -> str: | |
| return """ | |
| <div class="st-empty" id="st-empty"> | |
| <div class="st-empty__hive" aria-hidden="true"> | |
| <i></i><i></i><i></i><i></i><i></i><i></i><i></i> | |
| </div> | |
| <h2 class="st-empty__title">STUDIO</h2> | |
| <p class="st-empty__txt">Leer ist Feature. Sag 3B, was du brauchst — Waben docken von selbst an.</p> | |
| </div> | |
| """ | |
| def chips_html(chips: list[str]) -> str: | |
| if not chips: | |
| return '<div class="st-chips" id="st-chips"></div>' | |
| buttons = [] | |
| for chip in chips: | |
| buttons.append( | |
| f'<button type="button" class="st-chip" data-st-chip="{escape(chip, quote=True)}">{escape(chip)}</button>' | |
| ) | |
| return f'<div class="st-chips" id="st-chips" role="list">{"".join(buttons)}</div>' | |
| def _macro_controls(wabe: WabeSpec) -> str: | |
| if not wabe.macros: | |
| # show up to 3 primitive params as sliders | |
| rows = [] | |
| for prim in wabe.primitives[:1]: | |
| for key, val in list(prim.params.items())[:3]: | |
| rows.append( | |
| f'<label class="st-macro"><span>{escape(key)}</span>' | |
| f'<input type="range" min="0" max="100" value="{int(float(val) * 5 + 50) % 101}" ' | |
| f'data-st-macro="{escape(wabe.id)}" data-st-macro-key="{escape(key)}" data-st-prim="{escape(prim.id)}"/></label>' | |
| ) | |
| return "".join(rows) | |
| rows = [] | |
| for macro in wabe.macros: | |
| pct = int(round(float(macro.value) * 100)) | |
| rows.append( | |
| f'<label class="st-macro"><span>{escape(macro.name)}</span>' | |
| f'<input type="range" min="0" max="100" value="{pct}" ' | |
| f'data-st-macro="{escape(wabe.id)}" data-st-macro-key="{escape(macro.key)}"/></label>' | |
| ) | |
| return "".join(rows) | |
| def wabe_card_html(wabe: WabeSpec, index: int) -> str: | |
| enabled = "is-on" if wabe.enabled else "is-off" | |
| collapsed = "is-collapsed" if wabe.collapsed else "" | |
| prim_label = " · ".join(p.id for p in wabe.primitives[:3]) | |
| body = "" if wabe.collapsed else f'<div class="st-wabe__body">{_macro_controls(wabe)}</div>' | |
| return f""" | |
| <article class="st-wabe {enabled} {collapsed}" data-st-wabe="{escape(wabe.id)}" data-st-order="{index}" style="--i:{index}"> | |
| <header class="st-wabe__head"> | |
| <button type="button" class="st-wabe__toggle" data-st-toggle="{escape(wabe.id)}" aria-pressed="{str(wabe.enabled).lower()}" title="Bypass">{'●' if wabe.enabled else '○'}</button> | |
| <div class="st-wabe__title"> | |
| <strong>{escape(wabe.title)}</strong> | |
| <small>{escape(prim_label)}</small> | |
| </div> | |
| <div class="st-wabe__actions"> | |
| <button type="button" data-st-collapse="{escape(wabe.id)}" title="Ein-/Ausklappen">⬡</button> | |
| <button type="button" data-st-up="{escape(wabe.id)}" title="Nach oben">↑</button> | |
| <button type="button" data-st-down="{escape(wabe.id)}" title="Nach unten">↓</button> | |
| <button type="button" data-st-remove="{escape(wabe.id)}" title="Entfernen">✕</button> | |
| </div> | |
| </header> | |
| {body} | |
| </article> | |
| """ | |
| def honeycomb_html(waben: list[WabeSpec], analysis: dict[str, Any] | None = None) -> str: | |
| if not waben: | |
| return empty_state_html() | |
| cards = "".join(wabe_card_html(w, i) for i, w in enumerate(waben)) | |
| meter = "" | |
| if analysis: | |
| bits = [] | |
| if analysis.get("approx_lufs") is not None: | |
| bits.append(f"{float(analysis['approx_lufs']):.1f} LUFS") | |
| if analysis.get("peak_dbfs") is not None: | |
| bits.append(f"Peak {float(analysis['peak_dbfs']):.1f} dBFS") | |
| if analysis.get("bpm"): | |
| bits.append(f"≈ {int(analysis['bpm'])} BPM") | |
| if bits: | |
| meter = f'<div class="st-meter">{" · ".join(escape(b) for b in bits)}</div>' | |
| return f'<div class="st-hive" id="st-hive">{meter}<div class="st-waben">{cards}</div></div>' | |
| def chat_bubble_html(turns: list[dict[str, str]]) -> str: | |
| if not turns: | |
| return '<div class="st-chat" id="st-chat"><p class="st-chat__hint">3B wartet · eine Zeile für alles.</p></div>' | |
| parts = [] | |
| for turn in turns[-8:]: | |
| role = turn.get("role", "system") | |
| cls = "is-user" if role == "user" else "is-agent" | |
| who = "Du" if role == "user" else "3B" | |
| parts.append( | |
| f'<div class="st-chat__row {cls}"><span>{who}</span><p>{escape(turn.get("text", ""))}</p></div>' | |
| ) | |
| return f'<div class="st-chat" id="st-chat">{"".join(parts)}</div>' | |
| def selection_label(sel: dict[str, float] | None) -> str: | |
| if not sel: | |
| return "Kein Abschnitt markiert" | |
| return f"Abschnitt {sel.get('start_s', 0):.1f}s – {sel.get('end_s', 0):.1f}s" | |