--- viewer: false tags: [uv-script, ocr, vision-language-model, document-processing] --- # OCR UV Scripts > Part of [uv-scripts](https://huggingface.co/uv-scripts) - ready-to-run ML tools powered by UV Ready-to-run OCR scripts that work with `uv run` - no setup required! ## 🚀 Quick Start with HuggingFace Jobs Run OCR on any dataset without needing your own GPU: ```bash hf jobs uv run --flavor l4x1 \ https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nanonets-ocr.py \ your-input-dataset your-output-dataset ``` That's it! The script will: - ✅ Process all images in your dataset - ✅ Add OCR results as a new `markdown` column - ✅ Push the results to a new dataset - 📊 View results at: `https://huggingface.co/datasets/[your-output-dataset]` ## 📋 Available Scripts ### Nanonets OCR (`nanonets-ocr.py`) State-of-the-art document OCR using [nanonets/Nanonets-OCR-s](https://huggingface.co/nanonets/Nanonets-OCR-s) that handles: - 📐 **LaTeX equations** - Mathematical formulas preserved - 📊 **Tables** - Extracted as HTML format - 📝 **Document structure** - Headers, lists, formatting maintained - 🖼️ **Images** - Captions and descriptions included - ☑️ **Forms** - Checkboxes rendered as ☐/☑ ## 💻 Usage Examples ### Run on HuggingFace Jobs (Recommended) No GPU? No problem! Run on HF infrastructure: ```bash # Basic OCR job hf jobs uv run --flavor l4x1 \ https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nanonets-ocr.py \ your-input-dataset your-output-dataset # Real example with UFO dataset 🛸 hf jobs uv run \ --flavor a10g-large \ --image vllm/vllm-openai:latest \ -e HF_TOKEN=$(python3 -c "from huggingface_hub import get_token; print(get_token())") \ https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nanonets-ocr.py \ davanstrien/ufo-ColPali \ your-username/ufo-ocr \ --image-column image \ --max-model-len 16384 \ --batch-size 64 # Private dataset with custom settings hf jobs uv run --flavor l40sx1 \ -e HF_TOKEN=$(python3 -c "from huggingface_hub import get_token; print(get_token())") \ https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nanonets-ocr.py \ private-input private-output \ --private \ --batch-size 32 ``` ### Python API ```python from huggingface_hub import run_uv_job job = run_uv_job( "https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nanonets-ocr.py", args=["input-dataset", "output-dataset", "--batch-size", "16"], flavor="l4x1" ) ``` ### Run Locally (Requires GPU) ```bash # Clone and run git clone https://huggingface.co/datasets/uv-scripts/ocr cd ocr uv run nanonets-ocr.py input-dataset output-dataset # Or run directly from URL uv run https://huggingface.co/datasets/uv-scripts/ocr/raw/main/nanonets-ocr.py \ input-dataset output-dataset ``` ## 📁 Works With Any HuggingFace dataset containing images - documents, forms, receipts, books, handwriting. ## 🎛️ Configuration Options | Option | Default | Description | | -------------------------- | ------- | --------------------------- | | `--image-column` | `image` | Column containing images | | `--batch-size` | `8` | Images processed together | | `--max-model-len` | `8192` | Max context length | | `--max-tokens` | `4096` | Max output tokens | | `--gpu-memory-utilization` | `0.7` | GPU memory usage | | `--split` | `train` | Dataset split to process | | `--max-samples` | None | Limit samples (for testing) | | `--private` | False | Make output dataset private | More OCR VLM Scripts coming soon! Stay tuned for updates!