version: "3.8"

services:
  # Ollama LLM server with GPU
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    ports:
      - "11434:11434"
    volumes:
      - ollama_data:/root/.ollama
    environment:
      - NVIDIA_VISIBLE_DEVICES=all
      - CUDA_VISIBLE_DEVICES=0
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    command: serve

  # PDF OCR + Summarization worker
  pdf-worker:
    build:
      context: .
      dockerfile: Dockerfile.pdf
    container_name: pdf-worker
    volumes:
      - ./input:/input:ro
      - ./output:/output
      - ./temp:/temp
    environment:
      - OLLAMA_HOST=http://ollama:11434
      - NVIDIA_VISIBLE_DEVICES=all
      - CUDA_VISIBLE_DEVICES=0
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
    depends_on:
      - ollama
    command: python3 pdf_summarize.py

volumes:
  ollama_data:
