FROM python:3.11-slim RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" ENV HF_HOME=/home/user/.cache/huggingface WORKDIR /app COPY --chown=user requirements.txt requirements.txt RUN pip install --no-cache-dir --upgrade -r requirements.txt COPY --chown=user . /app EXPOSE 7860 # Single-threaded BLAS to avoid CPU oversubscription on small instances ENV OMP_NUM_THREADS=1 ENV MKL_NUM_THREADS=1 ENV TOKENIZERS_PARALLELISM=false # No --preload: PyTorch's threading state doesn't survive fork() cleanly, # which causes /predict to hang. Worker loads its own model copy. CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:7860", "--timeout", "180", "--workers", "1"]