# ─────────────────────────────────────────────────────────── # Word-As-Image • FastAPI GPU Space • builds diffvg # ─────────────────────────────────────────────────────────── FROM python:3.10-slim # —— OS packages needed by diffvg & image libs ——————————— RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential git cmake ffmpeg pkg-config \ libgl1-mesa-dev libglib2.0-0 libpng-dev libxrender1 xorg-dev \ && rm -rf /var/lib/apt/lists/* # —— Non-root user per HF best practice ———————————————— RUN useradd -m -u 1000 appuser USER appuser WORKDIR /app # —— Persist HF + Torch caches (saves model download time) — ENV HF_HOME=/home/appuser/.cache/huggingface \ TRANSFORMERS_CACHE=/home/appuser/.cache/huggingface \ TORCH_HOME=/home/appuser/.cache/huggingface/torch \ PATH="/home/appuser/.local/bin:${PATH}" ENV CUDA_VISIBLE_DEVICES="" # (the extra PATH entry suppresses the “not on PATH” pip warnings) # —— Python deps (NO diffvg here) ———————————————— COPY --chown=appuser requirements.txt . RUN pip install --upgrade pip \ && pip install --no-cache-dir -r requirements.txt # —— Build diffvg from a known-good commit —————————— RUN git clone https://github.com/BachiLi/diffvg.git /tmp/diffvg \ && cd /tmp/diffvg \ && git submodule update --init --recursive \ && python setup.py install --user \ && cd /app \ && rm -rf /tmp/diffvg # —— Project code ———————————————————————————— COPY --chown=appuser . /app EXPOSE 7860 CMD ["uvicorn", "rest_api:app", "--host", "0.0.0.0", "--port", "7860"]