FROM python:3.10-slim WORKDIR /code RUN apt-get update && apt-get install -y \ libgl1 \ libglx-mesa0 \ libglib2.0-0 \ git \ && rm -rf /var/lib/apt/lists/* COPY ./requirements.txt /code/requirements.txt RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt # Create cache dirs with open permissions BEFORE preloading RUN mkdir -p /tmp/torch_cache /tmp/ultralytics_config \ && chmod -R 777 /tmp/torch_cache /tmp/ultralytics_config ENV TORCH_HOME=/tmp/torch_cache ENV YOLO_CONFIG_DIR=/tmp/ultralytics_config # Copy files (including preload script) COPY . . # Pre-download MiDaS at build time — no interactive prompt possible here RUN python preload_models.py CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]