File size: 2,012 Bytes
39d0c75 f94bf7d 39d0c75 f94bf7d 39d0c75 10f8ce7 39d0c75 23f6e20 39d0c75 23f6e20 39d0c75 23f6e20 39d0c75 36fcf33 58d5e14 39d0c75 58d5e14 39d0c75 58d5e14 39d0c75 | 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 58 59 60 61 62 63 64 65 66 | # 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"]
|