File size: 1,446 Bytes
a63cedf
 
 
 
 
 
55e74ff
 
a63cedf
 
 
 
 
 
 
98b0b74
 
 
 
 
a63cedf
98b0b74
 
 
 
 
a63cedf
98b0b74
 
 
 
a63cedf
98b0b74
a63cedf
 
 
98b0b74
a63cedf
 
98b0b74
 
a63cedf
98b0b74
 
 
a63cedf
98b0b74
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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}"]