# ═══════════════════════════════════════════════════════════════ # GovBridge India — Production Dockerfile # Target: Hugging Face Spaces (CPU Basic: 2 vCPU, 16GB RAM) # Constraint: ZERO CUDA binaries. CPU-only PyTorch wheels. # ═══════════════════════════════════════════════════════════════ FROM python:3.11-slim WORKDIR /app # ── Layer 1: OS Dependencies (ROOT) ────────────────────────── # libgomp1: Required for OpenMP multi-threading (PyTorch CPU) # build-essential + git: Required for pip builds RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ git \ libgomp1 \ && rm -rf /var/lib/apt/lists/* # ── Layer 2: CPU-Only PyTorch Installation ─────────────────── # CRITICAL: This MUST run BEFORE requirements.txt to prevent # pip from resolving torch from the default PyPI index (which # downloads 1.2GB+ of CUDA/NVIDIA binaries and exhausts disk). RUN pip install --no-cache-dir \ torch>=2.2.0 \ --extra-index-url https://download.pytorch.org/whl/cpu # ── Layer 3: Python Dependencies ───────────────────────────── COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # ── Layer 4a: Pre-cache Nomic Embedding model ──────────────── RUN python -c "\ from sentence_transformers import SentenceTransformer; \ SentenceTransformer('nomic-ai/nomic-embed-text-v1', cache_folder='/app/models', trust_remote_code=True); \ print('✓ Nomic Embedding model (768-dim) cached')" # ── Layer 4b: Pre-cache Ettin Reranker (ModernBERT) ────────── # trust_remote_code=True is MANDATORY for ModernBERT architecture. RUN python -c "\ from sentence_transformers import CrossEncoder; \ CrossEncoder('cross-encoder/ettin-reranker-68m-v1', max_length=512, trust_remote_code=True); \ print('✓ Ettin Reranker (ModernBERT) cached')" # NOTE: IndicTrans2 model caching REMOVED (Sprint 18 v2). # Translation is now handled by Groq LLM (llama-3.3-70b-versatile) # which requires zero local model files. This saves ~1.6GB of image size # and eliminates the transformers.onnx compatibility nightmare. # ── Layer 5: Copy application code LAST ────────────────────── # Code changes don't invalidate the expensive model cache layers. COPY . . EXPOSE 7860 CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "7860"]