# Dockerfile for Hugging Face Spaces (All-in-One Free Hosting) FROM python:3.10-slim # Install system dependencies including Node.js (for React compilation), ffmpeg (for video/audio processing), and build-essential RUN apt-get update && apt-get install -y --no-install-recommends \ curl \ gnupg \ build-essential \ ffmpeg \ libgl1 \ libglib2.0-0 \ && rm -rf /var/lib/apt/lists/* # Install Node.js (v18) to build React frontend RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ && apt-get install -y nodejs \ && rm -rf /var/lib/apt/lists/* # Set up working directory WORKDIR /workspace # Set up Hugging Face user (HF spaces run as user ID 1000) RUN useradd -m -u 1000 user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Install PyTorch CPU-only first (saves ~2GB of space and speeds up Hugging Face build) RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu # Pre-install retinaface-pytorch with --no-deps to bypass its strict, outdated torchvision==0.10.0 constraint RUN pip install --no-cache-dir retinaface-pytorch==0.0.8 --no-deps # Copy requirements and install python dependencies # We filter out torch, torchvision, torchaudio, and retinaface-pytorch to avoid version-resolution conflicts COPY requirements.txt . RUN sed -i -E '/^(torch|torchvision|torchaudio|retinaface-pytorch)(>=|==)/d' requirements.txt && \ pip install --no-cache-dir -r requirements.txt # Force reinstall matching CPU versions of PyTorch to resolve any ABI mismatches introduced by requirements RUN pip uninstall -y torch torchvision torchaudio && \ pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu # Purge duplicate legacy files and force reinstall typing-extensions and pydantic to avoid Sentinel ImportError RUN pip uninstall -y typing-extensions pydantic pydantic-core && \ rm -f /usr/local/lib/python3.10/site-packages/typing_extensions.py* && \ pip install --no-cache-dir -U typing-extensions pydantic pydantic-core # Copy source code and app COPY src ./src COPY app/backend ./app/backend COPY app/frontend ./app/frontend # Build the React frontend WORKDIR /workspace/app/frontend RUN npm install RUN npm run build # Change working directory back to root WORKDIR /workspace # Set permissions for the Hugging Face user RUN chown -R user:user /workspace USER user # Set environment variables ENV PYTHONPATH=/workspace/src:/workspace/app/backend # Expose port 7860 (Hugging Face Spaces default port) EXPOSE 7860 # Run FastAPI backend using uvicorn on port 7860 CMD ["uvicorn", "app.backend.main:app", "--host", "0.0.0.0", "--port", "7860"]