FROM python:3.11-slim WORKDIR /app # System dependencies required by opencv-python-headless (ultralytics transitive dep) RUN apt-get update && apt-get install -y --no-install-recommends \ libgl1 libglib2.0-0 \ && rm -rf /var/lib/apt/lists/* # Install dependencies COPY requirements.txt . RUN pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu && \ pip install --no-cache-dir -r requirements.txt # Pre-bake YOLOv8n weights (6MB) so first request doesn't block RUN python -c "from ultralytics import YOLO; YOLO('yolov8n.pt')" # HuggingFace cache directory for transformers + torchxrayvision ENV HF_HOME=/app/.hf-cache \ TORCH_HOME=/app/.torch-cache # Copy app files COPY . . # HF Spaces requires port 7860 EXPOSE 7860 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]