Sync from GitHub via hub-sync
Browse files
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 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
```bash
|
| 19 |
-
|
| 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 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
```
|
| 26 |
|
| 27 |
-
This
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
-
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
## Models at a glance
|
| 39 |
|
| 40 |
-
**
|
| 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 |
-
|
| 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
|