Spaces:
Sleeping
Sleeping
# β Use official slim image | |
FROM python:3.10-slim | |
# β Set working directory | |
WORKDIR /app | |
# β Set environment variables early to ensure cache use in setup.py | |
ENV TRANSFORMERS_CACHE=/app/model_cache \ | |
HF_HOME=/app/model_cache \ | |
TORCH_HOME=/app/model_cache \ | |
TOKENIZERS_PARALLELISM=false \ | |
OMP_NUM_THREADS=4 | |
# β Install only necessary OS packages and clean cache | |
RUN apt-get update && apt-get install -y git \ | |
&& rm -rf /var/lib/apt/lists/* | |
# β Copy files (excluding model_cache, logs, etc. via .dockerignore) | |
COPY . . | |
# β Upgrade pip + install deps without cache | |
RUN pip install --upgrade pip \ | |
&& pip install --no-cache-dir -r requirements.txt | |
# β Run setup.py to download the model | |
RUN python setup.py | |
# β Expose Hugging Face Space-required port | |
EXPOSE 7860 | |
# β Launch FastAPI on port 7860 for HF Space | |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--timeout-keep-alive", "120", "--log-level", "info"] | |