# Use a slim Python base image FROM python:3.12-slim # Set the working directory in the container WORKDIR /app # Install system dependencies required for PyMuPDF (fitz) # This is in a separate layer to leverage Docker's build cache. RUN apt-get update && apt-get install -y --no-install-recommends \ libmupdf-dev \ gcc \ && rm -rf /var/lib/apt/lists/* # Install CPU-only PyTorch first — avoids pulling 2.5 GB CUDA build # sentence-transformers depends on torch; without this it installs the full CUDA wheel RUN pip install --no-cache-dir torch==2.5.1 --index-url https://download.pytorch.org/whl/cpu # Copy the requirements file and install remaining Python dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Pre-download and cache the sentence transformer model. # This ensures the model is ready on first boot and avoids download delays. RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('all-MiniLM-L6-v2')" # Copy the application code into the container COPY app/ ./app/ # Default port 8000 for local/Docker. HF Spaces overrides with PORT=7860. ENV PORT=7860 EXPOSE 7860 CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT}"]