Datasets:
Download code/engines/export_preds.py from schift-io/KoOCR-Bench: direct link, hf CLI and curl.
- Browser
- Download file 652 Bytes
-
https://huggingface.co/datasets/schift-io/KoOCR-Bench/resolve/main/code/engines/export_preds.py
- Command line
-
hf download hf://datasets/schift-io/KoOCR-Bench/code/engines/export_preds.py
-
curl -L -o export_preds.py https://huggingface.co/datasets/schift-io/KoOCR-Bench/resolve/main/code/engines/export_preds.py
652 Bytes
| #!/usr/bin/env python3 | |
| """raw client rows -> predictions.jsonl {id: kbench id with '/', text}. Usage: export_preds.py MANIFEST_JSON... -- RAW_JSONL... -- OUT""" | |
| import json, sys | |
| a = sys.argv[1:]; i = a.index("--"); j = a.index("--", i + 1) | |
| kid = {p["id"]: p["kid"] for m in a[:i] for p in json.load(open(m))["pages"]} | |
| rows = {} | |
| for raw in a[i + 1:j]: | |
| for l in open(raw): | |
| r = json.loads(l); rows[r["id"]] = r | |
| with open(a[j + 1], "w") as f: | |
| for k, r in rows.items(): f.write(json.dumps({"id": kid[k], "text": r["text"], "finish": r["finish"], "error": r["error"]}, ensure_ascii=False) + "\n") | |
| print("exported", len(rows), "of", len(kid)) | |