File size: 929 Bytes
55bcd2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.11-slim

RUN apt-get update && apt-get install -y \
    ffmpeg \
    libgl1 \
    libglib2.0-0 \
    libsm6 \
    libxext6 \
    libxrender-dev \
    curl \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY requirements.txt .
# Install torch CPU-only first (~250MB vs ~2GB for the default CUDA build)
RUN \
    pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu
RUN \
    pip install --timeout 300 -r requirements.txt

COPY app/ ./app/
COPY scripts/ ./scripts/

EXPOSE 8000

HEALTHCHECK --interval=30s --timeout=10s --start-period=300s --retries=3 \
    CMD curl -f http://localhost:8000/health || exit 1

# Models download on first cold start and are cached by HF Spaces persistently.
# preload_models.py runs before uvicorn so the API is ready when /health passes.
CMD ["sh", "-c", "python scripts/preload_models.py && uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 1"]