"""Futuristic theme injection for Streamlit.""" import streamlit as st from pathlib import Path THEME_MODES = ("black", "white") def get_theme_mode() -> str: """Read the active theme from session state. Defaults to ``"black"``.""" mode = st.session_state.get("ui_theme_mode", "black") return mode if mode in THEME_MODES else "black" def set_theme_mode(mode: str) -> None: """Set the active theme. Use ``"black"`` for pure-black background, ``"white"`` for pure-white background. Anything else is normalized.""" st.session_state["ui_theme_mode"] = mode if mode in THEME_MODES else "black" def inject_theme(mode: str | None = None): """Inject custom CSS for the chosen theme and hide Streamlit chrome. When ``mode`` is ``None`` we read the active mode from session state via :func:`get_theme_mode`. The base ``assets/theme.css`` is always included; theme-specific overrides are appended on top. """ if mode is None: mode = get_theme_mode() base_css_path = Path(__file__).parent / "assets" / "theme.css" overlay_css_path = Path(__file__).parent / "assets" / f"theme_{mode}.css" css = base_css_path.read_text() if base_css_path.exists() else "" if overlay_css_path.exists(): css += "\n\n" + overlay_css_path.read_text() st.markdown(f"", unsafe_allow_html=True) def hero_header(title, subtitle="", github_url="https://github.com/siddhant-rajhans/cortexlab"): """Render a futuristic hero header with gradient title.""" st.markdown(f"""

{title}

{subtitle}

GitHub HuggingFace Live Demo
""", unsafe_allow_html=True) def glow_card(title, value, subtitle="", color="#06B6D4"): """Render a glowing metric card. Layout uses the ``cl-stat-card`` CSS class so background / border / text colors come from theme variables and flip automatically when the user switches between Black and White modes. Only the accent color (the big number) stays per-card. """ st.markdown( f"""
{title}
{value}
{subtitle}
""", unsafe_allow_html=True, ) def section_header(title, description=""): """Render a styled section header with optional description. Colors come from theme variables (``--text-primary`` for the title, ``--text-secondary`` for the description, ``--border-glass`` for the underline) so the same markup reads correctly on dark and light backgrounds. """ desc_html = ( f'

{description}

' if description else "" ) st.markdown( f"""

{title}

{desc_html}
""", unsafe_allow_html=True, ) _FEATURE_ICONS: dict[str, str] = { # Heroicons-style monochrome strokes; small currentColor SVGs so the # accent color flows from the parent `--card-accent` variable. "target": ( '' ), "bars": ( '' ), "clock": ( '' ), "graph": ( '' ), "brain": ( '' ), "broadcast": ( '' ), "arrow": ( '' ), } def feature_icon(name: str) -> str: """Return inline SVG markup for a named card icon. Unknown names fall back to a hollow circle so layout still works.""" return _FEATURE_ICONS.get( name, '', ) def feature_card(icon, title, description, color="#7C3AED"): """Render a feature card for the home page (no inline CTA). Kept for backwards compatibility. New callers should prefer :func:`feature_card_link` which produces a uniform-height card with a built-in "Open ..." link, so a row of cards lines up. ``icon`` may be either a name registered in ``_FEATURE_ICONS`` (e.g. ``"target"``) or raw SVG / HTML markup. """ icon_html = _FEATURE_ICONS.get(icon, icon) return f""" {icon_html} {title} {description} """ def feature_card_link(icon, title, description, href: str, color="#7C3AED"): """Render a feature card as a single clickable anchor element. Inner blocks are rendered as ```` elements with ``display: block`` in CSS — anchors only allow phrasing-content children in HTML5, and Streamlit's HTML sanitizer hoists ``
`` children out of ````, splitting the card visually. Spans are safe. ``icon`` may be either a name registered in ``_FEATURE_ICONS`` (``"target"``, ``"bars"``, ``"clock"``, ``"graph"``, ``"brain"``, ``"broadcast"``) or raw SVG markup. ``href`` is the multipage URL Streamlit exposes (e.g. ``./Brain_Alignment``). """ icon_html = _FEATURE_ICONS.get(icon, icon) arrow = _FEATURE_ICONS["arrow"] return f""" {icon_html} {title} {description} Open {arrow} """