Spaces:
Sleeping
Sleeping
File size: 968 Bytes
7d0f4d3 3a6ecdf 28067b9 548e04f 868d51b 548e04f 868d51b 548e04f 868d51b 548e04f 7d0f4d3 548e04f f6ba75c 28067b9 548e04f 868d51b 548e04f 868d51b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
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"] |