Upload folder using huggingface_hub
Browse files- __pycache__/model.cpython-312.pyc +0 -0
- model.py +4 -3
- static/index.html +11 -5
__pycache__/model.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/model.cpython-312.pyc and b/__pycache__/model.cpython-312.pyc differ
|
|
|
model.py
CHANGED
|
@@ -71,7 +71,8 @@ DEMO = {
|
|
| 71 |
' .single("safety", ["safe", "unsafe"])\n'
|
| 72 |
' .multi("harm_category", [\n'
|
| 73 |
' "prompt_injection", "violence_and_weapons", "sexual_content",\n'
|
| 74 |
-
' "hate_and_discrimination", "privacy_violation", "misinformation"]
|
|
|
|
| 75 |
'joint = separate.constrain(\n'
|
| 76 |
' C.implies(C.any_selected("harm_category"), ("safety", "unsafe")),\n'
|
| 77 |
' C.implies(("safety", "unsafe"), C.any_selected("harm_category")))\n'
|
|
@@ -236,7 +237,7 @@ def _schema_separate():
|
|
| 236 |
from gliner2.classification import ClassificationSchema
|
| 237 |
return (ClassificationSchema()
|
| 238 |
.single("safety", SAFETY_LABELS)
|
| 239 |
-
.multi("harm_category", HARM_LABELS))
|
| 240 |
|
| 241 |
|
| 242 |
def _schema_joint(implies, mins):
|
|
@@ -249,7 +250,7 @@ def _schema_joint(implies, mins):
|
|
| 249 |
min_by_task = dict(mins)
|
| 250 |
s = (ClassificationSchema()
|
| 251 |
.single("safety", SAFETY_LABELS)
|
| 252 |
-
.multi("harm_category", HARM_LABELS,
|
| 253 |
min_labels=min_by_task.get("harm_category", 0))
|
| 254 |
.constrain(*[C.implies(expr(*cond), expr(*cons)) for cond, cons in implies]))
|
| 255 |
if min_by_task.get("safety", 0) > 0: # "at least one safety label" is vacuous (single task)
|
|
|
|
| 71 |
' .single("safety", ["safe", "unsafe"])\n'
|
| 72 |
' .multi("harm_category", [\n'
|
| 73 |
' "prompt_injection", "violence_and_weapons", "sexual_content",\n'
|
| 74 |
+
' "hate_and_discrimination", "privacy_violation", "misinformation"],\n'
|
| 75 |
+
' threshold=0.5))\n'
|
| 76 |
'joint = separate.constrain(\n'
|
| 77 |
' C.implies(C.any_selected("harm_category"), ("safety", "unsafe")),\n'
|
| 78 |
' C.implies(("safety", "unsafe"), C.any_selected("harm_category")))\n'
|
|
|
|
| 237 |
from gliner2.classification import ClassificationSchema
|
| 238 |
return (ClassificationSchema()
|
| 239 |
.single("safety", SAFETY_LABELS)
|
| 240 |
+
.multi("harm_category", HARM_LABELS, threshold=0.5))
|
| 241 |
|
| 242 |
|
| 243 |
def _schema_joint(implies, mins):
|
|
|
|
| 250 |
min_by_task = dict(mins)
|
| 251 |
s = (ClassificationSchema()
|
| 252 |
.single("safety", SAFETY_LABELS)
|
| 253 |
+
.multi("harm_category", HARM_LABELS, threshold=0.5,
|
| 254 |
min_labels=min_by_task.get("harm_category", 0))
|
| 255 |
.constrain(*[C.implies(expr(*cond), expr(*cons)) for cond, cons in implies]))
|
| 256 |
if min_by_task.get("safety", 0) > 0: # "at least one safety label" is vacuous (single task)
|
static/index.html
CHANGED
|
@@ -120,6 +120,9 @@
|
|
| 120 |
width: 158px; flex-shrink: 0;
|
| 121 |
font-family: var(--font-mono); font-size: 12px; font-weight: 400; color: var(--ink-faint);
|
| 122 |
}
|
|
|
|
|
|
|
|
|
|
| 123 |
.l-row.chosen .l-name { font-weight: 700; color: var(--span-color); }
|
| 124 |
.l-score { width: 34px; flex-shrink: 0; text-align: right; font-family: var(--font-mono); font-size: 11px; color: var(--ink-faint); }
|
| 125 |
.l-row.chosen .l-score { color: var(--ink-soft); }
|
|
@@ -323,10 +326,12 @@ $("add-rule").addEventListener("click", () => {
|
|
| 323 |
inferSoon(120);
|
| 324 |
});
|
| 325 |
|
| 326 |
-
/* semantic colors: safe = green, unsafe = red; harm labels
|
| 327 |
-
|
|
|
|
|
|
|
| 328 |
if (task === "safety") return label === "safe" ? "var(--ok)" : "var(--neg)";
|
| 329 |
-
return "var(--
|
| 330 |
}
|
| 331 |
|
| 332 |
/* one task section: every label gets its own row, name left, score+bar right,
|
|
@@ -337,8 +342,9 @@ function taskSection(task, probs, chosen, opts = {}) {
|
|
| 337 |
const rows = order.map((l) => {
|
| 338 |
const p = (probs || {})[l] || 0;
|
| 339 |
const on = chosenSet.has(l);
|
| 340 |
-
const
|
| 341 |
-
|
|
|
|
| 342 |
<span class="l-name">${esc(l)}</span>
|
| 343 |
<span class="l-score">${p.toFixed(2)}</span>
|
| 344 |
<span class="l-bar"><i data-w="${(p * 100).toFixed(1)}"></i></span>
|
|
|
|
| 120 |
width: 158px; flex-shrink: 0;
|
| 121 |
font-family: var(--font-mono); font-size: 12px; font-weight: 400; color: var(--ink-faint);
|
| 122 |
}
|
| 123 |
+
/* above the 0.5 threshold: purple, selected or not */
|
| 124 |
+
.l-row.hot .l-name { font-weight: 600; color: var(--purple); }
|
| 125 |
+
.l-row.hot .l-bar i { background: var(--purple); }
|
| 126 |
.l-row.chosen .l-name { font-weight: 700; color: var(--span-color); }
|
| 127 |
.l-score { width: 34px; flex-shrink: 0; text-align: right; font-family: var(--font-mono); font-size: 11px; color: var(--ink-faint); }
|
| 128 |
.l-row.chosen .l-score { color: var(--ink-soft); }
|
|
|
|
| 326 |
inferSoon(120);
|
| 327 |
});
|
| 328 |
|
| 329 |
+
/* semantic colors: safe = green, unsafe = red; harm labels purple when they
|
| 330 |
+
clear the 0.5 selection threshold (chosen or not), gray below it */
|
| 331 |
+
const HARM_THRESHOLD = 0.5;
|
| 332 |
+
function labelColor(task, label, p) {
|
| 333 |
if (task === "safety") return label === "safe" ? "var(--ok)" : "var(--neg)";
|
| 334 |
+
return p >= HARM_THRESHOLD ? "var(--purple)" : "var(--warm-gray)";
|
| 335 |
}
|
| 336 |
|
| 337 |
/* one task section: every label gets its own row, name left, score+bar right,
|
|
|
|
| 342 |
const rows = order.map((l) => {
|
| 343 |
const p = (probs || {})[l] || 0;
|
| 344 |
const on = chosenSet.has(l);
|
| 345 |
+
const hot = task === "harm_category" && p >= HARM_THRESHOLD;
|
| 346 |
+
const color = labelColor(task, l, p);
|
| 347 |
+
return `<div class="l-row${on ? " chosen" : ""}${hot ? " hot" : ""}" style="--span-color:${color}">
|
| 348 |
<span class="l-name">${esc(l)}</span>
|
| 349 |
<span class="l-score">${p.toFixed(2)}</span>
|
| 350 |
<span class="l-bar"><i data-w="${(p * 100).toFixed(1)}"></i></span>
|