Spaces:
Sleeping
Sleeping
File size: 947 Bytes
899d656 deda7a1 899d656 deda7a1 899d656 deda7a1 899d656 deda7a1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | # Stage 1: fetch Helsinki-NLP opus-mt he-ru / ru-he from HF Hub and convert to CTranslate2 int8 (~80 MB each)
FROM python:3.12-slim AS mt
RUN pip install --no-cache-dir ctranslate2 sentencepiece transformers \
torch --index-url https://download.pytorch.org/whl/cpu --extra-index-url https://pypi.org/simple
RUN for p in he-ru ru-he; do \
ct2-transformers-converter --model Helsinki-NLP/opus-mt-$p --output_dir /models/opus-$p \
--quantization int8 --copy_files source.spm target.spm --low_cpu_mem_usage; \
done && rm -rf /root/.cache
# Stage 2: runtime (no torch/transformers)
FROM python:3.12-slim
RUN pip install --no-cache-dir aiohttp==3.* ctranslate2 sentencepiece
RUN useradd -m -u 1000 user
USER user
WORKDIR /app
COPY --from=mt --chown=user /models ./models
COPY --chown=user server.py opus_mt.py ./
COPY --chown=user public ./public
ENV HOST=0.0.0.0 PORT=7860 OPUS_THREADS=2
EXPOSE 7860
CMD ["python3", "server.py"]
|