File size: 1,005 Bytes
5efc5e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
FROM python:3.11-slim

# non-root user (HF Spaces convention; writable HOME for the HF cache the model
# is pulled into at boot).
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH \
    HF_HOME=/home/user/.cache/huggingface \
    PYTHONUNBUFFERED=1 \
    TMPDIR=/tmp

WORKDIR /home/user/app

# CPU-only torch (the default PyPI wheel is CUDA and huge).
RUN pip install --no-cache-dir --user torch --index-url https://download.pytorch.org/whl/cpu

COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir --user -r requirements.txt

COPY --chown=user . .

EXPOSE 7860

# One worker (single shared model), threads for concurrent requests. No --preload:
# the worker pulls + loads the model in its own process (avoids the torch/OpenMP
# fork deadlock). --timeout 0 keeps the first-boot model download from tripping
# the worker timeout.
CMD ["gunicorn", "-w", "1", "--threads", "8", "-k", "gthread", "-b", "0.0.0.0:7860", "--timeout", "0", "app:app"]