"""Demo console (#17, ADR-004/005): web chat of the patient, demo clock and scenario playback. Everything goes through the HTTP API (`API_BASE_URL`); the page keeps working when the backend serves fixtures. """ import sys from pathlib import Path import streamlit as st # `streamlit run dashboard/app.py` already puts dashboard/ on sys.path; this keeps the page runnable on its own. sys.path.insert(0, str(Path(__file__).resolve().parents[1])) from console import widgets as w # noqa: E402 from console.playback_ui import render_playback_panel # noqa: E402 from dashboard import theme # noqa: E402 from dashboard.components import ui # noqa: E402 st.set_page_config(page_title="Демо-консоль", page_icon="🎬", layout="wide") st.html(theme.CSS) st.html( ui.page_header( "Демо-консоль", "Чат пациента и сценарий сопровождения. Прототип на синтетических данных.", kicker="Демонстрация", ) ) persona = w.select_persona() w.render_connect_hero() w.show_flash() st.sidebar.caption(f"API: {w.get_api().base_url}") # One switch for the presentation: initial questionnaires after consent on/off (off → straight to the chat). try: _screening = bool(w.get_api().demo_settings().get("screening_enabled", True)) _wanted = st.sidebar.toggle( "Начальный тест (скрининг)", value=_screening, help="Выключено: после согласия пациент сразу попадает в чат, без опросников.", ) if _wanted != _screening: w.get_api().set_screening(_wanted) st.sidebar.success("Начальный тест " + ("включён" if _wanted else "выключен")) except Exception: # noqa: BLE001 — the switch must never break the console st.sidebar.caption("Переключатель теста недоступен (API)") with st.container(border=True, key="panel-console-clock"): w.render_clock_bar(persona, key="console-clock") chat_col, play_col = st.columns([1.05, 1], gap="large") with chat_col, st.container(border=True, key="panel-console-chat"): st.subheader(f"Чат пациента — {persona.get('display_name') or persona['token']}") w.render_chat(persona["token"], height=560, key="console-chat") with play_col, st.container(border=True, key="panel-console-scenario"): render_playback_panel(persona)