FROM python:3.12-slim

WORKDIR /app

RUN apt-get update && apt-get install -y --no-install-recommends \
    libgl1 libglib2.0-0 curl git && \
    rm -rf /var/lib/apt/lists/*

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt && \
    pip install --no-cache-dir einops ftfy regex && \
    pip install --no-cache-dir "clip @ git+https://github.com/openai/CLIP.git" && \
    pip install --no-cache-dir "deepgaze-pytorch @ git+https://github.com/matthias-k/DeepGaze.git"

# Pre-download DeepGaze IIE weights during build to eliminate cold-start downloads
RUN python -c "\
import deepgaze_pytorch; \
print('Pre-loading DeepGaze IIE weights...'); \
deepgaze_pytorch.DeepGazeIIE(pretrained=True); \
print('Weights cached.')"

COPY main.py .

ENV PYTHONUNBUFFERED=1
ENV PORT=8080

EXPOSE 8080

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]
