Spaces:
Running
Running
Download lab.js from Giuliocc/tacitus-source-lab: direct link, hf CLI and curl.
- Browser
- Download file 2.22 kB
-
https://huggingface.co/spaces/Giuliocc/tacitus-source-lab/resolve/main/lab.js
- Command line
-
hf download hf://spaces/Giuliocc/tacitus-source-lab/lab.js
-
curl -L -o lab.js https://huggingface.co/spaces/Giuliocc/tacitus-source-lab/resolve/main/lab.js
2.22 kB
| const buttons = [...document.querySelectorAll("[data-task]")]; | |
| let current; | |
| function render(task) { | |
| current = window.tacitusExamples[task]; | |
| const { text, claim, result } = current; | |
| for (const button of buttons) button.setAttribute("aria-pressed", button.dataset.task === task); | |
| const spans = result.mentions ?? result.events?.map(event => event.trigger) ?? []; | |
| const codepoints = Array.from(text); | |
| const bounds = [...new Set([0, codepoints.length, ...spans.flatMap(span => [span.start, span.end])])].sort((a, b) => a - b); | |
| const source = document.querySelector("#source"); | |
| source.replaceChildren(); | |
| for (let i = 1; i < bounds.length; i++) { | |
| const left = bounds[i - 1]; | |
| const right = bounds[i]; | |
| const segment = codepoints.slice(left, right).join(""); | |
| const matches = spans.filter(span => span.start <= left && span.end >= right); | |
| if (matches.length === 0) { | |
| source.append(segment); | |
| continue; | |
| } | |
| const mark = document.createElement("mark"); | |
| mark.textContent = segment; | |
| mark.title = matches.map(span => span.type).join(", "); | |
| source.append(mark); | |
| } | |
| document.querySelector("#summary").textContent = task === "evidence" | |
| ? result.verdict.replaceAll("_", " ") | |
| : `${spans.length} ${task === "events" ? "proposed event triggers" : "detected actor mentions"}`; | |
| document.querySelector("#revision").textContent = `${result.model_id}@${result.model_revision} · Schema ${result.schema_version}`; | |
| document.querySelector("#claim").textContent = claim ? `Claim under review — ${claim}` : ""; | |
| document.querySelector("#warning").textContent = result.warnings.join(" "); | |
| document.querySelector("#json").textContent = JSON.stringify(result, null, 2); | |
| } | |
| for (const button of buttons) button.addEventListener("click", () => render(button.dataset.task)); | |
| document.querySelector("#download").addEventListener("click", () => { | |
| const url = URL.createObjectURL(new Blob([JSON.stringify(current.result, null, 2)], { type: "application/json" })); | |
| const link = document.createElement("a"); | |
| link.download = `tacitus-${current.result.task}.json`; | |
| link.href = url; | |
| link.click(); | |
| setTimeout(() => URL.revokeObjectURL(url), 1000); | |
| }); | |
| render("evidence"); | |