# ---- Base image ---- FROM python:3.11-slim # Prevent Python buffering/logging issues ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ PORT=7860 \ HF_HOME=/home/user/.cache/huggingface # Install system deps RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential curl ca-certificates && \ rm -rf /var/lib/apt/lists/* # Set workdir WORKDIR /app # Install Python deps first (better layer caching) COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy app code COPY app.py . # Create a non-root user (optional but recommended) RUN useradd -m -u 1000 user && chown -R user:users /app USER user # Expose the port expected by HF Spaces EXPOSE 7860 # Start the server # Uvicorn binds to 0.0.0.0 and PORT env used by Spaces router CMD uvicorn app:app --host 0.0.0.0 --port ${PORT}