# ─── Stage 1: Base Image ─────────────────────────────────────────────────── FROM python:3.10-slim # Set working directory WORKDIR /app # ─── Environment Variables ───────────────────────────────────────────────── # Prevent Python from writing .pyc files ENV PYTHONDONTWRITEBYTECODE=1 # Prevent Python from buffering stdout/stderr ENV PYTHONUNBUFFERED=1 # HuggingFace Spaces runs on port 7860 ENV PORT=7860 # ─── Install System Dependencies ─────────────────────────────────────────── RUN apt-get update && apt-get install -y --no-install-recommends \ libglib2.0-0 \ libsm6 \ libxrender1 \ libxext6 \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* # ─── Install Python Dependencies ─────────────────────────────────────────── COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # ─── Copy Application Files ──────────────────────────────────────────────── COPY app.py . COPY cifar10_model.pth . COPY templates/ ./templates/ # ─── Create a non-root user (HuggingFace best practice) ──────────────────── RUN useradd -m -u 1000 appuser USER appuser # ─── Expose Port ─────────────────────────────────────────────────────────── EXPOSE 7860 # ─── Launch with Gunicorn (production WSGI server) ───────────────────────── CMD ["gunicorn", \ "--bind", "0.0.0.0:7860", \ "--workers", "1", \ "--timeout", "120", \ "--log-level", "info", \ "app:app"]