word-as-image-api / Dockerfile
Ashish Ajin
Fix Dockerfile to run FastAPI server
e8b5f16
FROM ghcr.io/huggingface/text-generation-inference:3.3.4@sha256:91822fefc613d742f19f56b321925e81e41690dda29673c070fc68a65ae6bdb2
# Install system dependencies
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
build-essential git cmake ninja-build pkg-config curl ca-certificates gnupg software-properties-common \
python3-pip python3.11 python3.11-dev python3.11-venv python3.11-distutils python3-dev tzdata && \
ln -fs /usr/share/zoneinfo/Etc/UTC /etc/localtime && dpkg-reconfigure --frontend noninteractive tzdata && \
curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/3bf863cc.pub | \
gpg --dearmor --batch --yes -o /usr/share/keyrings/cuda-archive-keyring.gpg && \
echo "deb [signed-by=/usr/share/keyrings/cuda-archive-keyring.gpg] https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64 /" \
> /etc/apt/sources.list.d/cuda.list && \
apt-get update && \
apt-get install -y --no-install-recommends cuda-compiler-11-8 && \
rm -rf /var/lib/apt/lists/* && \
ldconfig
# Use Python 3.11 by default
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 2
# Upgrade pip and install PyTorch
RUN python3 -m pip install --upgrade pip && \
python3 -m pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
# Build and install diffvg (with thrust support)
RUN git clone --depth 1 --recursive https://github.com/BachiLi/diffvg.git /tmp/diffvg && \
cd /tmp/diffvg && \
# Replace internal pybind11, keep thrust submodule
rm -rf pybind11 && \
git clone --depth 1 --branch v2.12.1 https://github.com/pybind/pybind11.git pybind11 && \
sed -i 's/^\s*cmake_minimum_required(VERSION .*$/cmake_minimum_required(VERSION 3.5)/' pybind11/CMakeLists.txt && \
mkdir build && cd build && \
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_STANDARD=14 \
-DDIFFVG_CUDA=0 \
-DTHRUST_INCLUDE_DIR=/tmp/diffvg/thrust && \
make -j$(nproc) && \
cd /tmp/diffvg && python3 setup.py install && \
rm -rf /tmp/diffvg
# Copy the application code and install Python dependencies
COPY . /app
WORKDIR /app
RUN python3 -m pip install --no-cache-dir -r requirements.txt
# Launch the FastAPI server on container start
ENTRYPOINT ["uvicorn", "rest_api:app", "--host", "0.0.0.0", "--port", "7860"]