File size: 1,353 Bytes
e84e3d2
cfb9834
 
 
e84e3d2
cfb9834
 
 
 
 
 
e84e3d2
cfb9834
e84e3d2
cfb9834
 
 
 
e84e3d2
 
 
 
 
 
 
 
 
4edd459
 
 
 
 
 
 
 
 
 
cfb9834
e84e3d2
cfb9834
 
e84e3d2
cfb9834
 
e84e3d2
cfb9834
 
c25adf8
 
 
 
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
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"]