Spaces:
Running on Zero
Running on Zero
feat(ui): preset_bar + status_banner components
Browse files
ui.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ui.py
|
| 2 |
+
"""Reusable Gradio components shared across modes."""
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import gradio as gr
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def preset_bar(label: str = "Preset") -> gr.Radio:
|
| 9 |
+
"""Fast / Balanced / Quality radio. Use as a single component."""
|
| 10 |
+
return gr.Radio(
|
| 11 |
+
choices=["Fast", "Balanced", "Quality"],
|
| 12 |
+
value="Balanced",
|
| 13 |
+
label=label,
|
| 14 |
+
container=True,
|
| 15 |
+
info="Fast: distilled 8 steps 路 Balanced: two-stage 30+4 路 Quality: HQ res_2s sampler",
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def status_banner() -> gr.HTML:
|
| 20 |
+
"""Status banner: stage chips + progress + memory."""
|
| 21 |
+
return gr.HTML(
|
| 22 |
+
value=_render_idle(),
|
| 23 |
+
elem_classes=["status-banner"],
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def _render_idle() -> str:
|
| 28 |
+
return (
|
| 29 |
+
'<div class="status-card status-idle">'
|
| 30 |
+
'<div class="status-row"><span class="status-dot"></span>'
|
| 31 |
+
'<span class="status-label">Idle</span></div></div>'
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def render_status(
|
| 36 |
+
stage_index: int,
|
| 37 |
+
stage_label: str,
|
| 38 |
+
step: int,
|
| 39 |
+
total_steps: int,
|
| 40 |
+
elapsed_s: float,
|
| 41 |
+
eta_s: float,
|
| 42 |
+
memory_text: str = "",
|
| 43 |
+
) -> str:
|
| 44 |
+
"""Render a status banner HTML string for the current event."""
|
| 45 |
+
pct = 0 if total_steps <= 0 else int(100 * step / total_steps)
|
| 46 |
+
return (
|
| 47 |
+
f'<div class="status-card">'
|
| 48 |
+
f' <div class="status-row">'
|
| 49 |
+
f' <span class="status-stage">Stage {stage_index} 路 {stage_label}</span>'
|
| 50 |
+
f' <span class="status-meta">Step {step}/{total_steps} 路 '
|
| 51 |
+
f' {_fmt_secs(elapsed_s)} elapsed 路 ~{_fmt_secs(eta_s)} remaining</span>'
|
| 52 |
+
f' </div>'
|
| 53 |
+
f' <div class="status-bar"><div class="status-fill" style="width:{pct}%"></div></div>'
|
| 54 |
+
f' <div class="status-mem">{memory_text}</div>'
|
| 55 |
+
f'</div>'
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def _fmt_secs(secs: float) -> str:
|
| 60 |
+
secs = int(max(0, secs))
|
| 61 |
+
if secs < 60:
|
| 62 |
+
return f"{secs}s"
|
| 63 |
+
return f"{secs // 60}m {secs % 60}s"
|