File size: 2,428 Bytes
d41ddc1
 
 
 
 
 
 
 
 
 
0ac79d5
 
cb43dd3
 
 
d41ddc1
 
 
 
 
 
 
 
 
 
 
 
0ac79d5
 
 
d41ddc1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cb43dd3
 
 
bc2ee7a
 
85b6fb8
 
d41ddc1
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# ────────────────────────────────────────────────────────────────────────────────
# 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"]