TransPlugin / Dockerfile
angre369's picture
fix: Set HF_HOME in Dockerfile and use JSONResponse in app.py
5296f29
raw
history blame contribute delete
623 Bytes
# 使用官方Python镜像作为基础
FROM python:3.9-slim
# 设置工作目录
WORKDIR /app
ENV HF_HOME=/app/.cache
# 复制依赖文件并安装
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# 复制应用代码
COPY . .
# 预下载模型以避免运行时权限问题
RUN python -c "from transformers import AutoTokenizer, AutoModelForSeq2SeqLM; AutoTokenizer.from_pretrained('Helsinki-NLP/opus-mt-en-zh'); AutoModelForSeq2SeqLM.from_pretrained('Helsinki-NLP/opus-mt-en-zh')"
# 暴露端口
EXPOSE 7860
# 启动应用
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]