FROM python:3.10-slim # Set environment variables ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ HF_HOME=/home/user/.cache/huggingface \ VISUALIZER_CONFIG=visualizer.hf.toml \ HOME=/home/user # Install system dependencies (git for compphoto/Intrinsic installation, ffmpeg, glib for OpenCV) RUN apt-get update && \ apt-get install -y --no-install-recommends \ git \ ffmpeg \ libglib2.0-0 \ libgomp1 \ build-essential && \ rm -rf /var/lib/apt/lists/* # Set up a new user named "user" with UID 1000 for Hugging Face permissions RUN useradd -m -u 1000 user WORKDIR /app # Copy requirements files first COPY requirements-base.txt ./ # Install CPU PyTorch/Torchvision first, then other base requirements RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir torch torchvision --extra-index-url https://download.pytorch.org/whl/cpu && \ pip install --no-cache-dir -r requirements-base.txt # Copy the rest of the application files COPY --chown=user:1000 . . # Create writable data directories and change ownership RUN mkdir -p data/uploads data/jobs && \ chown -R user:1000 /app # Switch to the non-root user USER user # Hugging Face Spaces expects the application on port 7860 EXPOSE 7860 CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]