Datasets:
Download code/engines/run_paddlevl.py from schift-io/KoOCR-Bench: direct link, hf CLI and curl.
- Browser
- Download file 1.75 kB
-
https://huggingface.co/datasets/schift-io/KoOCR-Bench/resolve/main/code/engines/run_paddlevl.py
- Command line
-
hf download hf://datasets/schift-io/KoOCR-Bench/code/engines/run_paddlevl.py
-
curl -L -o run_paddlevl.py https://huggingface.co/datasets/schift-io/KoOCR-Bench/resolve/main/code/engines/run_paddlevl.py
1.75 kB
| import os | |
| """PaddleOCR-VL-1.6 (default pipeline) on KDoc+Kolm pages -> score_external.py jsonl. Resumable. | |
| Usage: run_paddlevl.py OUT_JSONL [LIMIT] [SHARD_INDEX SHARD_COUNT]""" | |
| import json, os, sys, time | |
| from pathlib import Path | |
| from paddleocr import PaddleOCRVL | |
| M = Path(os.environ.get("MANIFEST_DIR", "manifests")) | |
| out = Path(sys.argv[1]); limit = int(sys.argv[2]) if len(sys.argv) > 2 else 0 | |
| si, sc = (int(sys.argv[3]), int(sys.argv[4])) if len(sys.argv) > 4 else (0, 1) | |
| pages = [p for b in os.environ.get("BENCHES", "kdoc,kolm").split(",") for p in json.loads((M / f"{b}.json").read_text())["pages"]][si::sc] | |
| if limit: pages = pages[:limit] | |
| done = {json.loads(l)["id"] for l in out.open()} if out.exists() else set() | |
| pipe = PaddleOCRVL(pipeline_version="v1.6", vl_rec_backend="vllm-server", vl_rec_server_url="http://127.0.0.1:8050/v1", vl_rec_api_model_name="PaddleOCR-VL-1.6-0.9B", vl_rec_max_concurrency=64) | |
| with out.open("a") as f: | |
| for p in pages: | |
| if p["id"] in done: continue | |
| t = time.time(); text, err, boxes = "", None, [] | |
| try: | |
| for res in pipe.predict(p["image"]): | |
| md = res.markdown | |
| text += (md.get("markdown_texts", "") if isinstance(md, dict) else str(md)) | |
| r = res.json.get("res", res.json) | |
| for b in r.get("parsing_res_list", []): | |
| boxes.append({"label": b.get("block_label"), "bbox": b.get("block_bbox")}) | |
| boxes.append({"image_size": [r.get("width"), r.get("height")]}) | |
| except Exception as e: | |
| err = repr(e)[:300] | |
| f.write(json.dumps({"id": p["id"], "text": text, "boxes": boxes, "error": err, "seconds": round(time.time() - t, 2)}, ensure_ascii=False) + "\n"); f.flush() | |