Spaces:
Sleeping
Sleeping
FROM python:3.9-slim | |
WORKDIR /app | |
# 1. Install only essential system dependencies | |
RUN apt-get update && \ | |
apt-get install -y --no-install-recommends \ | |
build-essential \ | |
&& rm -rf /var/lib/apt/lists/* | |
# 2. Set cache directories (HF Spaces provides writable /tmp) | |
ENV TRANSFORMERS_CACHE=/tmp/model_cache \ | |
HF_HOME=/tmp/huggingface \ | |
XDG_CACHE_HOME=/tmp/xdg_cache | |
# 3. Create cache directories | |
RUN mkdir -p ${TRANSFORMERS_CACHE} ${HF_HOME} ${XDG_CACHE_HOME} | |
# 4. Copy requirements first (better layer caching) | |
COPY requirements.txt . | |
RUN pip install --no-cache-dir --upgrade pip && \ | |
pip install --no-cache-dir -r requirements.txt | |
# 5. Copy application code | |
COPY . . | |
# 6. Health check endpoint | |
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ | |
CMD curl -f http://localhost:7860/health || exit 1 | |
# 7. Run with optimized settings | |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"] |