""" Cognitive Skills Engine — Hugging Face Space Gradio demo: interactive Cognition Board + skill injection """ import gradio as gr import os import pathlib REPO_ROOT = pathlib.Path(__file__).parent.parent BOARD = { "A1": ("TC", "Token Compression", "core/token-compression.md"), "A2": ("MM", "Mathematician", "science/mathematician-mind.md"), "A3": ("PH", "Physicist", "science/physicist-mind.md"), "A4": ("CH", "Chemist", "science/chemist-mind.md"), "A5": ("BIO", "Biologist", "science/biologist-mind.md"), "A6": ("CS", "Computer Scientist", "science/computer-scientist-mind.md"), "B1": ("HIS", "Historian", "humanities/historian-mind.md"), "B2": ("PHI", "Philosopher", "humanities/philosopher-mind.md"), "B3": ("PSY", "Psychologist", "humanities/psychologist-mind.md"), "B4": ("LIN", "Linguist", "humanities/linguist-mind.md"), "B5": ("GEO", "Geographer", "humanities/geographer-mind.md"), "B6": ("ECO", "Economist", "humanities/economist-mind.md"), "C1": ("POL", "Political Scientist", "humanities/political-scientist-mind.md"), "C2": ("LAW", "Jurist", "humanities/jurist-mind.md"), "C3": ("MED", "Medical Expert", "science/medical-mind.md"), "C4": ("AST", "Astronomer", "science/astronomer-mind.md"), "C5": ("ENG", "Engineer", "science/engineer-mind.md"), "C6": ("ART", "Arts Expert", "arts-culture/arts-mind.md"), "D1": ("ENV", "Environmentalist", "arts-culture/environmental-mind.md"), "D2": ("CUL", "Cultural Anthropologist", "arts-culture/culture-mind.md"), "D5": ("MST★", "Master Router", "../MASTER-SKILL.md"), } KEYWORDS = { "A2": ["math","proof","theorem","algebra","geometry","calculus","number theory","combinatorics"], "A3": ["physics","quantum","relativity","force","energy","wave","field","mechanics","thermodynamics"], "A4": ["chemistry","molecule","reaction","organic","acid","base","synthesis","compound","bond"], "A5": ["biology","gene","cell","evolution","protein","DNA","RNA","ecology","species"], "A6": ["code","algorithm","complexity","software","program","debug","data structure","machine learning","AI"], "B1": ["history","historical","century","civilization","war","empire","dynasty","revolution","ancient"], "B2": ["philosophy","ethics","logic","mind","consciousness","metaphysics","epistemology","moral","ontology"], "B3": ["psychology","behavior","cognitive","mental","therapy","emotion","personality","memory","perception"], "B4": ["language","grammar","syntax","linguistics","meaning","phonology","morphology","semantics","discourse"], "B5": ["geography","map","climate","spatial","territory","region","landform","migration","urban"], "B6": ["economics","market","trade","gdp","finance","price","supply","demand","monetary","fiscal"], "C1": ["politics","government","policy","democracy","power","state","election","party","governance"], "C2": ["law","legal","rights","court","justice","contract","statute","constitution","crime"], "C3": ["medicine","diagnosis","treatment","disease","clinical","symptom","drug","patient","therapy"], "C4": ["astronomy","star","galaxy","cosmology","universe","planet","black hole","telescope","orbit"], "C5": ["engineering","design","structure","system","circuit","material","mechanics","control","thermal"], "C6": ["art","music","aesthetic","culture","creative","literature","painting","architecture","film"], "D1": ["environment","climate change","ecology","biodiversity","carbon","ecosystem","species","pollution"], "D2": ["culture","anthropology","society","ritual","myth","identity","tradition","ethnography"], } def load_skill(code: str) -> str: if code not in BOARD: return f"# Cell {code} not found" _, _, path = BOARD[code] full = REPO_ROOT / "skills" / path if full.exists(): return full.read_text(encoding="utf-8") master = REPO_ROOT / "MASTER-SKILL.md" if code == "D5" and master.exists(): return master.read_text(encoding="utf-8") return f"# {code} skill content\n(File not found at {full})" def auto_route(task: str) -> list[str]: task_l = task.lower() path = ["D5", "A1"] for code, kws in KEYWORDS.items(): if any(kw in task_l for kw in kws): path.append(code) sci = [c for c in path if c[0] in ("A","C")] hum = [c for c in path if c[0] == "B"] if len(sci) > 2 and "D3" not in path: path.append("D3") if len(hum) > 2 and "D4" not in path: path.append("D4") path.append("D6") return path def route_and_build(task: str): if not task.strip(): return "Enter a task above.", "D5·A1·D6" path = auto_route(task) cells = [c for c in path if c not in ("D5","D6")] content_parts = [f"# COGNITIVE SKILLS ENGINE — Routed to: {' + '.join(path)}\n"] for c in cells: content_parts.append(load_skill(c)) content_parts.append("\n---\n") path_str = "·".join(path) content_parts.append(f"\nPATH: {path_str}") return "\n".join(content_parts), path_str def inject_cell(code: str): if not code: return "Select a cell code", "D5·A1·D6" content = "# Token Compression [A1]\n" + load_skill("A1") + "\n---\n" if code != "A1": content += f"# {code} — {BOARD.get(code, ('?','?','?'))[1]}\n" content += load_skill(code) content += f"\n\nPATH: D5·A1·{code}·D6" return content, f"D5·A1·{code}·D6" BOARD_HTML = """