--- title: Document OCR emoji: 📄 colorFrom: indigo colorTo: blue sdk: gradio sdk_version: 6.15.1 app_file: app.py python_version: "3.12" short_description: Persian and English OCR for images and PDFs license: apache-2.0 pinned: false startup_duration_timeout: 1h models: - PaddlePaddle/PaddleOCR-VL-1.6 tags: - ocr - document - persian - farsi - english - pdf - table - markdown --- # Document OCR Public document OCR with an English interface and a full Persian UI. Persian is supported, including mixed Persian–English pages. Upload images or PDFs and download a searchable PDF, Word, Markdown, JSON, and Unicode text. Author: [Alireza Aminzadeh](https://huggingface.co/alirezaaminzadeh) ## What you get - Images (`JPG`, `PNG`, `WEBP`, `BMP`, `TIFF`, `HEIC`) plus PDF - Camera capture, clipboard, and multi-file batch - Persian, English, mixed, or auto-detect - Modes: document text, precise overlay, tables, Markdown, form fields, and compare - Optional deskew/contrast enhancement and high-accuracy tiled reading - Searchable PDF, `.txt`, `.md`, `.json`, `.docx`, and a ZIP of every file - Editable text with rebuild (no second model run) - Session history, bilingual UI, and a `/health` API - No persistent storage of uploaded files ## Limits - Up to `8` pages or files per job - Maximum `25 MB` per file - Longest side is resized to `1920` pixels (`2560` in high-accuracy mode) - Best results on flat, sharp, well-lit pages ## Model The Space runs [PaddleOCR-VL-1.6](https://huggingface.co/PaddlePaddle/PaddleOCR-VL-1.6) through Transformers on ZeroGPU. The official PaddlePaddle page-parser is not used, so the app stays compatible with Hugging Face ZeroGPU. ## Privacy Uploads are written only to a temporary working directory for the current request and discarded after a short TTL. ## Local run Copy `.env.example` to `.env`, then: ```bash docker compose up --build ``` The app is available at [http://localhost](http://localhost). Optional GPU runtime (NVIDIA Docker required): ```bash docker compose -f docker-compose.yml -f docker-compose.gpu.yml up --build ``` Optional production locks in `.env`: - `OCR_API_KEY` — required on every extract call when set - `APP_AUTH_USER` / `APP_AUTH_PASSWORD` — HTTP basic auth for the UI Monitor containers with `docker stats`. ## API Gradio exposes named endpoints once the app is running: - `/ocr` — extract text and files - `/rebuild` — rebuild exports from edited text - `/health` — JSON status and process metrics Example: ```python from gradio_client import Client, handle_file client = Client("http://localhost") status, warnings, text, preview, pdf, txt, md, json_file, docx, archive, job, history, table = client.predict( handle_file("scan.png"), None, "auto", "document", True, False, "", "en", [], api_name="/ocr", ) ``` ## Tests ```bash python -m pip install -r requirements-test.txt python scripts/make_assets.py python -m unittest discover -s tests -v ``` ## License Apache License 2.0. See `LICENSE` and `NOTICE`.