FROM python:3.10-slim ENV PYTHONUNBUFFERED=1 \ PYTHONUTF8=1 \ PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python \ # On Hugging Face CPU Spaces, warmup of heavy ML models can exceed container # startup time and cause apparent hangs. Set to 1 to skip warmup during # container start (models still lazy-load on first request). FAKESHIELD_SKIP_WARMUP=1 WORKDIR /app # System dependencies (Adding build-essential for C extensions) RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ libgl1 \ libglib2.0-0 \ libsndfile1 \ ffmpeg \ libmagic1 \ libgles2 \ libegl1 \ && rm -rf /var/lib/apt/lists/* COPY backend/requirements.txt . RUN pip install --no-cache-dir --upgrade pip # Step 1: Core Framework RUN pip install --no-cache-dir fastapi "uvicorn[standard]" python-multipart python-dotenv pydantic "pydantic-settings" email-validator motor "passlib[bcrypt]" PyJWT google-generativeai spacy && \ python -m spacy download en_core_web_sm # Step 2: Heavy ML Engines (CPU Only) RUN pip install --no-cache-dir torch torchaudio torchvision --index-url https://download.pytorch.org/whl/cpu # Ensure any optional native extensions that might pull CUDA builds use the # CPU wheels instead. TorchCodec can auto-pick a CUDA wheel which then tries # to load libnvrtc (missing on CPU-only Spaces). Force-install the CPU wheel # from the PyTorch CPU index to avoid libnvrtc dependency. RUN pip install --no-cache-dir --force-reinstall --no-deps --index-url https://download.pytorch.org/whl/cpu torchcodec || true # Step 3: Transformers & Scipy RUN pip install --no-cache-dir transformers accelerate "sentence-transformers" scikit-learn numpy scipy # Step 4: Image & Audio Utilities RUN pip install --no-cache-dir Pillow piexif opencv-python-headless "soundfile>=0.12.0" "librosa>=0.10.0" "resampy>=0.4.2" # Step 5: Isolate Pyannote (Very Heavy) RUN pip install --no-cache-dir "pyannote.audio>=3.1.0" # Step 6: Isolate C2PA (Might need build tools) RUN pip install --no-cache-dir c2pa-python # Step 7: Final Misc RUN pip install --no-cache-dir "protobuf~=4.25.3" python-magic email-validator aiosmtplib # Step 8: Extra ML Engines & Libraries RUN pip install --no-cache-dir "optimum[onnxruntime]" diffusers mediapipe asyncpg reportlab sentencepiece openai-whisper # Step 9: Retina-Face (Isolated to prevent OpenCV dependency conflicts) RUN pip install --no-cache-dir retina-face --no-deps COPY backend/ . EXPOSE 7860 CMD ["python", "start_backend.py"]