# THE FINAL, CORRECT BLUEPRINT. FROM python:3.10-slim # Install curl, which we need to download the model during the build. RUN apt-get update && apt-get install -y curl WORKDIR /code # THE ARCHITECTURAL FIX: We download the HEAVY AI model ONCE, during the build. # It will be baked into the application. It will never be downloaded at runtime. # This solves all startup timeout and "Starting..." errors forever. RUN curl -L "https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth" -o /tmp/sam_model.pth # Install the lightweight Python libraries. COPY ./requirements.txt /code/requirements.txt RUN pip install --no-cache-dir -r /code/requirements.txt # Copy our API code into the main directory. No sub-folders. COPY ./main.py /code/main.py # The simple, reliable startup command. It starts ONE worker, fixing the memory crash. CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]