FROM python:3.11-slim WORKDIR /app # 1. CPU-only torch on its own line: huge, but cached as a single reusable layer. # The CPU index drops the NVIDIA CUDA stack you don't need on a CPU server. RUN pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu # 2. The rest of the dependencies (torch is already satisfied above). COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # 3. Application code last — the layer that changes most often. COPY . . EXPOSE 7860 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]