FROM python:3.12-slim ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PIP_NO_CACHE_DIR=1 WORKDIR /app # torch first, from the CPU-only index. `--extra-index-url` would not be enough: # PyPI publishes the same version number as a CUDA build, and pip is free to # resolve to it -- which is 2.5GB of CUDA runtime this Space will never call. RUN pip install --no-cache-dir --index-url https://download.pytorch.org/whl/cpu torch==2.13.0 COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Bake the weights into the image: a Space that pulls a 409MB checkpoint on # every cold start answers its first message a minute late, and the trimmed # file is 136MB. COPY prepare_weights.py . RUN python prepare_weights.py /app/weights COPY booper ./booper COPY static ./static COPY app.py . EXPOSE 7860 # One worker: the model is a shared in-process object and 2 vCPUs are already # saturated by a single decode, so a second worker would only double the RAM. CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1", "--no-access-log"]