building-detection / Dockerfile
yusef
Fix: upgrade transformers to >=4.40.0 for SiglipProcessor support
3242e70
FROM python:3.10-slim
# System dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
git \
libgl1 \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
&& rm -rf /var/lib/apt/lists/*
# Create app directory
WORKDIR /app
# Step 1: Install PyTorch FIRST (CPU-only to save space)
RUN pip install --no-cache-dir \
torch torchvision --index-url https://download.pytorch.org/whl/cpu
# Step 2: Install Detectron2 (needs torch already installed)
RUN pip install --no-cache-dir \
'git+https://github.com/facebookresearch/detectron2.git'
# Step 3: Install remaining dependencies
RUN pip install --no-cache-dir \
fastapi>=0.104.0 \
"uvicorn[standard]>=0.24.0" \
opencv-python-headless>=4.8.0 \
numpy>=1.24.0 \
Pillow>=10.0.0 \
requests>=2.31.0 \
huggingface_hub>=0.19.0 \
python-multipart>=0.0.6
# Step 4: V5.1 Pipeline — MobileSAM + SigLIP
RUN pip install --no-cache-dir \
"transformers>=4.40.0" \
timm>=0.9.0 \
'git+https://github.com/ChaoningZhang/MobileSAM.git'
# Copy app code
COPY . .
# Create a non-root user (HF Spaces requirement)
RUN useradd -m -u 1000 user
USER user
# Expose port (HF Spaces uses 7860)
EXPOSE 7860
# Start the server
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]