from __future__ import annotations import gradio as gr from core.ontology import axis_options from core.route import Step1Result PATH_MESSAGE = "Describe your question" PATH_CHIPS = "Select from framework" def make_path_radio() -> gr.Radio: return gr.Radio( choices=[PATH_MESSAGE, PATH_CHIPS], value=PATH_MESSAGE, label="How do you want to start?", ) def _labels(axis: str, in_scope_only: bool = False) -> list[str]: items = axis_options()[axis] return [o["label"] for o in items if (o["in_scope"] or not in_scope_only)] def make_sector_group() -> gr.CheckboxGroup: return gr.CheckboxGroup( choices=_labels("sectors", in_scope_only=True), label="Sectors — indicator catalog available", ) def make_sector_group_no_catalog() -> gr.CheckboxGroup: oos = [o["label"] for o in axis_options()["sectors"] if not o["in_scope"]] return gr.CheckboxGroup( choices=oos, label="Other sectors — no indicator catalog (Step 2 finds nothing)", ) def make_lens_group() -> gr.CheckboxGroup: return gr.CheckboxGroup(choices=_labels("lens"), label="Lens (2D pillar) — optional") def make_type_group() -> gr.CheckboxGroup: return gr.CheckboxGroup(choices=_labels("type"), label="Type (1D pillar) — optional") def render_route_summary(res: Step1Result) -> str: """Pure markdown render of a resolved Step-1 route.""" all_sectors = res.in_scope + res.out_of_scope lines = ["### Step 1 — Route", ""] lines.append("**Sectors:** " + (", ".join(all_sectors) or "—")) lines.append("**Lens:** " + (", ".join(res.route.lens) or "—")) lines.append("**Type:** " + (", ".join(res.route.type) or "—")) if res.out_of_scope: lines += [ "", "> ℹ️ Outside catalog (WASH / Food Security / Shelter): " + ", ".join(res.out_of_scope) + " — Step 2 will show no indicators for these.", ] return "\n".join(lines)