microGPT / Dockerfile
Devdan Schretlen
Add MicroGPT chat demo: FastAPI + React app, Dockerfile, gpt3.1 model
8b12a0a
Raw History Blame Contribute Delete
1.4 kB
# MicroGPT chat demo for Hugging Face Spaces (Docker SDK).
# A FastAPI backend serves the fine-tuned GPT-3-style model and the prebuilt
# React frontend (web/dist) on a single origin.
FROM python:3.12-slim
# Run as the non-root "user" account Hugging Face Spaces expects (uid 1000).
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH \
PYTHONUNBUFFERED=1 \
TIKTOKEN_CACHE_DIR=/home/user/.cache/tiktoken
# Keep the app under the user's home so it owns the directory tree.
WORKDIR /home/user/app
# Install dependencies first so this layer caches across code/model changes.
# torch comes from the CPU-only wheel index (matches the locally tested build).
COPY --chown=user:user requirements.txt ./
RUN pip install --user --no-cache-dir --upgrade pip \
&& pip install --user --no-cache-dir torch==2.12.0 --index-url https://download.pytorch.org/whl/cpu \
&& pip install --user --no-cache-dir -r requirements.txt
# Copy the application: model weights, server/, models/, common.py, web/dist/.
COPY --chown=user:user . .
# Bake the GPT-2 BPE vocab into the image so the first request needs no network.
RUN mkdir -p "$TIKTOKEN_CACHE_DIR" \
&& python -c "import tiktoken; tiktoken.get_encoding('gpt2')"
# Hugging Face Spaces routes external traffic to port 7860.
EXPOSE 7860
CMD ["uvicorn", "server.app:app", "--host", "0.0.0.0", "--port", "7860"]