Spaces:
Running on Zero
Running on Zero
Upload folder using huggingface_hub
Browse files
app.py
CHANGED
|
@@ -679,13 +679,21 @@ def _refresh_futures(s: Session):
|
|
| 679 |
if s.probe is None or s.probe.history_ids is None: return
|
| 680 |
s.options = s.probe.generate_previews(s.width, s.preview_len)
|
| 681 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 682 |
def _refresh_after_step(s: Session):
|
| 683 |
_refresh_futures(s)
|
|
|
|
| 684 |
|
| 685 |
|
| 686 |
def initial_load(model_id: str, system_prompt: str, user_prompt: str, s: Session):
|
| 687 |
s.ensure(model_id=model_id, system_prompt=system_prompt or None, user_prompt=user_prompt or "")
|
| 688 |
_refresh_futures(s)
|
|
|
|
| 689 |
s.transcript.append(("(load)", f"loaded {s.probe.model_id} "
|
| 690 |
f"({s.probe.num_layers}LΓ{s.probe.num_heads}H)"))
|
| 691 |
return panes_html(s) + (status_html(s),)
|
|
@@ -694,12 +702,15 @@ def initial_load(model_id: str, system_prompt: str, user_prompt: str, s: Session
|
|
| 694 |
# ββ Gradio UI βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 695 |
CSS = """
|
| 696 |
.gradio-container { max-width: 100% !important; }
|
| 697 |
-
|
|
|
|
|
|
|
|
|
|
| 698 |
.pane { border: 1px solid #444; border-radius: 4px; background: #0d1117; color: #c9d1d9;
|
| 699 |
font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace; font-size: 12px; }
|
| 700 |
.pane h3 { margin: 0; padding: 4px 8px; background: #161b22; border-bottom: 1px solid #30363d;
|
| 701 |
font-size: 11px; letter-spacing: 0.5px; text-transform: uppercase; color: #8b949e; }
|
| 702 |
-
.pane-body { padding: 6px 8px; max-height:
|
| 703 |
.pane-body.scroll { overflow: auto; }
|
| 704 |
.dim { color: #6e7681; }
|
| 705 |
.context-text { white-space: pre-wrap; word-break: break-word; margin-top: 4px; }
|
|
@@ -736,41 +747,46 @@ HELP = """\
|
|
| 736 |
def build_ui():
|
| 737 |
with gr.Blocks(title="Cartogemma", css=CSS, theme=gr.themes.Base()) as demo:
|
| 738 |
gr.Markdown("# Cartogemma \n*Mechanistic probe (logit lens Β· head map Β· futures Β· rank sparkline) "
|
| 739 |
-
"
|
| 740 |
|
| 741 |
session = gr.State(Session())
|
| 742 |
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
|
| 754 |
muted_html = gr.HTML()
|
| 755 |
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
|
| 759 |
-
hm_pane = gr.HTML(label="Head Map", value="<div class='pane'><h3>Head Map "
|
| 760 |
-
"(pre-stream | xray | delta-v | L<sub>full</sub>)</h3>"
|
| 761 |
-
"<div class='pane-body'><i>Run <code>h *</code> after loading.</i></div></div>")
|
| 762 |
|
|
|
|
| 763 |
with gr.Row():
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 768 |
|
| 769 |
gr.Markdown(HELP)
|
| 770 |
|
| 771 |
with gr.Row():
|
| 772 |
cmd = gr.Textbox(label="CMD", placeholder="1-N | h * | top 1000,3,1 | spark the | mute 5 2 | β¦",
|
| 773 |
-
scale=8, autofocus=True)
|
| 774 |
run_btn = gr.Button("Run", scale=1, variant="primary")
|
| 775 |
|
| 776 |
status = gr.HTML(value="<div class='pane'><h3>Transcript</h3>"
|
|
|
|
| 679 |
if s.probe is None or s.probe.history_ids is None: return
|
| 680 |
s.options = s.probe.generate_previews(s.width, s.preview_len)
|
| 681 |
|
| 682 |
+
def _refresh_headmap(s: Session):
|
| 683 |
+
"""Always run full h * scan + xray after any step that mutates context."""
|
| 684 |
+
if s.probe is None or s.probe.history_ids is None: return
|
| 685 |
+
s.scan_data = s.probe.scan_heads(None, None)
|
| 686 |
+
s.xray = s.probe.perform_xray()
|
| 687 |
+
|
| 688 |
def _refresh_after_step(s: Session):
|
| 689 |
_refresh_futures(s)
|
| 690 |
+
_refresh_headmap(s)
|
| 691 |
|
| 692 |
|
| 693 |
def initial_load(model_id: str, system_prompt: str, user_prompt: str, s: Session):
|
| 694 |
s.ensure(model_id=model_id, system_prompt=system_prompt or None, user_prompt=user_prompt or "")
|
| 695 |
_refresh_futures(s)
|
| 696 |
+
_refresh_headmap(s)
|
| 697 |
s.transcript.append(("(load)", f"loaded {s.probe.model_id} "
|
| 698 |
f"({s.probe.num_layers}LΓ{s.probe.num_heads}H)"))
|
| 699 |
return panes_html(s) + (status_html(s),)
|
|
|
|
| 702 |
# ββ Gradio UI βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 703 |
CSS = """
|
| 704 |
.gradio-container { max-width: 100% !important; }
|
| 705 |
+
/* Compact top control row */
|
| 706 |
+
#topbar .gr-textbox textarea, #topbar .gr-textbox input { font-size: 12px !important; padding: 4px 6px !important; }
|
| 707 |
+
#topbar label { font-size: 11px !important; }
|
| 708 |
+
#topbar .gr-form { padding: 4px !important; }
|
| 709 |
.pane { border: 1px solid #444; border-radius: 4px; background: #0d1117; color: #c9d1d9;
|
| 710 |
font-family: 'JetBrains Mono', 'Fira Code', Consolas, monospace; font-size: 12px; }
|
| 711 |
.pane h3 { margin: 0; padding: 4px 8px; background: #161b22; border-bottom: 1px solid #30363d;
|
| 712 |
font-size: 11px; letter-spacing: 0.5px; text-transform: uppercase; color: #8b949e; }
|
| 713 |
+
.pane-body { padding: 6px 8px; max-height: 420px; overflow: auto; }
|
| 714 |
.pane-body.scroll { overflow: auto; }
|
| 715 |
.dim { color: #6e7681; }
|
| 716 |
.context-text { white-space: pre-wrap; word-break: break-word; margin-top: 4px; }
|
|
|
|
| 747 |
def build_ui():
|
| 748 |
with gr.Blocks(title="Cartogemma", css=CSS, theme=gr.themes.Base()) as demo:
|
| 749 |
gr.Markdown("# Cartogemma \n*Mechanistic probe (logit lens Β· head map Β· futures Β· rank sparkline) "
|
| 750 |
+
"on the Gemma-3 family. Layout faithful to `cartographer3.py`.*")
|
| 751 |
|
| 752 |
session = gr.State(Session())
|
| 753 |
|
| 754 |
+
# ββ Compact top bar: model | system | user | load ββ
|
| 755 |
+
with gr.Row(elem_id="topbar"):
|
| 756 |
+
model_id = gr.Textbox(value=DEFAULT_MODEL_ID, label="Model",
|
| 757 |
+
lines=1, max_lines=1, scale=3, container=True,
|
| 758 |
+
show_label=True)
|
| 759 |
+
system_prompt = gr.Textbox(label="System", value="",
|
| 760 |
+
lines=1, max_lines=3, scale=4, container=True)
|
| 761 |
+
user_prompt = gr.Textbox(label="User", value="",
|
| 762 |
+
lines=1, max_lines=3, scale=5, container=True)
|
| 763 |
+
load_btn = gr.Button("Load", variant="primary", scale=1, min_width=80)
|
| 764 |
|
| 765 |
muted_html = gr.HTML()
|
| 766 |
|
| 767 |
+
# ββ Context: full width ββ
|
| 768 |
+
ctx_pane = gr.HTML(value="<div class='pane'><h3>Context</h3>"
|
| 769 |
+
"<div class='pane-body'><i>Click <b>Load</b> to begin.</i></div></div>")
|
|
|
|
|
|
|
|
|
|
| 770 |
|
| 771 |
+
# ββ Futures + Head Map: side by side ββ
|
| 772 |
with gr.Row():
|
| 773 |
+
with gr.Column(scale=3, min_width=280):
|
| 774 |
+
fut_pane = gr.HTML(value="<div class='pane'><h3>Futures (top-k)</h3>"
|
| 775 |
+
"<div class='pane-body'><i>Top-k branches will appear here.</i></div></div>")
|
| 776 |
+
with gr.Column(scale=7):
|
| 777 |
+
hm_pane = gr.HTML(value="<div class='pane'><h3>Head Map "
|
| 778 |
+
"(pre-stream | xray | delta-v | L<sub>full</sub>)</h3>"
|
| 779 |
+
"<div class='pane-body'><i>Auto-runs after every step.</i></div></div>")
|
| 780 |
+
|
| 781 |
+
# ββ Sparkline: full width below ββ
|
| 782 |
+
spark_pane = gr.HTML(value="<div class='pane'><h3>Sparkline</h3>"
|
| 783 |
+
"<div class='pane-body'><i>Run <code>spark <token></code>.</i></div></div>")
|
| 784 |
|
| 785 |
gr.Markdown(HELP)
|
| 786 |
|
| 787 |
with gr.Row():
|
| 788 |
cmd = gr.Textbox(label="CMD", placeholder="1-N | h * | top 1000,3,1 | spark the | mute 5 2 | β¦",
|
| 789 |
+
scale=8, autofocus=True, lines=1, max_lines=1)
|
| 790 |
run_btn = gr.Button("Run", scale=1, variant="primary")
|
| 791 |
|
| 792 |
status = gr.HTML(value="<div class='pane'><h3>Transcript</h3>"
|