Skip to content

Commit fa313c8

Browse files
committed
refactor: remove local transformers backend, migrate to DeepSeek-OCR-2, and establish GPU-first deployment via Docker Compose.
1 parent 8cc10a7 commit fa313c8

32 files changed

Lines changed: 651 additions & 708 deletions

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
All notable changes to OpenCR are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/), and the project follows [Semantic Versioning](https://semver.org/).
44

5+
## [Unreleased]
6+
7+
### Changed
8+
9+
- **Breaking:** OpenCR is GPU-first again. The in-process Apple Silicon / CPU
10+
`MODEL_BACKEND=local` path, CPU Docker profile, and local `transformers`
11+
dependency file were removed.
12+
- Default OCR model is now `deepseek-ai/DeepSeek-OCR-2`.
13+
- `docker compose up -d` now starts the NVIDIA/vLLM stack directly; no compose
14+
profile is required.
15+
516
## [v1.0.0]
617

718
### Added

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ expected text is one of the highest-leverage contributions.
1919
PaddleOCR / Marker on a Turkish corpus and post the table — even
2020
informal numbers are useful.
2121

22-
- **Model-backend ports.** MLX, llama.cpp, ONNX, or any other runtime
23-
that improves throughput on a target platform.
22+
- **Deployment recipes.** vLLM, hosted GPU endpoints, and reproducible
23+
benchmark environments that improve throughput or quality.
2424

2525
- **Translations.** README and dataset cards in additional languages.
2626

@@ -33,7 +33,7 @@ make install
3333
make test
3434
```
3535

36-
`make run` starts a local dev server on http://localhost:39672 with the `local` model backend (no GPU needed; ~5–30 s/page on M-series Macs).
36+
`make run` starts a local dev server on http://localhost:39672 and points it at `MODEL_SERVER_URL` (default: `http://localhost:39671`). Start the bundled GPU stack with `docker compose up -d`, or provide another OpenAI-compatible GPU endpoint.
3737

3838
## Code style
3939

Makefile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
1-
.PHONY: help install install-local run run-remote test lint format docker-up docker-down clean
1+
.PHONY: help install run run-remote test lint format docker-up docker-down clean
22

33
PY ?= python3
44
VENV ?= .venv
55
PIP := $(VENV)/bin/pip
66
PYBIN := $(VENV)/bin/python
7+
MODEL_SERVER_URL ?= http://localhost:39671
78

89
help:
910
@echo "OpenCR developer targets:"
10-
@echo " make install # venv + base deps + local-backend deps (Mac/CPU friendly)"
11-
@echo " make run # start dev server on http://localhost:39672 with the local backend"
11+
@echo " make install # venv + base/dev deps"
12+
@echo " make run # start dev server on http://localhost:39672, using MODEL_SERVER_URL"
1213
@echo " make run-remote # start dev server pointing at MODEL_SERVER_URL"
1314
@echo " make test # run pytest suite"
1415
@echo " make lint # ruff check"
1516
@echo " make format # ruff format"
16-
@echo " make docker-up # docker compose up (NVIDIA GPU profile)"
17+
@echo " make docker-up # docker compose up (NVIDIA GPU stack)"
1718
@echo " make docker-down # docker compose down"
1819

1920
$(VENV):
2021
$(PY) -m venv $(VENV)
2122
$(PIP) install -U pip
2223

2324
install: $(VENV)
24-
$(PIP) install -r ocr_pipeline/requirements.txt -r requirements-local.txt
25+
$(PIP) install -r ocr_pipeline/requirements.txt
2526
$(PIP) install -r requirements-dev.txt
2627

2728
run: $(VENV)
28-
MODEL_BACKEND=local $(PYBIN) -m uvicorn ocr_pipeline.main:app --host 0.0.0.0 --port 39672 --reload
29+
MODEL_BACKEND=remote MODEL_SERVER_URL=$(MODEL_SERVER_URL) $(PYBIN) -m uvicorn ocr_pipeline.main:app --host 0.0.0.0 --port 39672 --reload
2930

3031
run-remote: $(VENV)
31-
MODEL_BACKEND=remote $(PYBIN) -m uvicorn ocr_pipeline.main:app --host 0.0.0.0 --port 39672 --reload
32+
MODEL_BACKEND=remote MODEL_SERVER_URL=$(MODEL_SERVER_URL) $(PYBIN) -m uvicorn ocr_pipeline.main:app --host 0.0.0.0 --port 39672 --reload
3233

3334
test: $(VENV)
3435
PYTHONPATH=. $(PYBIN) -m pytest -q
@@ -40,7 +41,7 @@ format: $(VENV)
4041
$(VENV)/bin/ruff format ocr_pipeline tests scripts
4142

4243
docker-up:
43-
docker compose --profile gpu up -d
44+
docker compose up -d
4445

4546
docker-down:
4647
docker compose down

README.md

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ For Turkish documents, see: [README.tr.md](./README.tr.md)
1010

1111
## Why OpenCR?
1212

13-
- **Turkish-first accuracy.** Built around DeepSeek-OCR, it handles Turkish characters and difficult page layouts better than off-the-shelf OCR.
13+
- **Turkish-first accuracy.** Built around DeepSeek-OCR-2, it handles Turkish characters and difficult page layouts better than off-the-shelf OCR.
1414
- **Dataset factory.** Outputs are packaged directly as `pages.parquet` + `documents.parquet` with deterministic train/validation/test splits and a HuggingFace dataset card.
1515
- **Operator console.** A single-page web UI to monitor runs, page-by-page validate quality, retry, and publish to HuggingFace.
16-
- **Pluggable backends.** Production-grade NVIDIA + vLLM by default; runs in-process on Apple Silicon / CPU for development; or talk to any OpenAI-compatible model server.
16+
- **GPU-first backend.** Production-grade NVIDIA + vLLM by default, with an optional remote mode for any OpenAI-compatible GPU model server.
1717

1818
---
1919

2020
## Quickstart
2121

22-
### Option 1 — Docker (NVIDIA GPU, fastest path to inference)
22+
### Option 1 — Docker (NVIDIA GPU, primary path)
2323

2424
Requires Docker, an NVIDIA GPU, and the NVIDIA Container Toolkit.
2525

@@ -29,27 +29,10 @@ docker compose up -d
2929

3030
Open http://localhost:39672. Drop PDFs in `./input/`, hit **Start OCR run**.
3131

32-
### Option 2 — Apple Silicon / CPU (in-process inference, no GPU needed)
33-
34-
For local development, demos, and small jobs on a Mac or Linux box with no GPU.
35-
36-
```bash
37-
git clone https://github.com/cdliai/opencr.git
38-
cd opencr
39-
python3 -m venv .venv && source .venv/bin/activate
40-
pip install -r ocr_pipeline/requirements.txt -r requirements-local.txt
41-
MODEL_BACKEND=local ./scripts/start.sh
42-
```
43-
44-
Open http://localhost:39672. The DeepSeek-OCR model (~6 GB) downloads
45-
on first request and runs in-process via `transformers` on MPS (Apple Silicon)
46-
or CPU. Expect **5–30 seconds per page on M-series, much slower on CPU**
47-
fine for development, not for production batch jobs.
48-
49-
### Option 3 — Remote model server (point at any OpenAI-compatible endpoint)
32+
### Option 2 — Remote model server (point at any OpenAI-compatible endpoint)
5033

5134
If you already run vLLM somewhere, or use OpenRouter, or another endpoint
52-
serving DeepSeek-OCR:
35+
serving DeepSeek-OCR-2:
5336

5437
```bash
5538
pip install -r ocr_pipeline/requirements.txt
@@ -64,12 +47,10 @@ Configurable via environment variables (or a `.env` file):
6447

6548
| Variable | Default | Description |
6649
| -------------------- | -------------------------------- | ------------------------------------------------------------------------------------------------- |
67-
| `MODEL_BACKEND` | `vllm` | `vllm` (NVIDIA, OpenAI-compatible server), `local` (in-process transformers), `remote` (alias). |
50+
| `MODEL_BACKEND` | `vllm` | `vllm` for the bundled NVIDIA model server, or `remote` for another OpenAI-compatible endpoint. |
6851
| `MODEL_SERVER_URL` | `http://ocr-model:39671` | Base URL for `vllm` / `remote` backends. |
69-
| `MODEL_NAME` | `deepseek-ai/DeepSeek-OCR` | Model identifier. |
52+
| `MODEL_NAME` | `deepseek-ai/DeepSeek-OCR-2` | Model identifier. |
7053
| `MODEL_API_KEY` | `EMPTY` | API key for remote endpoints. |
71-
| `LOCAL_DEVICE` | auto | `auto`, `mps`, `cuda`, or `cpu` for the `local` backend. |
72-
| `LOCAL_ATTN_IMPLEMENTATION` | auto | `auto`, `eager`, `sdpa`, or `flash_attention_2`. Auto uses FlashAttention only when `flash_attn` is installed. |
7354
| `INPUT_DIR` | `./input` (or `/data/input`) | Where to read PDFs from. |
7455
| `OUTPUT_DIR` | `./output` (or `/data/output`) | Where artifacts and the SQLite DB land. |
7556
| `HOST` / `PORT` | `0.0.0.0` / `39672` | Where the web console serves. |
@@ -117,9 +98,8 @@ Published datasets are tagged `opencr` so they're discoverable via [HuggingFace'
11798
┌───────────────────────────────┐
11899
│ Model backend │
119100
│ ┌─────────────────────────┐ │
120-
│ │ vllm (NVIDIA, prod) │ │
121-
│ │ local (MPS/CPU, dev) │ │
122-
│ │ remote (any OpenAI URL) │ │
101+
│ │ vLLM (NVIDIA, default) │ │
102+
│ │ remote (OpenAI URL) │ │
123103
│ └─────────────────────────┘ │
124104
└───────────────────────────────┘
125105
```
@@ -146,8 +126,8 @@ Tests live under `tests/`. UI is plain HTML + Alpine.js — no build step.
146126
## Contributing
147127

148128
Contributions are welcome — bug reports, Turkish-language
149-
test fixtures, benchmarks against other OCR engines, model-backend
150-
ports (MLX, llama.cpp), and documentation translations are
129+
test fixtures, benchmarks against other OCR engines, deployment
130+
recipes, and documentation translations are
151131
especially useful.
152132

153133
See [CONTRIBUTING.md](./CONTRIBUTING.md).

README.tr.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ OpenCR, özellikle Türkçe metinler, arşiv dökümanları ve karmaşık sayfa
44

55
## Neden OpenCR?
66

7-
- **Türkçe Odaklı Doğruluk:** DeepSeek-OCR tabanlı yapısıyla, standart OCR araçlarının zorlandığı Türkçe karakterlerde ve karmaşık sayfa düzenlerinde üstün performans sağlar.
7+
- **Türkçe Odaklı Doğruluk:** DeepSeek-OCR-2 tabanlı yapısıyla, standart OCR araçlarının zorlandığı Türkçe karakterlerde ve karmaşık sayfa düzenlerinde güçlü bir başlangıç noktası sağlar.
88
- **Veri Seti Fabrikası:** Çıkarılan metinleri doğrudan `.parquet` formatında paketler ve tek tıkla HuggingFace'e yüklemeye hazır hale getirir.
99
- **Operatör Konsolu:** İşlemleri izlemek, sayfa sayfa kontrol etmek ve hataları düzeltmek için modern bir web arayüzü sunar.
1010

1111
## Kurulum
1212

13-
### Docker ile Çalıştırma (GPU Gerekir)
13+
### Docker ile Çalıştırma (NVIDIA GPU Gerekir)
1414
```bash
15-
docker-compose up -d
15+
docker compose up -d
1616
```
1717

18-
### Lokal Geliştirme ve Web Arayüzü (Apple Silicon / CPU)
19-
Pipeline arayüzünü Apple bilgisayarınızda veya CPU üzerinde denemek için:
18+
### Harici Model Sunucusu ile Geliştirme
19+
Zaten çalışan OpenAI-compatible bir vLLM / GPU endpoint'iniz varsa:
2020

2121
1. **Klasör ve Ortam Hazırlığı:**
2222
```bash
@@ -30,13 +30,12 @@ Pipeline arayüzünü Apple bilgisayarınızda veya CPU üzerinde denemek için:
3030
```bash
3131
export INPUT_DIR="./input"
3232
export OUTPUT_DIR="./output"
33-
export PYTHONPATH=$PYTHONPATH:.
34-
python3 ocr_pipeline/main.py
33+
MODEL_BACKEND=remote MODEL_SERVER_URL="https://your-endpoint" ./scripts/start.sh
3534
```
3635
Erişim: **http://localhost:39672**
3736

3837
## Mimari
39-
- **Backend:** vLLM tabanlı DeepSeek-OCR (Ağır iş yükü).
38+
- **Backend:** vLLM tabanlı DeepSeek-OCR-2 (GPU-first).
4039
- **Frontend/API:** FastAPI & Alpine.js (Yönetim konsolu).
4140

4241
---

docker-compose.yml

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
# Two profiles ship out of the box:
2-
#
3-
# docker compose --profile gpu up -d # production: vLLM model server + pipeline (NVIDIA)
4-
# docker compose --profile cpu up -d # CPU/Mac: pipeline only, in-process transformers backend
5-
#
6-
# Without an explicit --profile, no services run. Always pick one.
1+
# GPU-first OpenCR stack: vLLM model server + pipeline.
2+
# Requires Docker, an NVIDIA GPU, and the NVIDIA Container Toolkit.
73

84
services:
95
ocr-model:
10-
profiles: ["gpu"]
116
build: ./ocr-model
127
runtime: nvidia
138
restart: unless-stopped
@@ -39,7 +34,6 @@ services:
3934
start_period: 600s
4035

4136
ocr-pipeline:
42-
profiles: ["gpu"]
4337
build: ./ocr_pipeline
4438
restart: unless-stopped
4539
ports:
@@ -50,30 +44,12 @@ services:
5044
environment:
5145
- MODEL_BACKEND=vllm
5246
- MODEL_SERVER_URL=http://ocr-model:39671
47+
- MODEL_NAME=deepseek-ai/DeepSeek-OCR-2
5348
- INPUT_DIR=/data/input
5449
- OUTPUT_DIR=/data/output
5550
depends_on:
5651
ocr-model:
5752
condition: service_healthy
5853

59-
ocr-pipeline-cpu:
60-
profiles: ["cpu"]
61-
build:
62-
context: .
63-
dockerfile: ocr_pipeline/Dockerfile.cpu
64-
restart: unless-stopped
65-
ports:
66-
- "39672:39672"
67-
volumes:
68-
- ./input:/data/input
69-
- ./output:/data/output
70-
- hf-cache:/root/.cache/huggingface
71-
environment:
72-
- MODEL_BACKEND=local
73-
- LOCAL_DEVICE=cpu
74-
- INPUT_DIR=/data/input
75-
- OUTPUT_DIR=/data/output
76-
- HF_HOME=/root/.cache/huggingface
77-
7854
volumes:
7955
hf-cache:

0 commit comments

Comments
 (0)