# Hugging Face Spaces Dockerfile for KYC POC Backend FROM python:3.10-slim # Set environment variables ENV PYTHONDONTWRITEBYTECODE=1 ENV PYTHONUNBUFFERED=1 ENV DEBIAN_FRONTEND=noninteractive # Install system dependencies and build tools for insightface RUN apt-get update && apt-get install -y --no-install-recommends \ git \ libgl1 \ libglib2.0-0 \ libsm6 \ libxext6 \ libxrender-dev \ libgomp1 \ build-essential \ cmake \ && rm -rf /var/lib/apt/lists/* # Create app user for HF Spaces (required) RUN useradd -m -u 1000 user WORKDIR /home/user/app # Create directories with correct ownership for models RUN mkdir -p /home/user/app/models/anti_spoof \ /home/user/app/insightface_models/models \ /home/user/app/.cache \ && chown -R user:user /home/user/app # Copy requirements first for better caching COPY --chown=user:user requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # Copy application code COPY --chown=user:user . . # Switch to non-root user (required for HF Spaces) USER user # Download models during build (as user, so permissions are correct) RUN python setup_models.py # Set HuggingFace and InsightFace to use local models ENV HF_HOME=/home/user/app/.cache/huggingface ENV INSIGHTFACE_HOME=/home/user/app/insightface_models # Expose port (HF Spaces uses 7860 by default) EXPOSE 7860 # Set environment variables for production ENV DEBUG=False ENV USE_GPU=False ENV DEVICE_ID=-1 # Run the application CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]