Fast, accurate OCR with correctness assessment.
Web Demo Deployment Tutorial
This guide is a self-hosted Web Demo tutorial. It runs the document-parse page on your own machine.
1. Prepare the environment
Before you start, follow the SDK tutorial to set up the environment and complete a full-page parse. On top of the .minicpm-ocr environment, the backend only needs the page server packages:
source .minicpm-ocr/bin/activate
python -m pip install fastapi uvicorn python-multipart
Prepare the rotation-adaptation models:
bash webdemo/backend/prepare_upright_models.sh
The frontend needs Node.js 22 or later. Corepack provides pnpm 10.32.1:
cd webdemo/frontend
corepack pnpm install
2. Start the recognition service
Choose one of the services below and leave it running. Follow its guide and serve the model as minicpm-ocr at http://127.0.0.1:18499.
| Service | Guide | OCR_ENGINE_TYPE |
|---|---|---|
| vLLM | Deployment guide | vllm |
| SGLang | Deployment guide | openai |
| llama.cpp | GGUF deployment guide | llamacpp |
| Ollama | Deployment guide | ollama |
Confirm the recognition service is up. The model list should include minicpm-ocr:
curl -f http://127.0.0.1:18499/v1/models
# For Ollama, check http://127.0.0.1:18499/api/tags instead.
3. Start the backend
source .minicpm-ocr/bin/activate
export OCRWEB_PYTHON=python
export OCR_ENGINE_TYPE=vllm # Set this from section 2
export OCR_SERVER_URL=http://127.0.0.1:18499
export OCR_SERVED_NAME=minicpm-ocr
export OCR_LAYOUT_MODEL_DIR="$PWD/models/PP-DocLayoutV3_infer" # Directory already downloaded by the SDK tutorial
export OCR_LAYOUT_DEVICE=cuda # On CPU, use cpu and also set OCR_LAYOUT_DEVICES=cpu
export OCR_LAYOUT_WORKERS=1 # Raise this when the GPU has room
export PORT=8966
# Rotation adaptation is on by default. It uses models/paddle_upright from section 1.
bash webdemo/backend/start_local_worker.sh
curl -f http://127.0.0.1:8966/health
# {"status":"ok"} means the process is up.
4. Start the frontend
cd webdemo/frontend
VITE_OCR_TARGET=http://127.0.0.1:8966 corepack pnpm dev --host --port 5173 --strictPort
Open http://localhost:5173/playground/document-parse to try the local Web Demo.
While a document is being parsed the page shows the pages still being recognized: finished blocks appear at once, blocks being decoded grow as their text arrives, and the first pages of a PDF start first. For that order, start the backend with OCR_SHARED_CROP_POOL=0 (start_local_worker.sh defaults to 1; with one recognition queue shared by all jobs, blocks are not ordered by page).
5. API
The backend also provides an API. The endpoints are listed below.
| Endpoint | Purpose |
|---|---|
POST /api/document-parse/jobs |
Async image or PDF. HTTP 200 returns a job |
GET /api/document-parse/jobs/{id} |
HTTP 200 returns progress and results; while the job runs, pages also lists, after the finished pages, the pages still being recognized ("partial": true) with the blocks done so far and the current text of the blocks being decoded |
DELETE /api/document-parse/jobs/{id} |
Cancel the job. HTTP 200 returns the job status |
POST /api/kie |
Sync single image. HTTP 200 returns one page |
Document parsing creates a job for both images and PDFs. The response status is Running. Key information extraction uses POST /api/kie and accepts one image: a JSON body with image and fields. That call does not create a job and does not accept a PDF. The async form of key information extraction can be adapted by following document parsing.