from __future__ import annotations from collections.abc import Iterable import streamlit as st CSS = """ """ def inject_css() -> None: """Inject static CSS only; do not interpolate user or dataset values into this markup.""" st.markdown(CSS, unsafe_allow_html=True) def badge(text: str, kind: str = "info") -> str: """Return a plain-text badge label for native Streamlit rendering.""" prefix = { "good": "✅", "warn": "⚠️", "bad": "🚨", "info": "ℹ️", }.get(kind, "•") return f"{prefix} {text}" def hero(title: str, subtitle: str, badges: Iterable[str] | None = None) -> None: st.title(title) st.markdown(subtitle) if badges: st.caption(" · ".join(str(item) for item in badges)) st.divider() def decision_strip(items: list[tuple[str, str, str]]) -> None: """Render the decision brief with native Streamlit elements. This keeps the decision brief stable across Streamlit versions. """ st.subheader("Decision brief") cols = st.columns(len(items)) for col, (label, value, hint) in zip(cols, items, strict=False): with col: with st.container(border=True): st.caption(label) st.markdown(f"**{value}**") st.caption(hint) def metric_card(label: str, value: str, caption: str, status: str = "info") -> None: st.metric(label=label, value=value) st.caption(f"{status.title()} · {caption}") def status_kind(status: str) -> str: s = status.lower() if any(x in s for x in ["stable", "good", "healthy", "pass"]): return "good" if any(x in s for x in ["risk", "high", "bad", "fail"]): return "bad" if any(x in s for x in ["watch", "review", "warn"]): return "warn" return "info" def section_title(title: str, subtitle: str = "", chip: str = "") -> None: label = f" — {chip}" if chip else "" st.markdown(f"## {title}{label}") if subtitle: st.caption(subtitle) def callout(kind: str, title: str, body: str) -> None: text = f"**{title}**\n\n{body}" if kind in {"good", "success", "pass"}: st.success(text) elif kind in {"warn", "warning", "review"}: st.warning(text) elif kind in {"bad", "error", "risk", "fail"}: st.error(text) else: st.info(text) def trace_box(title: str, body: str) -> None: with st.container(border=True): st.markdown(f"**{title}**") st.write(body)