| # Dockerfile for Hugging Face Spaces deployment | |
| # Uses Python 3.10 with CUDA support for GPU acceleration | |
| FROM python:3.10-slim | |
| # Install system dependencies | |
| # Note: libgl1-mesa-glx is obsolete in Debian Trixie (newer versions) | |
| # Using libgl1 which works on both old and new Debian versions | |
| RUN apt-get update && apt-get install -y \ | |
| build-essential \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| libsm6 \ | |
| libxext6 \ | |
| libxrender-dev \ | |
| libgomp1 \ | |
| wget \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Set working directory | |
| WORKDIR /app | |
| # Copy requirements first for better caching | |
| COPY requirements.txt requirements.txt | |
| # Install Python dependencies (excluding sam2, which will be installed from local directory) | |
| # This includes hydra-core which is required by sam2 | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Verify hydra-core is installed (required for sam2/__init__.py) | |
| RUN python -c "import hydra; print('hydra-core installed successfully')" | |
| # Copy and install sam2 package from local directory | |
| # This must be done before copying app code since app imports from sam2 | |
| COPY sam2/ ./sam2/ | |
| WORKDIR /app/sam2 | |
| # Install sam2 in editable mode, skip CUDA extension build for faster deployment | |
| # (CUDA extension is optional and doesn't affect core functionality) | |
| # Note: sam2 setup.py will install its dependencies, but we've already installed them | |
| RUN SAM2_BUILD_CUDA=0 pip install --no-cache-dir -e . | |
| # Return to app directory | |
| WORKDIR /app | |
| # Copy application code | |
| COPY model/ ./model/ | |
| COPY app.py ./ | |
| # Copy startup script | |
| COPY start.sh ./start.sh | |
| RUN chmod +x ./start.sh | |
| # Create necessary directories | |
| RUN mkdir -p /app/models | |
| # Expose port (Hugging Face Spaces will map this automatically) | |
| EXPOSE 7860 | |
| # Set environment variables | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV SAM2_BUILD_CUDA=0 | |
| # Run the FastAPI application using startup script | |
| # Hugging Face Spaces sets PORT environment variable automatically (usually 7860) | |
| CMD ["./start.sh"] | |