Datasets:
Download code/tools/find_content_fp.py from VEHwang/cocogni4d: direct link, hf CLI and curl.
- Browser
- Download file 1.9 kB
-
https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/tools/find_content_fp.py
- Command line
-
hf download hf://datasets/VEHwang/cocogni4d/code/tools/find_content_fp.py
-
curl -L -o find_content_fp.py https://huggingface.co/datasets/VEHwang/cocogni4d/resolve/main/code/tools/find_content_fp.py
1.9 kB
| #!/usr/bin/env python3 | |
| """Read-only: for every file that will change, compute content digests other than the raw-byte sha256 | |
| (canonical JSON variants, facts capability composite) and report where those digests are embedded.""" | |
| import hashlib, json, collections as C | |
| from pathlib import Path | |
| H = Path('${LOCAL}/simulation-workspace/runs/hf-release-20261120') | |
| res = {x['rel']: x for x in json.load(open(H / 'work/scan.json'))} | |
| g = json.load(open(H / 'work/graph.json')); ch = g['changed'] | |
| where = {} | |
| for x in res.values(): | |
| for h in x['hashes']: where.setdefault(h, []).append(x['rel']) | |
| sha = lambda b: hashlib.sha256(b).hexdigest() | |
| V = {'sort_ea': lambda o: json.dumps(o, sort_keys=True, ensure_ascii=False).encode(), | |
| 'sort_compact': lambda o: json.dumps(o, sort_keys=True, separators=(',', ':'), ensure_ascii=False).encode(), | |
| 'sort_compact_ascii': lambda o: json.dumps(o, sort_keys=True, separators=(',', ':')).encode(), | |
| 'sort_ascii': lambda o: json.dumps(o, sort_keys=True).encode(), | |
| 'plain': lambda o: json.dumps(o, ensure_ascii=False).encode()} | |
| hits = C.Counter(); ex = {} | |
| for rel in ch: | |
| if not rel.endswith('.json'): continue | |
| p = Path(res[rel]['root']) / rel | |
| try: o = json.loads(p.read_bytes()) | |
| except Exception: continue | |
| for name, f in V.items(): | |
| d = sha(f(o)) | |
| for r in where.get(d, []): | |
| k = (name, rel.split('/')[0] + '/' + rel.split('/')[-1], r.split('/')[0] + '/' + r.split('/')[-1]) | |
| hits[k] += 1; ex.setdefault(k, (rel, r)) | |
| if rel.endswith('/capability.json'): | |
| sb = p.parent / 'static-bands.npz' | |
| d = sha(p.read_bytes() + sb.read_bytes()) | |
| for r in where.get(d, []): | |
| k = ('cap+static', rel.split('/')[-1], r.split('/')[0] + '/' + r.split('/')[-1]); hits[k] += 1; ex.setdefault(k, (rel, r)) | |
| for k, n in hits.most_common(): print(n, k, ex[k]) | |
| print('done', len(hits)) | |