"""Base120 Explorer: browse the 120 Base120 reasoning operators (snapshot of base120 3.1.0).""" import html import re import gradio as gr import pandas as pd from huggingface_hub import hf_hub_download DATASET = "hummbl-hf/base120" REVISION = "792d69f18da12e4235fb60fe76aa0d25e9e53cfc" # pinned dataset commit path = hf_hub_download(DATASET, "data/operators.parquet", repo_type="dataset", revision=REVISION) DF = pd.read_parquet(path).sort_values(["transformation", "index"]).reset_index(drop=True) FAMILIES = {"P": "Perspective", "IN": "Inversion", "CO": "Composition", "DE": "Decomposition", "RE": "Recursion", "SY": "Systems"} FAMILY_CHOICES = ["ALL"] + [f"{k} — {v}" for k, v in FAMILIES.items()] STOP = set("a an the and or of to in on for with is are be by as at from that this it into how what why".split()) def card(row) -> str: return (f"
No operators match.
" return f"{len(d)} operator(s)
" + cards def pick(problem: str, k: int): words = {w for w in re.findall(r"[a-z]+", (problem or "").lower()) if w not in STOP and len(w) > 2} if not words: return "Describe a problem in a sentence or two.
" stems = {w[:5] for w in words} def score(r): toks = {t[:5] for t in re.findall(r"[a-z]+", (r["name"] + " " + r["definition"]).lower()) if len(t) > 2} return len(stems & toks) d = DF.assign(score=DF.apply(score, axis=1)) d = d[d.score > 0].sort_values(["score", "code"], ascending=[False, True]).head(int(k)) if d.empty: return "No keyword overlap. Try other words, or browse by family.
" return ("Keyword overlap only (no AI model); a starting point, not a recommendation.
" + "".join(card(r) for _, r in d.iterrows())) def random_op(): return card(DF.sample(1).iloc[0]) with gr.Blocks(title="Base120 Explorer") as demo: gr.Markdown( "# Base120 Explorer\n" "120 named reasoning operators in 6 transformation families " "(**P** Perspective, **IN** Inversion, **CO** Composition, **DE** Decomposition, **RE** Recursion, **SY** Systems).\n\n" f"Data: [`{DATASET}`](https://huggingface.co/datasets/{DATASET}) at revision `{REVISION[:7]}`, " "a snapshot of the `base120` **3.1.0** PyPI package. Wording can differ slightly from other Base120 sources. " "These are reasoning heuristics, not validated methods.") with gr.Tab("Browse"): with gr.Row(): fam = gr.Dropdown(FAMILY_CHOICES, value="ALL", label="Family") q = gr.Textbox(label="Search name/definition") out = gr.HTML(browse("ALL", "")) fam.change(browse, [fam, q], out) q.change(browse, [fam, q], out) with gr.Tab("Keyword picker"): prob = gr.Textbox(label="Describe your problem", lines=3) k = gr.Slider(1, 15, value=6, step=1, label="How many") btn = gr.Button("Suggest operators") pout = gr.HTML() btn.click(pick, [prob, k], pout) with gr.Tab("Random"): rb = gr.Button("Random operator") rout = gr.HTML() rb.click(random_op, None, rout) if __name__ == "__main__": demo.launch()