File size: 2,806 Bytes
99cc0f4
 
 
 
 
 
771c2ee
a40c8e4
 
 
99cc0f4
d05deb5
 
99cc0f4
771c2ee
 
99cc0f4
771c2ee
 
99cc0f4
 
 
 
 
 
 
 
 
a40c8e4
 
 
637ae4f
dda4bd8
b43ac14
adfde89
b43ac14
6399ce4
b43ac14
 
 
d05deb5
b43ac14
 
 
 
a40c8e4
d05deb5
 
 
 
99cc0f4
d05deb5
99cc0f4
a40c8e4
 
 
771c2ee
9b93efe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# ═══════════════════════════════════════════════════════════════
# 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"]