trohrbaugh commited on
Commit
2e3661e
·
verified ·
1 Parent(s): ce148d0

DNA-017: source-tag scans (ui vs internal-test)

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -47,13 +47,14 @@ except Exception as _e:
47
  _SCAN_LOGGER = None
48
  print(f"[DNA-017] scan logging DISABLED: scheduler init failed: {_e!r}", flush=True)
49
 
50
- def log_scan(model_id: str, result: dict) -> None:
51
  if _SCAN_LOGGER is None:
52
  return
53
  try:
54
  v = result.get("verdict", {})
55
  rec = {
56
  "model_id": model_id,
 
57
  "ts": _dt.datetime.now(_dt.timezone.utc).isoformat(),
58
  "format": result.get("format", "checkpoint"),
59
  "architecture": v.get("architecture", "") or result.get("detected", "")[:80],
@@ -463,7 +464,7 @@ def inspect_action(gguf_id: str):
463
  _HIDE = None # placeholder; gr.update created inline
464
 
465
 
466
- def run_scan(model_id: str):
467
  """Main scan. Returns 8 outputs: 4 markdown panes + GGUF action row/button updates + 2 states."""
468
  import gradio as _gr
469
  model_id = model_id.strip()
@@ -489,7 +490,15 @@ def run_scan(model_id: str):
489
 
490
  result = scan(model_id)
491
  store_scan_result(result)
492
- log_scan(model_id, result) # DNA-017: telemetry to HF dataset (no-op without LOG_TOKEN)
 
 
 
 
 
 
 
 
493
 
494
  # GGUF: show detection + reveal the optional follow-up buttons
495
  if str(result.get("format", "")).startswith("GGUF"):
 
47
  _SCAN_LOGGER = None
48
  print(f"[DNA-017] scan logging DISABLED: scheduler init failed: {_e!r}", flush=True)
49
 
50
+ def log_scan(model_id: str, result: dict, source: str = "ui") -> None:
51
  if _SCAN_LOGGER is None:
52
  return
53
  try:
54
  v = result.get("verdict", {})
55
  rec = {
56
  "model_id": model_id,
57
+ "source": source, # "ui" (web) vs "internal-test" (our gradio_client) — for usage filtering
58
  "ts": _dt.datetime.now(_dt.timezone.utc).isoformat(),
59
  "format": result.get("format", "checkpoint"),
60
  "architecture": v.get("architecture", "") or result.get("detected", "")[:80],
 
464
  _HIDE = None # placeholder; gr.update created inline
465
 
466
 
467
+ def run_scan(model_id: str, request: gr.Request = None):
468
  """Main scan. Returns 8 outputs: 4 markdown panes + GGUF action row/button updates + 2 states."""
469
  import gradio as _gr
470
  model_id = model_id.strip()
 
490
 
491
  result = scan(model_id)
492
  store_scan_result(result)
493
+ # DNA-017: source tag for usage filtering — "ui" for web visitors; our gradio_client test
494
+ # calls set the X-ModelDNA-Source header so they can be excluded from external-usage counts.
495
+ _src = "ui"
496
+ try:
497
+ if request is not None:
498
+ _src = (request.headers.get("x-modeldna-source") or "ui").lower()[:32]
499
+ except Exception:
500
+ _src = "ui"
501
+ log_scan(model_id, result, _src) # telemetry to HF dataset (no-op without LOG_TOKEN)
502
 
503
  # GGUF: show detection + reveal the optional follow-up buttons
504
  if str(result.get("format", "")).startswith("GGUF"):