example rail: buttons labelled by attack type down the left side
Browse filesFiles changed (3)
- README.md+18-9
- app.py+46-18
- examples/manifest.jsonAdded+15
35 unmodified lines36373839404142434445464748495035 unmodified lines## The examplesThirteen example documents ship with the Space — **one per injection family, plus one cleancontrol** — taken from the generation repo. Click one and it loads into the uploader.They are named `Example_0` … `Example_12` and nothing else. The model never sees a filename (itreads only extracted text), but `javascript_injection_WICAR_0470.pdf` would tell the *person* theanswer before they pressed anything, and a demo that announces its own result proves nothing. Twofurther precautions: the numbering is shuffled with a fixed seed so the order carries noinformation, and every file sits in a **12–15 KB band** so that file size does not quietly revealwhich one is the clean control — an earlier draft had the clean file at 3 KB against 200 KB+injected ones, which gave it away completely.Being small also matters practically: each example produces 2–8 regions, so **every one fits in asingle batch** — one example is one GPU run covering the whole document.35 unmodified lines36373839404142434445464748495051525354555657585935 unmodified lines## The examplesThirteen example documents ship with the Space — **one per injection family, plus one cleancontrol** — taken from the generation repo. They appear as a rail of buttons down the left edge,labelled by attack type: press **ransomware simulation** and that document loads into the uploaderand is triaged exactly as an uploaded file would be. There is no separate code path for examplesand nothing about them is pre-computed.**The files themselves stay anonymous.** On disk they are `Example_0` … `Example_12`, so theuploader shows a neutral filename and the document never announces its own answer. The buttons arelabelled because a demo you can drive deliberately is more useful than a guessing game — and itcosts nothing on the model side, since a filename never reaches the prompt. Only extracted textdoes.Two further precautions on the files: the numbering is shuffled with a fixed seed so `Example_0`is not simply the alphabetically-first family, and every file sits in a **12–15 KB band** so filesize does not reveal which one is the clean control. An earlier draft had the clean file at 3 KBagainst 200 KB+ injected ones, which gave it away completely.Button labels are read from `examples/manifest.json`, written by the same script that copies thePDFs — so a button cannot end up pointing at the wrong family.Being small also matters practically: each example produces 2–8 regions, so **every one fits in asingle batch** — one example is one GPU run covering the whole document.
111 unmodified lines112113114115116117118119120121122123124125126127292 unmodified lines42042142242342442542642742842943043143243343443530 unmodified lines4664674684694704714726 unmodified lines479480481482483484111 unmodified lines# One example per injection family, plus one clean control, taken from the generation repo.## They are named Example_N and nothing else. The model never sees a filename - it reads only the# extracted text - but `javascript_injection_WICAR_0001.pdf` would tell the *person* the answer# before they pressed anything, which makes the demo prove nothing. `examples/Example_Key.txt`# holds the mapping for whoever is marking this.## They are also all within 190-236 KB, so file size does not leak which one is the clean control# either. Sorted numerically rather than lexically, or Example_10 would sit between 1 and 2.EXAMPLE_DIR = Path(__file__).resolve().parent / "examples"EXAMPLES = sorted(EXAMPLE_DIR.glob("Example_*.pdf"),key=lambda p: int(p.stem.rsplit("_", 1)[1]))def fmt_eta(n: int, runtime: str = None) -> str:292 unmodified linesstate = gr.State()with gr.Row():with gr.Column(scale=1):pdf = gr.File(label="PDF", file_types=[".pdf"], type="filepath")if EXAMPLES:# cache_examples=False is not optional here: caching makes Gradio run the whole# scan for every example at startup, which would burn the entire day's ZeroGPU# quota before anyone opened the page - and time out the build doing it.gr.Examples(examples=[[str(p)] for p in EXAMPLES], inputs=[pdf],label="Or try an example (12 injection types + 1 clean, unlabelled)",examples_per_page=len(EXAMPLES), cache_examples=False)# Offered rather than decided, because the GPU here is the scarce resource: a free# account gets ~5 minutes of ZeroGPU a day and one batch reserves most of a run. The# CPU path is ~30x slower and has no quota at all, which makes it the right answer30 unmodified linesgo = gr.Button("Check this batch", variant="primary")plan = gr.Markdown("Upload a PDF to see what will be read.")with gr.Column(scale=2):with gr.Tab("Report"):report = gr.Markdown()with gr.Tab("Regions read"):6 unmodified linesraw = gr.Textbox(lines=22, interactive=False,label="The prompt route and untouched generation per region")inputs = [pdf, per_batch, sweep, runtime_pick]for ev in (pdf.change, per_batch.change, sweep.change, runtime_pick.change):ev(on_upload, inputs, [state, plan, batch_pick])111 unmodified lines112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144292 unmodified lines43743843944044144244344444544644744844945045145245345445545645730 unmodified lines4884894904914924934946 unmodified lines501502503504505506507508509510511512111 unmodified lines# One example per injection family, plus one clean control, taken from the generation repo.## The files on disk are named Example_N and nothing else, and that stays true: the uploader shows# a neutral filename, and nothing about the file announces its own answer. The *buttons* are# labelled by family so the demo can be driven deliberately ("show me ransomware"), which costs# nothing on the model side - a filename never reaches the prompt, only extracted text does.## Labels come from `examples/manifest.json`, written by the same script that copies the PDFs, so# a button cannot end up pointing at the wrong family. `examples/Example_Key.txt` is the same# mapping in prose, for whoever is marking this.EXAMPLE_DIR = Path(__file__).resolve().parent / "examples"def load_examples():"""[(label, path)], families first in the model's own order, clean last. Empty if absent."""manifest = EXAMPLE_DIR / "manifest.json"if not manifest.exists():return []import jsonmapping = json.loads(manifest.read_text(encoding="utf-8"))order = {f: i for i, f in enumerate(mimo.FAMILIES)}rows = [(fam, EXAMPLE_DIR / name) for name, fam in mapping.items()if (EXAMPLE_DIR / name).exists()]# "clean" is not in FAMILIES, so it sorts last - which is where it belongs: it is the control,# read after you have seen what a hit looks like.return sorted(rows, key=lambda r: order.get(r[0], len(order)))EXAMPLES = load_examples()def fmt_eta(n: int, runtime: str = None) -> str:292 unmodified linesstate = gr.State()with gr.Row():# The example rail, down the left edge. Plain buttons rather than `gr.Examples`: the# built-in renders a horizontal table of filenames, and what is wanted here is one# labelled tab per attack type that loads its document on click. Buttons also sidestep# `gr.Examples`' caching, which would run a full scan of all thirteen files at startup# and spend the whole day's ZeroGPU quota before anyone opened the page.with gr.Column(scale=1, min_width=170):if EXAMPLES:gr.Markdown("### Examples\nOne document per attack type.")example_buttons = [(gr.Button(label.replace("_", " "), size="sm"), path)for label, path in EXAMPLES]else:example_buttons = []with gr.Column(scale=2):pdf = gr.File(label="PDF", file_types=[".pdf"], type="filepath")# Offered rather than decided, because the GPU here is the scarce resource: a free# account gets ~5 minutes of ZeroGPU a day and one batch reserves most of a run. The# CPU path is ~30x slower and has no quota at all, which makes it the right answer30 unmodified linesgo = gr.Button("Check this batch", variant="primary")plan = gr.Markdown("Upload a PDF to see what will be read.")with gr.Column(scale=4):with gr.Tab("Report"):report = gr.Markdown()with gr.Tab("Regions read"):6 unmodified linesraw = gr.Textbox(lines=22, interactive=False,label="The prompt route and untouched generation per region")# Each example button just drops its path into the file component. That fires `pdf.change`# below, so an example goes through exactly the same triage as a real upload - there is no# second code path for demo files, and nothing about an example is pre-computed.for button, path in example_buttons:button.click(lambda p=str(path): p, None, pdf)inputs = [pdf, per_batch, sweep, runtime_pick]for ev in (pdf.change, per_batch.change, sweep.change, runtime_pick.change):ev(on_upload, inputs, [state, plan, batch_pick])
123456789101112131415{
"Example_0.pdf": "clean",
"Example_1.pdf": "object_action_injection",
"Example_2.pdf": "ssrf",
"Example_3.pdf": "dde_template_injection",
"Example_4.pdf": "xfa_acroform_injection",
"Example_5.pdf": "ransomware_simulation",
"Example_6.pdf": "shellcode_embedded_exe",
"Example_7.pdf": "cross_site_scripting",
"Example_8.pdf": "polyglot_file",
"Example_9.pdf": "steganographic_payload",
"Example_10.pdf": "uri_redirect_phishing",
"Example_11.pdf": "javascript_injection",
"Example_12.pdf": "llm_prompt_injection"
}README.md+18-9
app.py+46-18
examples/manifest.jsonAdded+15