# Use official slim Python image FROM python:3.10-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 ENV PORT=7860 WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ && rm -rf /var/lib/apt/lists/* # Create a non-root user with UID 1000 (required for Hugging Face Spaces security) RUN useradd -m -u 1000 user # Install Python dependencies as root COPY requirements.txt . RUN pip install --no-cache-dir "torch>=2.6.0" --extra-index-url https://download.pytorch.org/whl/cpu RUN pip install --no-cache-dir -r requirements.txt # Copy application files and change ownership to the non-root user COPY --chown=user . . # Switch to the non-root user USER user ENV PATH="/home/user/.local/bin:$PATH" # Expose port (HF Spaces uses 7860, Render uses dynamic $PORT) EXPOSE 7860 # Start Uvicorn server binding dynamically to $PORT CMD uvicorn app:app --host 0.0.0.0 --port $PORT