Model Loader: - Update model_loader.py with complete dots.ocr loading code - Proper device detection (CUDA/CPU/MPS) with fallback - Memory optimization (low_cpu_mem_usage) - Better error handling and logging - Support for local model paths and HF Hub Docker: - Multi-stage Dockerfile (CPU/CUDA builds) - docker-compose.yml for parser-service - .dockerignore for clean builds - Model cache volume for persistence Configuration: - Support DOTS_OCR_MODEL_ID and DEVICE env vars (backward compatible) - Better defaults and environment variable handling Deployment: - Add DEPLOYMENT.md with detailed instructions - Local deployment (venv) - Docker Compose deployment - Ollama runtime setup - Troubleshooting guide Integration: - Add parser-service to main docker-compose.yml - Configure volumes and networks - Health checks and dependencies
65 lines
1.5 KiB
Docker
65 lines
1.5 KiB
Docker
# Multi-stage build for PARSER Service
|
|
# Stage 1: Base with system dependencies
|
|
FROM python:3.11-slim as base
|
|
|
|
WORKDIR /app
|
|
|
|
# Install system dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
poppler-utils \
|
|
libgl1-mesa-glx \
|
|
libglib2.0-0 \
|
|
git \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Stage 2: CPU-only build
|
|
FROM base as cpu
|
|
|
|
# Copy requirements and install CPU-only dependencies
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir \
|
|
torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu && \
|
|
pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Copy application code
|
|
COPY . .
|
|
|
|
# Create temp directory and model cache
|
|
RUN mkdir -p /tmp/parser /root/.cache/huggingface
|
|
|
|
# Expose port
|
|
EXPOSE 9400
|
|
|
|
# Run application
|
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "9400"]
|
|
|
|
# Stage 3: CUDA build (optional, use --target=cuda)
|
|
FROM base as cuda
|
|
|
|
# Install CUDA dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
nvidia-cuda-toolkit \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy requirements and install CUDA dependencies
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir \
|
|
torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 && \
|
|
pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Copy application code
|
|
COPY . .
|
|
|
|
# Create temp directory and model cache
|
|
RUN mkdir -p /tmp/parser /root/.cache/huggingface
|
|
|
|
# Expose port
|
|
EXPOSE 9400
|
|
|
|
# Run application
|
|
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "9400"]
|
|
|
|
# Default to CPU build
|
|
FROM cpu
|
|
|