# Use Python 3.12 slim image FROM python:3.12-slim # Env: don't write .pyc and flush logs ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 # HF Spaces default port ENV PORT=7860 WORKDIR /app # System deps (curl for HEALTHCHECK; libgomp for numpy/torch) RUN apt-get update && apt-get install -y --no-install-recommends \ curl libglib2.0-0 libsm6 libxext6 libxrender1 libgomp1 \ && rm -rf /var/lib/apt/lists/* # Copy requirements and install (CPU-only torch wheels) COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy app COPY app.py . # Non-root (optional) RUN useradd --create-home --shell /bin/bash app && chown -R app:app /app USER app EXPOSE 7860 # Health check hits /health on the default port HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ CMD curl -f http://localhost:${PORT}/health || exit 1 # Run FastAPI on port 7860 (HF Spaces requirement) CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]