trohrbaugh commited on
Commit
a55c5d2
Β·
verified Β·
1 Parent(s): 649bd46

Wave 1: provenance risk score (DNA-001) + engine panel (DNA-003)

Browse files
Files changed (2) hide show
  1. app.py +20 -9
  2. scan.py +55 -0
app.py CHANGED
@@ -113,6 +113,11 @@ def format_verdict(result: dict) -> tuple[str, str, str]:
113
  # Header
114
  confidence_emoji = {"HIGH": "βœ…", "MODERATE": "⚠️", "ORIGINAL": "🧬", "NONE": "❓"}.get(v.get("confidence",""), "❓")
115
  header = f"{confidence_emoji} **{v.get('architecture', 'Unknown')}**"
 
 
 
 
 
116
  header += f"\n\n*Scanned in {result.get('elapsed_s', '?')}s Β· Stage 1 (config-only)*"
117
  header += f"\n\nπŸ“₯ {m.get('downloads',0):,} downloads Β· πŸ‘ {m.get('likes',0)} likes"
118
 
@@ -133,18 +138,21 @@ def format_verdict(result: dict) -> tuple[str, str, str]:
133
  for s in e["modelatlas_similar"][:3]:
134
  details += f"- `{s['model_id']}`\n"
135
 
136
- # Flags
137
- flag_text = ""
138
- if flags:
139
- flag_text = f"### ⚠️ {len(flags)} Flag(s) Found\n\n"
140
- for f in flags:
141
- flag_text += f"**[{f['type']}]**\n\n{f['explanation']}\n\n---\n\n"
142
- else:
143
- flag_text = "### βœ… No Flags\n\nNo suspicious claims detected in model name or metadata."
144
 
145
  return header, details, flag_text
146
 
147
 
 
 
 
 
 
 
 
 
 
148
  def _fmt_flags(flags: list) -> str:
149
  if not flags:
150
  return "### βœ… No Flags\n\nNo suspicious claims detected in model name or metadata."
@@ -180,12 +188,15 @@ def format_inspection(result: dict) -> tuple[str, str, str, str]:
180
  v = result.get("verdict", {}); ev = result.get("evidence", {})
181
  header = (f"πŸ“¦ **GGUF metadata inspection** β€” {v.get('architecture','')}\n\n"
182
  "*Read from the GGUF header only β€” no weights downloaded.*")
 
 
 
183
  details = ("### GGUF header\n"
184
  f"- **name:** {ev.get('gguf_general.name')}\n"
185
  f"- **architecture:** `{ev.get('gguf_architecture')}`\n"
186
  f"- **chat template present:** {ev.get('chat_template_present')}\n"
187
  f"- **file:** `{result.get('gguf_file')}`\n")
188
- return header, details, _fmt_flags(v.get("flags", [])), ""
189
 
190
 
191
  def inspect_action(gguf_id: str):
 
113
  # Header
114
  confidence_emoji = {"HIGH": "βœ…", "MODERATE": "⚠️", "ORIGINAL": "🧬", "NONE": "❓"}.get(v.get("confidence",""), "❓")
115
  header = f"{confidence_emoji} **{v.get('architecture', 'Unknown')}**"
116
+ # DNA-001: provenance risk score gauge
117
+ if "risk_score" in v:
118
+ band = v.get("risk_band", "")
119
+ be = {"CLEAN": "🟒", "LOW": "🟑", "MODERATE": "🟠", "HIGH": "πŸ”΄"}.get(band, "βšͺ")
120
+ header += f"\n\n### {be} Provenance Risk: {v['risk_score']}/100 Β· {band}"
121
  header += f"\n\n*Scanned in {result.get('elapsed_s', '?')}s Β· Stage 1 (config-only)*"
122
  header += f"\n\nπŸ“₯ {m.get('downloads',0):,} downloads Β· πŸ‘ {m.get('likes',0)} likes"
123
 
 
138
  for s in e["modelatlas_similar"][:3]:
139
  details += f"- `{s['model_id']}`\n"
140
 
141
+ # Flags β€” lead with the DNA-003 engine panel, then the detail
142
+ flag_text = _fmt_engine_panel(v.get("engines", [])) + _fmt_flags(flags)
 
 
 
 
 
 
143
 
144
  return header, details, flag_text
145
 
146
 
147
+ def _fmt_engine_panel(engines: list) -> str:
148
+ if not engines:
149
+ return ""
150
+ t = "### πŸ”¬ Detector Engines\n\n"
151
+ for e in engines:
152
+ t += f"- {e['status']} Β· **{e['engine']}** β€” {e['detail']}\n"
153
+ return t + "\n---\n\n"
154
+
155
+
156
  def _fmt_flags(flags: list) -> str:
157
  if not flags:
158
  return "### βœ… No Flags\n\nNo suspicious claims detected in model name or metadata."
 
188
  v = result.get("verdict", {}); ev = result.get("evidence", {})
189
  header = (f"πŸ“¦ **GGUF metadata inspection** β€” {v.get('architecture','')}\n\n"
190
  "*Read from the GGUF header only β€” no weights downloaded.*")
191
+ if "risk_score" in v:
192
+ be = {"CLEAN": "🟒", "LOW": "🟑", "MODERATE": "🟠", "HIGH": "πŸ”΄"}.get(v.get("risk_band",""), "βšͺ")
193
+ header += f"\n\n### {be} Provenance Risk: {v['risk_score']}/100 Β· {v.get('risk_band','')}"
194
  details = ("### GGUF header\n"
195
  f"- **name:** {ev.get('gguf_general.name')}\n"
196
  f"- **architecture:** `{ev.get('gguf_architecture')}`\n"
197
  f"- **chat template present:** {ev.get('chat_template_present')}\n"
198
  f"- **file:** `{result.get('gguf_file')}`\n")
199
+ return header, details, _fmt_engine_panel(v.get("engines", [])) + _fmt_flags(v.get("flags", [])), ""
200
 
201
 
202
  def inspect_action(gguf_id: str):
scan.py CHANGED
@@ -510,6 +510,55 @@ def detect_provenance_scrubbing(chat_template: str) -> Optional[dict]:
510
  return None
511
 
512
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
513
  # Closed-weight brands: no weights ever released, so weight transfer is IMPOSSIBLE (not merely
514
  # unverifiable). Distillation-via-outputs is the only possible link and leaves no weight trace.
515
  _CLOSED_WEIGHT_BRANDS = {
@@ -805,6 +854,9 @@ def generate_verdict(
805
  else (f"{self_cat.get('model_type')} (original architecture)" if self_cat else "Unknown")
806
  ),
807
  "confidence": headline_confidence,
 
 
 
808
  "flags": flags,
809
  "flag_count": len(flags),
810
  "stage": "Stage 1 (config-only β€” no weight download)",
@@ -880,6 +932,9 @@ def inspect_gguf(model_id: str) -> dict:
880
  "verdict": {
881
  "architecture": f"CONFIRMED β€” GGUF architecture '{arch_raw}' = {arch}" if arch_raw
882
  else "UNRECOGNIZED",
 
 
 
883
  "flags": flags, "flag_count": len(flags),
884
  "stage": "Stage 1 (GGUF metadata β€” header only, no download)",
885
  },
 
510
  return None
511
 
512
 
513
+ # ── DNA-001: provenance risk scoring ──────────────────────────────────────────
514
+ # Points per flag type (heaviest = active deception). Score clamps to 100; 0 flags = 0 = clean.
515
+ _FLAG_WEIGHTS = {
516
+ "PROVENANCE_SCRUBBING": 45, # actively hides its lineage β€” worst
517
+ "IMPOSSIBLE_WEIGHT_PROVENANCE": 30, # claims a closed brand it can't be built on
518
+ "NAMING_MISATTRIBUTION": 20, # sells a brand that isn't the base
519
+ "IDENTITY_OVERRIDE": 15, # hard-coded identity, not necessarily deceptive
520
+ "NAME_MISMATCH": 15,
521
+ "UNVERIFIABLE_CLAIM": 10,
522
+ }
523
+
524
+ def _risk_score(flags: list) -> tuple:
525
+ """Aggregate flags into a 0–100 score + band. Higher = more provenance risk."""
526
+ score = 0
527
+ for f in flags:
528
+ w = _FLAG_WEIGHTS.get(f.get("type"), 8)
529
+ if f.get("severity") == "MEDIUM":
530
+ w = int(w * 0.85)
531
+ score += w
532
+ score = min(100, score)
533
+ band = ("CLEAN" if score == 0 else "LOW" if score <= 25
534
+ else "MODERATE" if score <= 55 else "HIGH")
535
+ return score, band
536
+
537
+
538
+ def _engine_panel(flags: list, arch_known: bool, chat_template_seen: bool) -> list:
539
+ """DNA-003: group detectors into named 'engines' with per-engine verdicts (VirusTotal-style)."""
540
+ by_type = {f.get("type") for f in flags}
541
+ def verdict(triggered, ran=True):
542
+ return "πŸ”΄ flagged" if triggered else ("βœ… pass" if ran else "βž– not run")
543
+ return [
544
+ {"engine": "Architecture Match",
545
+ "status": "βœ… pass" if arch_known else "❓ unrecognized",
546
+ "detail": "base architecture identified against ModelAtlas reference" if arch_known
547
+ else "no known base match"},
548
+ {"engine": "Provenance Integrity",
549
+ "status": verdict({"PROVENANCE_SCRUBBING", "IDENTITY_OVERRIDE"} & by_type, chat_template_seen),
550
+ "detail": "chat-template lineage scrub / identity override"},
551
+ {"engine": "Naming & Attribution",
552
+ "status": verdict({"NAMING_MISATTRIBUTION", "NAME_MISMATCH", "IMPOSSIBLE_WEIGHT_PROVENANCE",
553
+ "UNVERIFIABLE_CLAIM"} & by_type),
554
+ "detail": "name vs actual base; closed-brand / impossible claims"},
555
+ {"engine": "License Compliance", "status": "βž– not run",
556
+ "detail": "DNA-007 β€” coming soon"},
557
+ {"engine": "Safety Profile", "status": "βž– not run",
558
+ "detail": "DNA-012 (Stage 2) β€” coming soon"},
559
+ ]
560
+
561
+
562
  # Closed-weight brands: no weights ever released, so weight transfer is IMPOSSIBLE (not merely
563
  # unverifiable). Distillation-via-outputs is the only possible link and leaves no weight trace.
564
  _CLOSED_WEIGHT_BRANDS = {
 
854
  else (f"{self_cat.get('model_type')} (original architecture)" if self_cat else "Unknown")
855
  ),
856
  "confidence": headline_confidence,
857
+ "risk_score": _risk_score(flags)[0],
858
+ "risk_band": _risk_score(flags)[1],
859
+ "engines": _engine_panel(flags, bool(base_matches or self_cat), bool(chat_template)),
860
  "flags": flags,
861
  "flag_count": len(flags),
862
  "stage": "Stage 1 (config-only β€” no weight download)",
 
932
  "verdict": {
933
  "architecture": f"CONFIRMED β€” GGUF architecture '{arch_raw}' = {arch}" if arch_raw
934
  else "UNRECOGNIZED",
935
+ "risk_score": _risk_score(flags)[0],
936
+ "risk_band": _risk_score(flags)[1],
937
+ "engines": _engine_panel(flags, bool(arch_raw), bool(chat_template)),
938
  "flags": flags, "flag_count": len(flags),
939
  "stage": "Stage 1 (GGUF metadata β€” header only, no download)",
940
  },