Download app.js from Project-Bastion/attack-technique-tagger-demo: direct link, hf CLI and curl.
- Browser
- Download file 1.67 kB
-
https://huggingface.co/spaces/Project-Bastion/attack-technique-tagger-demo/resolve/main/app.js
- Command line
-
hf download hf://spaces/Project-Bastion/attack-technique-tagger-demo/app.js
-
curl -L -o app.js https://huggingface.co/spaces/Project-Bastion/attack-technique-tagger-demo/resolve/main/app.js
1.67 kB
| import { tagReport } from "./tagger.js"; | |
| const CDN = "https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.3.2", MODEL = "Project-Bastion/attack-technique-tagger"; | |
| const $ = (id) => document.getElementById(id); let cache = {}; | |
| $("go").onclick = async () => { | |
| const dtype = $("dtype").value; $("go").disabled = true; | |
| try { | |
| if (!cache[dtype]) { | |
| $("status").textContent = " loading model (first time only)..."; | |
| const T = await import(CDN); const cb = (p) => { if (p.status === "progress") $("status").textContent = ` downloading ${p.file || ""} ${Math.round(p.progress || 0)}%`; }; | |
| cache[dtype] = { T, tok: await T.AutoTokenizer.from_pretrained(MODEL, { progress_callback: cb }), model: await T.AutoModelForSequenceClassification.from_pretrained(MODEL, { dtype, progress_callback: cb }) }; | |
| } | |
| $("status").textContent = " running locally..."; | |
| const res = await tagReport($("inp").value, cache[dtype].tok, cache[dtype].model, undefined, cache[dtype].T.Tensor); | |
| const tb = $("tbl").querySelector("tbody"); tb.innerHTML = ""; | |
| res.forEach((r, i) => { | |
| const tr = document.createElement("tr"); const td = (n) => tr.appendChild(document.createElement("td")); td().textContent = i + 1; td().textContent = r.sentence; | |
| const c = td(); r.hits.forEach((h) => { const s = document.createElement("span"); s.className = "t"; s.textContent = `${h.technique} ${h.prob.toFixed(2)}`; c.appendChild(s); }); if (!r.hits.length) c.textContent = "-"; tb.appendChild(tr); | |
| }); | |
| $("status").textContent = " done"; | |
| } catch (e) { $("status").textContent = " error: " + e.message; console.error(e); } | |
| $("go").disabled = false; | |
| }; | |