DeepSeek Dockerized OCR API
Relevant source files
The following files were used as context for generating this wiki page:
The DeepSeek Dockerized OCR API is a high-performance Optical Character Recognition (OCR) solution integrated into the OpenMRS ecosystem to facilitate the conversion of PDF documents and images into structured Markdown format. It leverages the DeepSeek-OCR model with a vLLM backend and a FastAPI web interface to provide scalable, GPU-accelerated document processing capabilities. Sources: README.md:1-10, README.md:3-8
Within the broader project architecture, this API serves as a critical component of the AI/ML backend, enabling clinical staff to digitize physical records and extract medical data directly into the Electronic Health Record (EHR) system. Sources: AGENTS.md:5-10, deployment/HOSPITAL-DEPLOYMENT-GUIDE.md:20-30
System Architecture
The system is designed as a containerized microservice that interacts with NVIDIA GPUs via the NVIDIA Container Toolkit. It consists of a FastAPI application serving as the entry point, which manages requests and interfaces with the vLLM-powered DeepSeek-OCR model. Sources: openMRS-main/DeekSeek-OCR---Dockerized-API-main/README.md:12-25, openMRS-main/DeekSeek-OCR---Dockerized-API-main/DOCKER_README.md:1-10
Component Relationship
The diagram below illustrates the relationship between the client, the FastAPI application, and the underlying OCR model infrastructure.
Functional Modules
1. Document Processing Scripts
The system provides specialized Python scripts for different processing workflows, primarily focused on converting PDFs to Markdown or plain text. Sources: openMRS-main/DeekSeek-OCR---Dockerized-API-main/README.md:65-70
| Processor | Primary Prompt | Output Suffix | Core Use Case |
|---|---|---|---|
pdf_to_markdown_processor.py | `< | grounding | >Convert the document to markdown.` |
pdf_to_ocr_enhanced.py | Free OCR. | -OCR.md | Raw text extraction. |
pdf_to_custom_prompt.py | Customizable (YAML) | -CUSTOM.md | Specialized data extraction tasks. |
Sources: openMRS-main/DeekSeek-OCR---Dockerized-API-main/README.md:162-172
2. REST API Endpoints
The FastAPI backend exposes several endpoints to allow integration with external dashboards and frontend microfrontends. Sources: openMRS-main/DeekSeek-OCR---Dockerized-API-main/DOCKER_README.md:60-70
Configuration and Deployment
Hardware Requirements
Due to the model size and inference requirements, specific hardware configurations are necessary for stable operation. Sources: openMRS-main/DeekSeek-OCR---Dockerized-API-main/README.md:27-35
- GPU: NVIDIA GPU with CUDA 11.8+; Minimum 12GB VRAM (16GB+ recommended for production).
- RAM: Minimum 32GB System RAM.
- Storage: 50GB+ for model weights and Docker images.
Sources: openMRS-main/DeekSeek-OCR---Dockerized-API-main/DOCKER_README.md:5-15
Runtime Environment Variables
The Docker container behavior is tuned via environment variables in docker-compose.yml. Sources: openMRS-main/DeekSeek-OCR---Dockerized-API-main/README.md:412-420
| Variable | Description | Default/Example |
|---|---|---|
CUDA_VISIBLE_DEVICES | Specifies which GPU to utilize. | 0 |
MODEL_PATH | Path to the local DeepSeek-OCR model weights. | /app/models/deepseek-ai/DeepSeek-OCR |
MAX_CONCURRENCY | Maximum number of concurrent requests. | 50 |
GPU_MEMORY_UTILIZATION | Fraction of GPU memory to reserve (0.1 - 1.0). | 0.85 |
Sources: openMRS-main/DeekSeek-OCR---Dockerized-API-main/DOCKER_README.md:115-125
Critical Fixes and Customizations
The project implements a "transparent replacement approach" during the Docker build process to fix bugs in the original DeepSeek-OCR library, most notably a missing prompt parameter in the tokenize_with_images() method which previously caused server startup failures. Sources: openMRS-main/DeekSeek-OCR---Dockerized-API-main/README.md:365-375
Automated Build Logic
The Dockerfile performs several file overrides to ensure stability:
custom_config.py: Replaces the defaultconfig.pyto allow customizable prompts.custom_image_process.py: Fixes the image processing module's handling of prompt parameters.- Enhanced Run Scripts: Replaces standard run scripts with versions that accept
--promptarguments.
Sources: openMRS-main/DeekSeek-OCR---Dockerized-API-main/README.md:384-405
Usage Workflow
The typical usage involves starting the container and then interacting via the health check or OCR endpoints.
# Verify the service is healthy
curl http://localhost:8000/health
# Process a document
curl -X POST "http://localhost:8000/ocr/pdf" \
-H "Content-Type: multipart/form-data" \
-F "file=@medical_report.pdf"
Sources: openMRS-main/DeekSeek-OCR---Dockerized-API-main/README.md:46-55, openMRS-main/DeekSeek-OCR---Dockerized-API-main/DOCKER_README.md:82-90
Summary
The DeepSeek Dockerized OCR API provides a robust, GPU-optimized backend for document digitization within the OpenMRS ecosystem. By implementing critical bug fixes directly into the container build process and exposing flexible REST endpoints, it enables the system to handle complex medical documents with high accuracy and structure preservation through Markdown output. Sources: README.md:1-10, openMRS-main/DeekSeek-OCR---Dockerized-API-main/README.md:450-465