FROM pytorch/pytorch:2.4.1-cuda12.1-cudnn9-runtime WORKDIR /app # system dependencies RUN apt-get update && apt-get install -y \ libglib2.0-0 \ libsm6 \ libxext6 \ libxrender-dev \ libgomp1 \ libgl1-mesa-glx \ git \ wget \ && rm -rf /var/lib/apt/lists/* RUN pip install --no-cache-dir --upgrade pip RUN pip install --no-cache-dir \ torch==2.4.1+cu121 \ torchvision==0.19.1+cu121 \ torchaudio==2.4.1+cu121 \ --index-url https://download.pytorch.org/whl/cu121 # install all other dependencies COPY requirements.txt . # Install everything except SAM2 RUN grep -v "facebookresearch/sam2" requirements.txt > requirements_no_sam.txt && \ pip install --no-cache-dir -r requirements_no_sam.txt # SAM2 officially requires torch>=2.5.1, but this project was # developed and validated with torch==2.4.1. Install SAM2 without dependency resolution to preserve the tested environment RUN pip install --no-cache-dir --no-deps \ git+https://github.com/facebookresearch/sam2.git@2b90b9f5ceec907a1c18123530e92e794ad901a4 # copy backend code COPY . . # create runtime directories RUN mkdir -p uploads outputs models # expose HF Spaces port EXPOSE 7860 COPY download_models.sh . RUN chmod +x download_models.sh CMD ["sh", "-c", "./download_models.sh && uvicorn main:app --host 0.0.0.0 --port 7860"]