# Base image: PyTorch with CUDA (torch is pre-installed in conda here) FROM pytorch/pytorch:2.1.2-cuda12.1-cudnn8-runtime # Environment ENV DEBIAN_FRONTEND=noninteractive ENV PYTHONUNBUFFERED=1 # --------------------------------------------------------------- # ALL installs run as ROOT so pip uses the conda environment # where torch already lives. This prevents GroundingDINO's # setup.py from failing to find torch. # --------------------------------------------------------------- # System dependencies RUN apt-get update && apt-get install -y \ git \ ffmpeg \ libsm6 \ libxext6 \ wget \ && rm -rf /var/lib/apt/lists/* # Upgrade pip inside conda RUN pip install --no-cache-dir --upgrade pip # Python dependencies (into the conda env as root) COPY requirements.txt /tmp/requirements.txt RUN pip install --no-cache-dir -r /tmp/requirements.txt # Install GroundingDINO with --no-build-isolation so its setup.py can # find torch from the conda environment (not a sandboxed temp env). RUN pip install --no-cache-dir --no-build-isolation \ "git+https://github.com/IDEA-Research/GroundingDINO.git" # Install Segment Anything RUN pip install --no-cache-dir \ "git+https://github.com/facebookresearch/segment-anything.git" # --------------------------------------------------------------- # Create non-root user for runtime (HF Spaces requirement) # Packages installed above are in /opt/conda and accessible # to all users, so this is safe. # --------------------------------------------------------------- RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:${PATH}" WORKDIR /home/user/app # Copy application files COPY --chown=user . . # Hugging Face Spaces mandatory port EXPOSE 7860 CMD ["python", "app.py"]