Fourtris's picture
Commit Project
74d6c39
# Use an official Python image as the base image
FROM python:3.10-slim
# Set environment variables to prevent Python from writing .pyc files and to buffer stdout and stderr
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# Set the working directory inside the container
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
wget \
git \
curl \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Install pip and upgrade it
RUN pip install --no-cache-dir --upgrade pip
# Install PyTorch and TorchVision
RUN pip install --no-cache-dir \
torch==2.5.1 \
torchvision==0.20.1 \
-f https://download.pytorch.org/whl/torch_stable.html
# Clone SAM2 repository and install it
RUN git clone https://github.com/facebookresearch/sam2.git sam2_repo && \
cd sam2_repo && \
pip install -e .
# Download SAM2 model checkpoints
RUN cd /app/sam2_repo/checkpoints && \
chmod +x download_ckpts.sh && \
./download_ckpts.sh
RUN apt-get update && apt-get install ffmpeg libsm6 libxext6 -y
# Install Flask application dependencies
RUN pip install --no-cache-dir \
httpx==0.27.2 \
Flask==3.1.0 \
Flask-Cors==5.0.0 \
openai==1.55.3 \
matplotlib==3.9.2 \
tqdm==4.67.0 \
opencv-python==4.10.0.84 \
albumentations==1.4.21 \
gunicorn
# Copy the application code to the container
COPY . /app/
# Download ResNet50 checkpoint
RUN curl https://download.pytorch.org/models/resnet50-0676ba61.pth --output /app/resnet50-0676ba61.pth
# Copy SAM2 checkpoints
RUN mv /app/sam2_repo/checkpoints/*.pt /app/ && ls /app/
# Expose the port the app runs on
EXPOSE 7860
# Define the command to run the Flask app
CMD ["gunicorn", "-b=0.0.0.0:7860", "app:app", "--timeout=0"]