Spaces:
Running
Running
| FROM python:3.11-slim | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| curl \ | |
| wget \ | |
| procps \ | |
| git \ | |
| build-essential \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| && curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ | |
| && apt-get install -y nodejs \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Set up a new user named "user" with user ID 1000 (Required by HF Spaces) | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| WORKDIR $HOME/app | |
| # Copy requirements and install | |
| COPY --chown=user requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Securely mount the HF_TOKEN secret during build to pre-download the model | |
| # You configure HF_TOKEN in the "Secrets" tab of your Hugging Face Space settings | |
| RUN --mount=type=secret,id=HF_TOKEN,mode=0444,required=true \ | |
| python -c "from transformers import AutoProcessor, AutoModel; \ | |
| import os; \ | |
| token = open('/run/secrets/HF_TOKEN').read().strip(); \ | |
| AutoProcessor.from_pretrained('google/medsiglip-448', token=token); \ | |
| AutoModel.from_pretrained('google/medsiglip-448', token=token)" | |
| # Pre-download YOLO | |
| RUN python -c "from ultralytics import YOLO; YOLO('yolov8n.pt')" | |
| # Copy the rest of the application code | |
| COPY --chown=user . $HOME/app | |
| # Hugging Face defaults to port 7860 | |
| ENV PORT=7860 | |
| EXPOSE 7860 | |
| CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT}"] | |