finetune-deploy1 / Dockerfile
longvnhue1's picture
Update Dockerfile (#2)
afe3bd7 verified
FROM python:3.12
WORKDIR /app
# Tạo thư mục cache cho huggingface, cấp quyền ghi
RUN mkdir -p /cache && chmod 777 /cache
# Cài g++ để tránh lỗi transformers build lại tokenizer
RUN apt-get update && apt-get install -y g++ && apt-get upgrade -y && apt-get clean && rm -rf /var/lib/apt/lists/*
# Set biến môi trường để huggingface cache model vào /cache
ENV TRANSFORMERS_CACHE=/cache
ENV HF_HOME=/cache
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
# Tải sẵn model lúc build để tránh lỗi runtime permission
RUN python -c "from transformers import M2M100Tokenizer, M2M100ForConditionalGeneration; \
M2M100Tokenizer.from_pretrained('longvnhue1/facebook-m2m100_418M-fine_tuning'); \
M2M100ForConditionalGeneration.from_pretrained('longvnhue1/facebook-m2m100_418M-fine_tuning')"
# Mặc định FastAPI chạy bằng Uvicorn
# CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "2"]