A production-ready OCR service using DeepSeek-OCR model for extracting text from images and PDFs with markdown formatting.
- 🚀 Fast inference with GPU acceleration (NVIDIA)
- 📄 PDF support with automatic page conversion
- 🖼️ Image support (JPEG, PNG, and more)
- 📝 Markdown-formatted output preserving document layout
- 🔧 Docker containerized for easy deployment
- 🤖 Automated CI/CD via GitHub Actions → DockerHub
- Framework: FastAPI with Uvicorn
- Model: DeepSeek-OCR
- GPU: Single GPU allocation (configurable)
- Port: 5010
- Deployment: Docker container with Portainer stack
- NVIDIA GPU with CUDA 11.8+
- Docker with NVIDIA Container Toolkit
- Portainer (optional, for stack management)
- Add DockerHub credentials to Portainer secrets
- Create new stack from
docker-compose.yml - Deploy and wait for health checks to pass
# Or deploy directly with Docker Compose
docker-compose up -d# Health check
curl http://localhost:5010/health
# Or open in browser
# http://localhost:5010/docsProcess an image or PDF file for OCR.
Request:
curl -X POST "http://localhost:5010/ocr" \
-H "accept: application/json" \
-F "file=@document.pdf"Response:
{
"status": "success",
"pages": 3,
"text": "# Document Title\n\nContent here...",
"file_type": "pdf"
}Check service health and GPU status.
Response:
{
"status": "healthy",
"gpu_available": true,
"model_loaded": true
}Interactive API documentation (Swagger UI).
import requests
# Process an image
with open('document.jpg', 'rb') as f:
response = requests.post(
'http://localhost:5010/ocr',
files={'file': f}
)
result = response.json()
print(result['text'])# Process PDF
curl -X POST "http://localhost:5010/ocr" \
-F "file=@document.pdf"
# Process image
curl -X POST "http://localhost:5010/ocr" \
-F "file=@screenshot.png"CUDA_VISIBLE_DEVICES: GPU device to use (default: 0)PYTHONUNBUFFERED: Python output buffering
The service uses "Gundam mode" for optimal quality/speed balance:
base_size=1024image_size=640crop_mode=True
These settings are optimized for large documents and can be modified in app/ocr_service.py.
# Install dependencies
pip install -r requirements.txt
# Run service
python app/main.py
# Or with uvicorn
uvicorn app.main:app --reload --port 5010# Build locally
docker build -t deepseek-ocr .
# Run locally
docker run --gpus all -p 5010:5010 deepseek-ocr# Use the test script
python test_api.py- First request: Model loading takes ~30-60 seconds
- Subsequent requests: ~2-5 seconds per page
- GPU memory: ~8-12GB per GPU
- Concurrent requests: Single GPU handles sequential processing
# Check NVIDIA driver
nvidia-smi
# Check Docker GPU support
docker run --rm --gpus all nvidia/cuda:11.8.0-base-ubuntu22.04 nvidia-smiThe model will download on first request (~3GB). Ensure network access to Hugging Face.
Reduce batch size or use smaller image_size in ocr_service.py.
MIT
- DeepSeek-OCR by DeepSeek AI
- PyMuPDF for PDF processing
- FastAPI for the web framework