| FROM python:3.11-slim | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential curl git \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # PyTorch with CUDA 12.1 (matches HF T4 environment) | |
| RUN pip install --no-cache-dir \ | |
| torch \ | |
| --index-url https://download.pytorch.org/whl/cu121 | |
| # Model serving dependencies | |
| RUN pip install --no-cache-dir \ | |
| transformers>=4.51.0 \ | |
| peft \ | |
| accelerate \ | |
| huggingface_hub \ | |
| fastapi \ | |
| "uvicorn[standard]" \ | |
| pydantic | |
| WORKDIR /app | |
| COPY app.py . | |
| RUN useradd -m -u 1000 appuser && chown -R appuser /app | |
| USER appuser | |
| EXPOSE 7860 | |
| HEALTHCHECK --interval=30s --timeout=5s --start-period=60s --retries=5 \ | |
| CMD curl -f http://localhost:7860/health || exit 1 | |
| CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] | |