trohrbaugh commited on
Commit
dfbcee9
Β·
verified Β·
1 Parent(s): 0dbbedb

GGUF support (metadata inspection + source resolution) + Mythos closed-brand

Browse files
Files changed (2) hide show
  1. app.py +85 -17
  2. scan.py +203 -9
app.py CHANGED
@@ -15,7 +15,7 @@ from pathlib import Path
15
 
16
  # scan.py is in the same directory as app.py in both local hf_space/ and on HF
17
  sys.path.insert(0, str(Path(__file__).parent))
18
- from scan import scan, KNOWN_BASES
19
 
20
  # ── Discovery: find derivatives that may not attribute properly ────────────
21
 
@@ -145,21 +145,78 @@ def format_verdict(result: dict) -> tuple[str, str, str]:
145
  return header, details, flag_text
146
 
147
 
148
- def run_scan(model_id: str) -> tuple[str, str, str, str]:
149
- """Main scan function called by Gradio."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  model_id = model_id.strip()
 
151
  if not model_id:
152
- return "Enter a HuggingFace model ID above.", "", "", ""
153
 
154
- # Normalize: handle full URLs
155
  if "huggingface.co/" in model_id:
156
  model_id = model_id.split("huggingface.co/")[-1].strip("/")
157
 
158
  result = scan(model_id)
159
-
160
- # Store result for derivative discovery
161
  store_scan_result(result)
162
 
 
 
 
 
 
 
 
163
  # Find unattributed derivatives
164
  base = result.get("verdict", {}).get("base_model_confirmed", "")
165
  derivatives = find_unattributed_derivatives(base, model_id) if base else []
@@ -180,7 +237,7 @@ def run_scan(model_id: str) -> tuple[str, str, str, str]:
180
  "derivatives that don't properly attribute their source will appear here."
181
  )
182
 
183
- return header, details, flags, discovery
184
 
185
 
186
  # ── Gradio UI ──────────────────────────────────────────────────────────────
@@ -209,8 +266,9 @@ with gr.Blocks(
209
  ### The DNA test for AI models β€” verify provenance before you download
210
  *Powered by ModelAtlas Β· a RadicalNotion product*
211
 
212
- > **Works with:** standard HuggingFace checkpoints (safetensors / PyTorch bin).
213
- > **Not yet supported:** GGUF quantized models, private/gated models. No weight download needed β€” Stage 1 reads config.json only.
 
214
  ---
215
  """)
216
 
@@ -238,6 +296,13 @@ with gr.Blocks(
238
  with gr.Column():
239
  flags_out = gr.Markdown(label="Flags")
240
 
 
 
 
 
 
 
 
241
  gr.Markdown("---")
242
  discovery_out = gr.Markdown(label="Derivative Discovery")
243
 
@@ -248,15 +313,18 @@ with gr.Blocks(
248
  *[modeldna.ai](https://modeldna.ai) Β· [RadicalNotionAI on HF](https://huggingface.co/RadicalNotionAI)*
249
  """)
250
 
251
- scan_btn.click(
252
- fn=run_scan,
253
- inputs=[model_input],
 
 
 
 
 
254
  outputs=[header_out, details_out, flags_out, discovery_out],
255
  )
256
- model_input.submit(
257
- fn=run_scan,
258
- inputs=[model_input],
259
- outputs=[header_out, details_out, flags_out, discovery_out],
260
  )
261
 
262
  if __name__ == "__main__":
 
15
 
16
  # scan.py is in the same directory as app.py in both local hf_space/ and on HF
17
  sys.path.insert(0, str(Path(__file__).parent))
18
+ from scan import scan, inspect_gguf, KNOWN_BASES
19
 
20
  # ── Discovery: find derivatives that may not attribute properly ────────────
21
 
 
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."
151
+ t = f"### ⚠️ {len(flags)} Flag(s) Found\n\n"
152
+ for f in flags:
153
+ sev = f.get("severity", "")
154
+ t += f"**[{f['type']}]**" + (f" _(severity: {sev})_" if sev else "")
155
+ t += f"\n\n{f['explanation']}\n\n---\n\n"
156
+ return t
157
+
158
+
159
+ def format_gguf_scan(result: dict) -> tuple[str, str, str, str]:
160
+ """Render a GGUF detection: what it is + the optional follow-up offers (as text)."""
161
+ src = result.get("resolved_source")
162
+ header = ("πŸ“¦ **GGUF quantization detected**\n\n"
163
+ "*A quant is the same weights at lower precision β€” its provenance equals its source.*")
164
+ details = "### What this is\n" + result.get("detected", "") + "\n\n"
165
+ if src:
166
+ details += f"**Resolved full-weights source:** `{src}`\n\n"
167
+ details += ("**Optional deeper checks** β€” use the buttons below:\n"
168
+ "- πŸ” Inspect this GGUF's embedded metadata (architecture + chat template) β€” header-only, no download\n")
169
+ if src:
170
+ details += "- πŸ”¬ Scan the full-weights source for full Stage 1 + Stage 2\n"
171
+ disc = ("### πŸ” Derivative Discovery\n\nGGUF quants inherit their source's provenance "
172
+ "(and any identity scrub baked into the chat template). Inspect the metadata or "
173
+ "scan the source for the full picture.")
174
+ return header, details, "", disc
175
+
176
+
177
+ def format_inspection(result: dict) -> tuple[str, str, str, str]:
178
+ if "error" in result:
179
+ return "❌ GGUF inspection failed", f"**Error**: {result['error']}", "", ""
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):
192
+ """Optional action (offer #1): inspect the GGUF's embedded metadata."""
193
+ return format_inspection(inspect_gguf(gguf_id))
194
+
195
+
196
+ _HIDE = None # placeholder; gr.update created inline
197
+
198
+
199
+ def run_scan(model_id: str):
200
+ """Main scan. Returns 8 outputs: 4 markdown panes + GGUF action row/button updates + 2 states."""
201
+ import gradio as _gr
202
  model_id = model_id.strip()
203
+ hide_row = _gr.update(visible=False); hide_btn = _gr.update(visible=False)
204
  if not model_id:
205
+ return "Enter a HuggingFace model ID above.", "", "", "", hide_row, hide_btn, "", ""
206
 
 
207
  if "huggingface.co/" in model_id:
208
  model_id = model_id.split("huggingface.co/")[-1].strip("/")
209
 
210
  result = scan(model_id)
 
 
211
  store_scan_result(result)
212
 
213
+ # GGUF: show detection + reveal the optional follow-up buttons
214
+ if str(result.get("format", "")).startswith("GGUF"):
215
+ h, d, fl, disc = format_gguf_scan(result)
216
+ src = result.get("resolved_source") or ""
217
+ src_btn = _gr.update(visible=bool(src), value=f"πŸ”¬ Scan source: {src}") if src else hide_btn
218
+ return h, d, fl, disc, _gr.update(visible=True), src_btn, src, model_id
219
+
220
  # Find unattributed derivatives
221
  base = result.get("verdict", {}).get("base_model_confirmed", "")
222
  derivatives = find_unattributed_derivatives(base, model_id) if base else []
 
237
  "derivatives that don't properly attribute their source will appear here."
238
  )
239
 
240
+ return header, details, flags, discovery, hide_row, hide_btn, "", ""
241
 
242
 
243
  # ── Gradio UI ──────────────────────────────────────────────────────────────
 
266
  ### The DNA test for AI models β€” verify provenance before you download
267
  *Powered by ModelAtlas Β· a RadicalNotion product*
268
 
269
+ > **Works with:** standard HuggingFace checkpoints (safetensors / PyTorch bin) **and GGUF quants**
270
+ > (header-only metadata inspection + source resolution). Not yet supported: private/gated models.
271
+ > No weight download needed β€” Stage 1 reads config.json (or the GGUF header) only.
272
  ---
273
  """)
274
 
 
296
  with gr.Column():
297
  flags_out = gr.Markdown(label="Flags")
298
 
299
+ # GGUF optional follow-up actions (hidden until a GGUF is scanned)
300
+ source_state = gr.State("")
301
+ gguf_id_state = gr.State("")
302
+ with gr.Row(visible=False) as gguf_actions:
303
+ inspect_btn = gr.Button("πŸ” Inspect GGUF metadata (no download)")
304
+ source_btn = gr.Button("πŸ”¬ Scan full-weights source", variant="primary")
305
+
306
  gr.Markdown("---")
307
  discovery_out = gr.Markdown(label="Derivative Discovery")
308
 
 
313
  *[modeldna.ai](https://modeldna.ai) Β· [RadicalNotionAI on HF](https://huggingface.co/RadicalNotionAI)*
314
  """)
315
 
316
+ _scan_outputs = [header_out, details_out, flags_out, discovery_out,
317
+ gguf_actions, source_btn, source_state, gguf_id_state]
318
+ scan_btn.click(fn=run_scan, inputs=[model_input], outputs=_scan_outputs)
319
+ model_input.submit(fn=run_scan, inputs=[model_input], outputs=_scan_outputs)
320
+
321
+ # Optional GGUF follow-ups (user-triggered)
322
+ inspect_btn.click(
323
+ fn=inspect_action, inputs=[gguf_id_state],
324
  outputs=[header_out, details_out, flags_out, discovery_out],
325
  )
326
+ source_btn.click( # scan the resolved full-weights source
327
+ fn=run_scan, inputs=[source_state], outputs=_scan_outputs,
 
 
328
  )
329
 
330
  if __name__ == "__main__":
scan.py CHANGED
@@ -307,6 +307,117 @@ def fetch_model_metadata(model_id: str) -> dict:
307
  return {}
308
 
309
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
310
  def fetch_chat_template(model_id: str) -> str:
311
  """Fetch the chat template (config-only, no weights). Checks tokenizer_config.json's
312
  chat_template field and the standalone chat_template.jinja. Returns "" on failure."""
@@ -398,6 +509,7 @@ def detect_provenance_scrubbing(chat_template: str) -> Optional[dict]:
398
  # unverifiable). Distillation-via-outputs is the only possible link and leaves no weight trace.
399
  _CLOSED_WEIGHT_BRANDS = {
400
  "claude": "Anthropic Claude", "anthropic": "Anthropic Claude",
 
401
  "gpt": "OpenAI GPT", "chatgpt": "OpenAI GPT", "openai": "OpenAI GPT",
402
  "gemini": "Google Gemini", "grok": "xAI Grok",
403
  }
@@ -425,7 +537,7 @@ def detect_claimed_base(model_id: str, config: dict, metadata: dict) -> dict:
425
  claims["name_implies"] = name_signals
426
  # Suspicious claims in name
427
  suspicious = []
428
- for term in ["claude", "gpt", "chatgpt", "openai", "gemini", "anthropic"]:
429
  if term in name:
430
  suspicious.append(term)
431
  if suspicious:
@@ -675,23 +787,105 @@ def generate_verdict(
675
  }
676
 
677
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
678
  def scan(model_id: str) -> dict:
679
  """Full Stage 1 scan. Entry point."""
680
  t0 = time.time()
681
 
682
- # Detect unsupported formats before attempting config fetch
683
  name_lower = model_id.lower()
684
  if "gguf" in name_lower:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
685
  return {
686
  "model_id": model_id,
687
- "error": (
688
- "GGUF models pack weights into a single file and don't have a standard config.json. "
689
- "Stage 1 scanning works with standard HuggingFace checkpoints (safetensors/PyTorch). "
690
- "Try the original (non-quantized) model instead β€” e.g. the unsloth/Qwen3.6-35B-A3B "
691
- "base would be Qwen/Qwen2.5-... or the upstream source. "
692
- "GGUF support is on the roadmap."
693
- ),
694
  "scanned_at": datetime.now(timezone.utc).isoformat(),
 
 
 
 
 
 
 
 
 
 
 
 
695
  }
696
 
697
  config = fetch_config(model_id)
 
307
  return {}
308
 
309
 
310
+ # ── GGUF support (header-only; no weight download / dequantization) ───────────
311
+ import struct
312
+
313
+ _GGUF_MAGIC = b"GGUF"
314
+ # value type -> fixed byte size (None = variable: STRING/ARRAY handled specially)
315
+ _GGUF_SCALAR = {0: 1, 1: 1, 2: 2, 3: 2, 4: 4, 5: 4, 6: 4, 7: 1, 10: 8, 11: 8, 12: 8}
316
+ _GGUF_STRING, _GGUF_ARRAY = 8, 9
317
+
318
+
319
+ def _gguf_read_str(buf, off):
320
+ (ln,) = struct.unpack_from("<Q", buf, off); off += 8
321
+ s = buf[off:off + ln].decode("utf-8", "replace"); off += ln
322
+ return s, off
323
+
324
+
325
+ def _gguf_skip_value(buf, off, vtype):
326
+ """Advance past a value of the given type; return (extracted_string_or_None, new_off)."""
327
+ if vtype in _GGUF_SCALAR:
328
+ return None, off + _GGUF_SCALAR[vtype]
329
+ if vtype == _GGUF_STRING:
330
+ s, off = _gguf_read_str(buf, off)
331
+ return s, off
332
+ if vtype == _GGUF_ARRAY:
333
+ (etype,) = struct.unpack_from("<I", buf, off); off += 4
334
+ (cnt,) = struct.unpack_from("<Q", buf, off); off += 8
335
+ for _ in range(cnt):
336
+ if etype in _GGUF_SCALAR:
337
+ off += _GGUF_SCALAR[etype]
338
+ elif etype == _GGUF_STRING:
339
+ _, off = _gguf_read_str(buf, off)
340
+ else:
341
+ raise ValueError(f"nested array type {etype}")
342
+ return None, off
343
+ raise ValueError(f"unknown gguf value type {vtype}")
344
+
345
+
346
+ def parse_gguf_metadata(buf: bytes) -> dict:
347
+ """Parse GGUF metadata KV pairs from the file header bytes. Returns {key: str_value}
348
+ for string-valued keys (architecture, name, chat_template, etc.). Tolerates truncation."""
349
+ if buf[:4] != _GGUF_MAGIC:
350
+ return {}
351
+ off = 4
352
+ (_ver,) = struct.unpack_from("<I", buf, off); off += 4
353
+ off += 8 # tensor_count (uint64) β€” skip
354
+ (kv_count,) = struct.unpack_from("<Q", buf, off); off += 8
355
+ out = {}
356
+ for _ in range(kv_count):
357
+ try:
358
+ key, off = _gguf_read_str(buf, off)
359
+ (vtype,) = struct.unpack_from("<I", buf, off); off += 4
360
+ val, off = _gguf_skip_value(buf, off, vtype)
361
+ if val is not None:
362
+ out[key] = val
363
+ except (struct.error, ValueError, IndexError):
364
+ break # ran past the fetched header window β€” return what we have
365
+ return out
366
+
367
+
368
+ def fetch_gguf_metadata(model_id: str, max_bytes: int = 12_000_000) -> dict:
369
+ """Find a .gguf file in the repo and range-fetch its header to parse metadata.
370
+ No full download. Returns {} on failure."""
371
+ headers = {}
372
+ token = os.environ.get("HF_TOKEN", "")
373
+ if token:
374
+ headers["Authorization"] = f"Bearer {token}"
375
+ try:
376
+ r = requests.get(f"{HF_API}/api/models/{model_id}", headers=headers, timeout=10)
377
+ files = [s["rfilename"] for s in r.json().get("siblings", [])]
378
+ except Exception:
379
+ return {}
380
+ ggufs = [f for f in files if f.lower().endswith(".gguf")]
381
+ # prefer a single-file / first shard
382
+ ggufs.sort(key=lambda f: ("00001" not in f, f))
383
+ for f in ggufs[:1]:
384
+ try:
385
+ h = dict(headers); h["Range"] = f"bytes=0-{max_bytes}"
386
+ rr = requests.get(f"{HF_API}/{model_id}/resolve/main/{f}", headers=h, timeout=30)
387
+ if rr.status_code in (200, 206):
388
+ md = parse_gguf_metadata(rr.content)
389
+ if md:
390
+ md["_gguf_file"] = f
391
+ return md
392
+ except Exception:
393
+ continue
394
+ return {}
395
+
396
+
397
+ def resolve_gguf_source(model_id: str, metadata: dict, gguf_md: dict) -> Optional[str]:
398
+ """Best-effort upstream full-weights repo for a GGUF quant."""
399
+ # 1) explicit base_model tag on the GGUF repo
400
+ bm = metadata.get("base_model")
401
+ if bm:
402
+ return bm if isinstance(bm, str) else (bm[0] if bm else None)
403
+ # 2) GGUF metadata general.base_model
404
+ for k in ("general.base_model", "general.base_model.0.repo_url", "general.source.repo"):
405
+ if gguf_md.get(k):
406
+ v = gguf_md[k]
407
+ return v.split("huggingface.co/")[-1].strip("/") if "huggingface.co" in v else v
408
+ # 3) name heuristic: strip common quant/format suffixes
409
+ name = model_id.split("/")[-1]
410
+ stripped = re.sub(r"[-_.]?(GGUF|gguf|Q\d[_A-Za-z0-9]*|i1|IQ\d[_A-Za-z0-9]*|imatrix|"
411
+ r"fp16|bf16|f16|MLX|mlx|AWQ|GPTQ|NVFP4|mxfp\d+|HyperQuant|SHQ8|ROCmFP4|COHERENT)$",
412
+ "", name)
413
+ while stripped != name: # strip repeated suffixes
414
+ name, stripped = stripped, re.sub(
415
+ r"[-_.]?(GGUF|gguf|Q\d[_A-Za-z0-9]*|i1|IQ\d[_A-Za-z0-9]*|imatrix|fp16|bf16|f16|"
416
+ r"MLX|mlx|AWQ|GPTQ|NVFP4|mxfp\d+|HyperQuant|SHQ8|ROCmFP4|COHERENT)$", "", stripped)
417
+ org = model_id.split("/")[0]
418
+ return f"{org}/{stripped}" if stripped and stripped != model_id.split("/")[-1] else None
419
+
420
+
421
  def fetch_chat_template(model_id: str) -> str:
422
  """Fetch the chat template (config-only, no weights). Checks tokenizer_config.json's
423
  chat_template field and the standalone chat_template.jinja. Returns "" on failure."""
 
509
  # unverifiable). Distillation-via-outputs is the only possible link and leaves no weight trace.
510
  _CLOSED_WEIGHT_BRANDS = {
511
  "claude": "Anthropic Claude", "anthropic": "Anthropic Claude",
512
+ "mythos": "Anthropic Mythos (closed)", "fable": "Anthropic Fable (closed)",
513
  "gpt": "OpenAI GPT", "chatgpt": "OpenAI GPT", "openai": "OpenAI GPT",
514
  "gemini": "Google Gemini", "grok": "xAI Grok",
515
  }
 
537
  claims["name_implies"] = name_signals
538
  # Suspicious claims in name
539
  suspicious = []
540
+ for term in ["claude", "gpt", "chatgpt", "openai", "gemini", "anthropic", "mythos", "fable"]:
541
  if term in name:
542
  suspicious.append(term)
543
  if suspicious:
 
787
  }
788
 
789
 
790
+ _GGUF_ARCH_MAP = {
791
+ "qwen35": "Qwen3.5", "qwen3_5": "Qwen3.5", "qwen3": "Qwen3", "qwen2": "Qwen2.5",
792
+ "llama": "Llama", "gemma": "Gemma", "gemma2": "Gemma", "gemma3": "Gemma",
793
+ "phi3": "Phi-3", "mistral": "Mistral", "deepseek2": "DeepSeek V2/V3",
794
+ }
795
+
796
+
797
+ def inspect_gguf(model_id: str) -> dict:
798
+ """OPTIONAL ACTION (offer #1): inspect a GGUF's embedded metadata (header-only, no
799
+ download) and run the provenance detectors on the template baked into the file."""
800
+ now = datetime.now(timezone.utc).isoformat()
801
+ md = fetch_gguf_metadata(model_id)
802
+ if not md:
803
+ return {"model_id": model_id, "scanned_at": now,
804
+ "error": "Could not read GGUF metadata header (file may be gated/missing)."}
805
+ arch_raw = md.get("general.architecture", "")
806
+ arch = _GGUF_ARCH_MAP.get(arch_raw, arch_raw or "unknown")
807
+ chat_template = md.get("tokenizer.chat_template", "")
808
+
809
+ flags = []
810
+ # provenance scrub baked into the GGUF's template
811
+ scrub = detect_provenance_scrubbing(chat_template)
812
+ if scrub:
813
+ scrub = dict(scrub); scrub["source"] = "gguf embedded chat_template"
814
+ flags.append(scrub)
815
+ # closed-weight brand + naming misattribution from the name
816
+ name_l = model_id.split("/")[-1].lower()
817
+ closed = sorted({_CLOSED_WEIGHT_BRANDS[t] for t in _CLOSED_WEIGHT_BRANDS if
818
+ re.search(r"\b" + re.escape(t) + r"\b", name_l)})
819
+ for brand in closed:
820
+ flags.append({
821
+ "type": "IMPOSSIBLE_WEIGHT_PROVENANCE", "severity": "HIGH", "term": brand,
822
+ "explanation": f"Name references {brand}, whose weights were never released β€” "
823
+ f"weight provenance is impossible. GGUF architecture is '{arch}'.",
824
+ })
825
+ arch_family = re.sub(r"[0-9.\-]", "", arch.lower())
826
+ if closed and arch_family and arch_family not in name_l.replace("-", ""):
827
+ flags.append({
828
+ "type": "NAMING_MISATTRIBUTION", "severity": "MEDIUM",
829
+ "explanation": f"Name foregrounds {', '.join(closed)} but GGUF architecture is "
830
+ f"{arch} β€” '{arch_family}' is absent from the name.",
831
+ })
832
+
833
+ return {
834
+ "model_id": model_id, "scanned_at": now,
835
+ "format": "GGUF (quantized)", "gguf_file": md.get("_gguf_file"),
836
+ "verdict": {
837
+ "architecture": f"CONFIRMED β€” GGUF architecture '{arch_raw}' = {arch}" if arch_raw
838
+ else "UNRECOGNIZED",
839
+ "flags": flags, "flag_count": len(flags),
840
+ "stage": "Stage 1 (GGUF metadata β€” header only, no download)",
841
+ },
842
+ "evidence": {"gguf_general.name": md.get("general.name"),
843
+ "gguf_architecture": arch_raw,
844
+ "chat_template_present": bool(chat_template),
845
+ "quantization": md.get("general.quantization_version") or md.get("general.file_type")},
846
+ "note": ("Read from the GGUF header only β€” no weights downloaded. The chat template "
847
+ "and identity behavior travel INTO the quant, so a scrub in the source is "
848
+ "present here too. Powered by ModelAtlas β€” modeldna.ai."),
849
+ }
850
+
851
+
852
  def scan(model_id: str) -> dict:
853
  """Full Stage 1 scan. Entry point."""
854
  t0 = time.time()
855
 
856
+ # GGUF: no standard config.json β€” offer metadata inspection + source resolution.
857
  name_lower = model_id.lower()
858
  if "gguf" in name_lower:
859
+ metadata = fetch_model_metadata(model_id)
860
+ gguf_md = fetch_gguf_metadata(model_id)
861
+ source = resolve_gguf_source(model_id, metadata, gguf_md)
862
+ offers = []
863
+ offers.append({
864
+ "action": "inspect_gguf", "model_id": model_id,
865
+ "label": "Inspect this GGUF's embedded metadata (architecture + chat template) β€” "
866
+ "header-only, no download",
867
+ })
868
+ if source:
869
+ offers.append({
870
+ "action": "scan_source", "model_id": source,
871
+ "label": f"Scan the full-weights source ({source}) β€” full Stage 1 + Stage 2",
872
+ })
873
+ arch_raw = gguf_md.get("general.architecture", "")
874
  return {
875
  "model_id": model_id,
 
 
 
 
 
 
 
876
  "scanned_at": datetime.now(timezone.utc).isoformat(),
877
+ "format": "GGUF (quantized)",
878
+ "detected": (
879
+ f"This is a GGUF quantization"
880
+ + (f" of an '{arch_raw}' architecture model" if arch_raw else "")
881
+ + (f", derived from {source}" if source else "") + ". "
882
+ "A quant is the SAME weights at lower precision β€” provenance is identical to "
883
+ "the source. The embedded chat template (and any identity scrub) travels into the file."
884
+ ),
885
+ "resolved_source": source,
886
+ "offers": offers,
887
+ "elapsed_s": round(time.time() - t0, 2),
888
+ "note": "Powered by ModelAtlas β€” modeldna.ai Β· a RadicalNotion product.",
889
  }
890
 
891
  config = fetch_config(model_id)