# ──────────────────────────────────────────────────────────────────────────────── # Grounded‑SAM CPU Docker image with Flask API # ──────────────────────────────────────────────────────────────────────────────── FROM python:3.10-slim ENV DEBIAN_FRONTEND=noninteractive \ PYTHONUNBUFFERED=1 \ AM_I_DOCKER=True \ BUILD_WITH_CUDA=False \ # ↓ Hugging Face cache inside the container (optional) HF_HOME=/opt/hf_cache \ # Set MPLCONFIGDIR to a writable directory MPLCONFIGDIR=/tmp/matplotlib-cache \ # Set Fontconfig cache directory to a writable location FONTCONFIG_PATH=/tmp/fontconfig-cache # ––– OS packages ––– RUN apt-get update && \ apt-get install -y --no-install-recommends \ git wget ffmpeg libgl1 && \ apt-get clean && rm -rf /var/lib/apt/lists/* # ––– Code ––– WORKDIR /workspace COPY requirements.txt ./requirements.txt RUN pip install --no-cache-dir -r requirements.txt # Ensure numpy and pycocotools compatibility RUN pip install --no-cache-dir --force-reinstall numpy pycocotools # Segment‑Anything & GroundingDINO in editable mode RUN git clone --depth 1 https://github.com/facebookresearch/segment-anything.git && \ pip install -e segment-anything RUN git clone --depth 1 https://github.com/IDEA-Research/GroundingDINO.git && \ pip install --no-build-isolation -e GroundingDINO # Flask API COPY app.py ./app.py # Download pretrained checkpoints at build time (comment out to download on first run) RUN mkdir -p weights && \ wget -q -O weights/sam_vit_h_4b8939.pth \ https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth && \ wget -q -O weights/groundingdino_swint_ogc.pth \ https://github.com/IDEA-Research/GroundingDINO/releases/download/v0.1.0-alpha/groundingdino_swint_ogc.pth # Set permissions for the working directory RUN chmod 777 /workspace RUN mkdir -p /tmp/fontconfig-cache && chmod 777 /tmp/fontconfig-cache RUN mkdir -p /opt/hf_cache && chmod 777 /opt/hf_cache EXPOSE 7860 ENTRYPOINT ["python", "app.py", "--host", "0.0.0.0", "--port", "7860"]