translation / Dockerfile
orik-ss's picture
chown app dir as user before USER directive
a78384c
Raw
History Blame Contribute Delete
1.71 kB
# Translation β€” Docker Space
# CPU-only NLLB-200-3.3B (CTranslate2 int8). Gradio on 7860.
#
# Mirrors the ainuvision-edge production setup: facebook/nllb-200-3.3B is
# downloaded and converted to CT2 int8 at build time (per STEPS_UNIFIED.md
# and translator.rs which uses ct2rs::Translator).
FROM python:3.10-slim-bookworm
# Build deps for sentencepiece wheels on slim images
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
git \
&& rm -rf /var/lib/apt/lists/*
# HF Spaces run as user 1000.
# Create $HOME/app *and* chown it as root before switching users β€” otherwise
# WORKDIR makes it root-owned and `user` can't write subdirs into it
# (the snapshot_download in convert_model.py creates ./model).
RUN useradd -m -u 1000 user
ENV HOME=/home/user PATH=/home/user/.local/bin:$PATH
RUN mkdir -p /home/user/app && chown -R user:user /home/user/app
USER user
WORKDIR /home/user/app
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt
# Fetch the pre-converted CT2 int8 NLLB-200-3.3B from the Hub at build time.
# (Conversion is done once on a workstation and uploaded to NLLB_CT2_REPO β€”
# the HF Spaces builder doesn't have enough RAM to convert 3.3B in place.)
# Output: $HOME/app/model/{model.bin, tokenizer.*}
COPY --chown=user convert_model.py .
ENV NLLB_CT2_REPO=Napron/nllb-200-3.3B-ct2-int8
ENV NLLB_CT2_DIR=/home/user/app/model
RUN python convert_model.py \
&& rm -rf /home/user/.cache/huggingface/hub
# App code
COPY --chown=user . .
ENV GRADIO_SERVER_NAME=0.0.0.0
ENV NLLB_DEVICE=cpu
ENV NLLB_COMPUTE_TYPE=int8
EXPOSE 7860
CMD ["python", "app.py"]