dialectica / Dockerfile
zkmine's picture
Update Dockerfile
7403e13 verified
Raw
History Blame Contribute Delete
1.34 kB
# Dockerfile for deploying Dialectica on Hugging Face Spaces (Docker SDK).
#
# Notes specific to Spaces:
# * The app must listen on port 7860.
# * Only /tmp is writable, so all model caches are redirected there.
# * The fine-tuned DistilBERT is pulled from the Hugging Face Hub at startup
# (set MODEL_REPO below), so it does not need to be baked into the image.
FROM python:3.11-slim
# System deps for PyMuPDF and general builds.
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
&& rm -rf /var/lib/apt/lists/*
# Redirect all model/library caches to /tmp (the only writable dir on Spaces).
ENV HF_HOME=/tmp/hf_home \
TRANSFORMERS_CACHE=/tmp/hf_home \
SENTENCE_TRANSFORMERS_HOME=/tmp/st_home \
XDG_CACHE_HOME=/tmp/cache \
MPLCONFIGDIR=/tmp/mpl
ENV PYTHONUNBUFFERED=1
WORKDIR /app
# Install Python dependencies first for better layer caching.
# Install the CPU build of torch explicitly to avoid pulling large CUDA wheels.
COPY requirements-app.txt .
RUN pip install --no-cache-dir "torch>=2.2.0" --index-url https://download.pytorch.org/whl/cpu
RUN pip install --no-cache-dir --upgrade -r requirements-app.txt
# Copy the application code.
COPY . .
# Spaces expects the app on port 7860.
EXPOSE 7860
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]