FROM python:3.8-slim | |
WORKDIR /code | |
# Install system dependencies | |
RUN apt-get update && apt-get install -y \ | |
build-essential \ | |
python3-dev \ | |
git \ | |
libcairo2-dev \ | |
pkg-config \ | |
&& rm -rf /var/lib/apt/lists/* | |
# Install PyTorch and torchvision | |
RUN pip install torch==2.0.0 torchvision==0.15.1 --extra-index-url https://download.pytorch.org/whl/cpu | |
# Install CLIP | |
RUN pip install git+https://github.com/openai/CLIP.git | |
# Install diffusers and other dependencies | |
RUN pip install diffusers transformers accelerate xformers omegaconf einops kornia | |
# Install cairosvg and other dependencies | |
RUN pip install cairosvg cairocffi cssselect2 defusedxml tinycss2 | |
# Install FastAPI and other dependencies | |
RUN pip install fastapi uvicorn pydantic pillow numpy requests | |
# Install SVG dependencies | |
RUN pip install svgwrite svgpathtools cssutils numba | |
# Copy the model files | |
COPY . /code/ | |
# Download model weights if they don't exist | |
RUN if [ ! -f /code/ViT-B-32.pt ]; then \ | |
pip install gdown && \ | |
python -c "import clip; clip.load('ViT-B-32')" ; \ | |
fi | |
# Make sure the handler and model are available | |
RUN if [ -f /code/diffsketcher_endpoint.py ]; then \ | |
echo "DiffSketcher endpoint found"; \ | |
else \ | |
echo "DiffSketcher endpoint not found, using placeholder"; \ | |
fi | |
# Set environment variables | |
ENV PYTHONUNBUFFERED=1 | |
# Run the API server | |
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8000"] |