FROM python:3.11-slim # OpenCV runtime deps RUN apt-get update && apt-get install -y --no-install-recommends \ libglib2.0-0 libgl1 \ && rm -rf /var/lib/apt/lists/* WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt \ && pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu \ && pip install --no-cache-dir ultralytics COPY analysis ./analysis COPY models ./models COPY app.py . # PRELOAD_NN: import torch and load the weights during startup instead of on # someone's first click. The Space is long-lived, so it pays this once. ENV PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 PRELOAD_NN=1 # HF Spaces routes traffic to port 7860 by convention EXPOSE 7860 CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]