davanstrien HF Staff commited on
Commit
c2abd1f
·
verified ·
1 Parent(s): 5505161

Sync from GitHub via hub-sync

Browse files
Files changed (1) hide show
  1. README.md +79 -19
README.md CHANGED
@@ -13,31 +13,74 @@ A model zoo of OCR scripts — one per model — that add a `markdown` column to
13
 
14
  ## Quick Start
15
 
16
- Run OCR on any dataset without needing your own GPU:
 
 
17
 
18
  ```bash
19
- # Quick test with 10 samples
20
- hf jobs uv run --flavor l4x1 \
21
- --secrets HF_TOKEN \
22
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/glm-ocr.py \
23
- your-input-dataset your-output-dataset \
24
- --max-samples 10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  ```
26
 
27
- This will:
 
 
 
 
 
 
28
 
29
- - Process the first 10 images from your dataset
30
- - Add OCR results as a new `markdown` column
31
- - Push the results to a new dataset
32
- - View results at: `https://huggingface.co/datasets/[your-output-dataset]`
 
 
 
 
 
33
 
34
- ## Serve a model as a live endpoint
35
 
36
- The recipes here run as batch jobs. Some models also have a **`-server.py` sibling recipe** that runs the same dataset→dataset batch job through an in-job `vllm serve` + concurrent driver — measurably faster (continuous batching stays fed) and more robust (one bad image fails one request, not a whole batch); see [SERVING.md](SERVING.md) for the architecture, A/B numbers, and which models officially document server mode. A third lane is starting: **`-saturate.py` companions** ([`lighton-ocr2-saturate.py`](https://huggingface.co/datasets/uv-scripts/ocr/blob/main/lighton-ocr2-saturate.py), [`ovis-ocr2-saturate.py`](https://huggingface.co/datasets/uv-scripts/ocr/blob/main/ovis-ocr2-saturate.py)) keep the same model, prompt, and sampling but replace the hand-rolled driver half with the [saturate](https://github.com/davanstrien/saturate) library — adaptive concurrency (no `--concurrency` to tune), crash-safe resumable output (re-running skips finished rows), and durable per-row error records instead of `[OCR ERROR]` strings. Each carries a machine-readable `SERVING` dict (serve flags + sampling + context math) at the top of the script. To call a model interactively, from an agent, or with concurrent ad-hoc requests, you can instead run it as a temporary endpoint: [HF Jobs serving](https://huggingface.co/docs/hub/jobs-serving) exposes a port on a GPU Job, giving an OpenAI-compatible endpoint that runs until the job is cancelled or its `--timeout` is reached. See [serving-unlimited-ocr.md](serving-unlimited-ocr.md) for a worked example serving Baidu's [Unlimited-OCR](https://huggingface.co/baidu/Unlimited-OCR) — with vLLM (official image) or SGLang. To OCR a whole corpus of single-page images instead, the batch recipe `unlimited-ocr-vllm.py` is the better fit (it's single-image only). **Multi-page** documents need a server: both vLLM and SGLang read clean multi-page docs, but **SGLang is the more robust** — on hard/degraded scans vLLM multi-page hallucinated in our tests while SGLang held up.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  ## Models at a glance
39
 
40
- **Start here:** for a quick first run, try **`lighton-ocr2.py`** (1B, very fast), **`paddleocr-vl-1.6.py`** (0.9B, 96.33 OmniDocBench) or **`ovis-ocr2.py`** (0.9B, 96.58 OmniDocBench — current SOTA); for the smallest footprint, **`falcon-ocr.py`** (0.3B, strong on tables). Reach for a 7–8B model only when quality demands it. Several of these models sit on the public [olmOCR-Bench](https://huggingface.co/datasets/allenai/olmOCR-bench) — pull the live ranking from your terminal in one command:
41
 
42
  ```bash
43
  hf datasets leaderboard allenai/olmOCR-bench
@@ -169,11 +212,7 @@ The scripts aim to expose a **consistent interface**: every OCR model script tak
169
  | `--create-pr` | Push as PR instead of direct commit |
170
  | `--verbose` | Log resolved package versions after run |
171
 
172
- Every script supports `--help` to see all available options:
173
-
174
- ```bash
175
- uv run glm-ocr.py --help
176
- ```
177
 
178
  ## NuExtract3: markdown OCR + structured extraction
179
 
@@ -239,6 +278,27 @@ Beyond the shared flags, some models add their own. Run `--help` on any script f
239
  - **Reproducible sampling** — `--shuffle` (with `--seed`, default 42) draws a representative sample instead of the first N rows.
240
  - **Automatic dataset cards** — every run writes a card with the model config, processing stats, column descriptions, and a reproduction command.
241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  ## More examples
243
 
244
  ```bash
 
13
 
14
  ## Quick Start
15
 
16
+ First, [install the `hf` CLI and sign in](https://huggingface.co/docs/hub/jobs-quickstart). Jobs requires pay-as-you-go credit.
17
+
18
+ Try [GLM-OCR](https://huggingface.co/zai-org/GLM-OCR) on seven scanned pages from [NASA’s *Food for Space Flight* booklet](https://huggingface.co/datasets/uv-scripts/ocr-demo). Replace `your-username` with your Hugging Face username:
19
 
20
  ```bash
21
+ hf jobs uv run --flavor a10g-small --timeout 15m --secrets HF_TOKEN \
 
 
22
  https://huggingface.co/datasets/uv-scripts/ocr/raw/main/glm-ocr.py \
23
+ uv-scripts/ocr-demo your-username/ocr-demo-results
24
+ ```
25
+
26
+ The Job adds a `markdown` column to all seven rows and saves them in `your-username/ocr-demo-results`. Dependency installation and model loading can take a few minutes before OCR starts. The [dataset card](https://huggingface.co/datasets/uv-scripts/ocr-demo) documents the source and licence. Check the extracted text against the originals, especially tables and reading order.
27
+
28
+ ### Try the same pages as a PDF
29
+
30
+ The [OCR demo Bucket](https://huggingface.co/buckets/uv-scripts/ocr-demo) holds the
31
+ original PDF, a seven-page extract matching the dataset, and the page images.
32
+ Mount the `demo/` prefix to process just the extract, and create your own Bucket
33
+ for the results:
34
+
35
+ ```bash
36
+ hf buckets create your-username/ocr-output --private
37
+ hf jobs uv run --flavor a10g-small --timeout 15m --secrets HF_TOKEN \
38
+ -v hf://buckets/uv-scripts/ocr-demo/demo:/input:ro \
39
+ -v hf://buckets/your-username/ocr-output/pdf:/output:rw \
40
+ https://huggingface.co/datasets/uv-scripts/ocr/raw/main/glm-ocr-bucket.py \
41
+ /input /output
42
  ```
43
 
44
+ This writes `food-for-space-flight/page_001.md` through `page_007.md` under your
45
+ output Bucket's `pdf/` prefix. See [Get and check your results](#get-and-check-your-results)
46
+ for how to download them.
47
+
48
+ ## Use your own documents
49
+
50
+ **Images in a Hub dataset:** replace the input dataset ID in the [Quick Start](#quick-start) command and choose a new output dataset ID. Start with `--max-samples 10` to limit OCR processing; loading the input dataset may still download more rows. The defaults expect a `train` split and an `image` column; use `--split` and `--image-column` if yours differ. If the input already has a `markdown` column, choose a different `--output-column`, such as `glm_markdown`. Add `--private` to create a private output dataset.
51
 
52
+ **Scans or PDFs on your machine:** put a few images or a short PDF in `./my-scans` for the first run. This recipe processes every supported file in that folder, including subfolders, and every page of each PDF. Create the output folder before launching:
53
+
54
+ ```bash
55
+ mkdir -p ./ocr-output
56
+ hf jobs uv run --flavor a10g-small --timeout 15m --secrets HF_TOKEN \
57
+ -v ./my-scans:/input -v ./ocr-output:/output:rw \
58
+ https://huggingface.co/datasets/uv-scripts/ocr/raw/main/glm-ocr-bucket.py \
59
+ /input /output
60
+ ```
61
 
62
+ The CLI uploads the local folders to a private bucket and makes them available inside the Job. `:rw` lets the Job write output. The script saves one `.md` file per image, or per PDF page. See [mounting local data](https://huggingface.co/docs/huggingface_hub/en/guides/jobs#mount-local-data) for more detail.
63
 
64
+ ## Get and check your results
65
+
66
+ Open the Job page linked by the CLI to see its status and logs. You can also check from your terminal:
67
+
68
+ ```bash
69
+ hf jobs inspect JOB_ID
70
+ hf jobs logs JOB_ID
71
+ ```
72
+
73
+ Once the Job has completed:
74
+
75
+ - **Dataset output:** open `https://huggingface.co/datasets/your-username/ocr-demo-results` and inspect the images alongside their `markdown` results. Use your chosen dataset and column names if you changed them.
76
+ - **Bucket output:** browse your output Bucket or download the files with `hf buckets sync hf://buckets/your-username/ocr-output/pdf ./ocr-output`.
77
+ - **Local-folder output:** run the `hf buckets sync` command printed by the CLI at launch. It downloads the results into `./ocr-output`; they are not synced back automatically. Images produce files such as `page.md`; a PDF produces files such as `report/page_001.md`.
78
+
79
+ Check for empty results or `[OCR ERROR]` markers and compare a few outputs with their source pages before scaling up. The GLM recipes can finish with failed batches, so a completed Job does not guarantee that every page was processed successfully.
80
 
81
  ## Models at a glance
82
 
83
+ **Other models to try after the GLM-OCR example:** **`lighton-ocr2.py`** (1B, very fast), **`paddleocr-vl-1.6.py`** (0.9B, 96.33 OmniDocBench) or **`ovis-ocr2.py`** (0.9B, 96.58 OmniDocBench — current SOTA); for the smallest footprint, **`falcon-ocr.py`** (0.3B, strong on tables). Reach for a 7–8B model only when quality demands it. Several of these models sit on the public [olmOCR-Bench](https://huggingface.co/datasets/allenai/olmOCR-bench) — pull the live ranking from your terminal in one command:
84
 
85
  ```bash
86
  hf datasets leaderboard allenai/olmOCR-bench
 
212
  | `--create-pr` | Push as PR instead of direct commit |
213
  | `--verbose` | Log resolved package versions after run |
214
 
215
+ Open the [script source](https://huggingface.co/datasets/uv-scripts/ocr/blob/main/glm-ocr.py) to inspect its arguments without installing dependencies. On a machine with compatible dependencies, `uv run <script-url> --help` shows its CLI options; `uv` resolves dependencies even for `--help`.
 
 
 
 
216
 
217
  ## NuExtract3: markdown OCR + structured extraction
218
 
 
278
  - **Reproducible sampling** — `--shuffle` (with `--seed`, default 42) draws a representative sample instead of the first N rows.
279
  - **Automatic dataset cards** — every run writes a card with the model config, processing stats, column descriptions, and a reproduction command.
280
 
281
+ ## Batch processing and live endpoints
282
+
283
+ Start with the batch examples above to process a collection of documents. For
284
+ concurrent processing or an API for your application:
285
+
286
+ - **Process a dataset:** `-server.py` recipes start vLLM inside the Job and send
287
+ page requests concurrently. See the [server-mode OCR guide](SERVING.md) for
288
+ supported models, setup and measured throughput. The
289
+ [LightOnOCR-2](https://huggingface.co/datasets/uv-scripts/ocr/blob/main/lighton-ocr2-saturate.py)
290
+ and [OvisOCR2](https://huggingface.co/datasets/uv-scripts/ocr/blob/main/ovis-ocr2-saturate.py)
291
+ `-saturate.py` variants add automatic concurrency and resumable output; their
292
+ script headers explain how to run them and read their results.
293
+ - **Call OCR from an app or agent:** expose a model server with
294
+ [Jobs serving](https://huggingface.co/docs/hub/jobs-serving). The endpoint stays
295
+ available until you cancel the Job or its timeout is reached. The
296
+ [Unlimited-OCR walkthrough](serving-unlimited-ocr.md) covers server setup,
297
+ requests and parsing several pages together in one request.
298
+
299
+ The [PDF example above](#try-the-same-pages-as-a-pdf) processes pages independently
300
+ in a batch Job.
301
+
302
  ## More examples
303
 
304
  ```bash