File size: 967 Bytes
1da3a1c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# Use official Python base (slim to keep image small)
FROM python:3.12-slim


# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    libgl1 \
    libglib2.0-0 \
    libsm6 \
    libxext6 \
    libxrender1 \
    && rm -rf /var/lib/apt/lists/*


# Create and switch to a non-root user
RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"


# Set working directory
WORKDIR /app

# Copy requirements first (better cache)
COPY --chown=user ./requirements.txt requirements.txt

# Upgrade pip and install deps
RUN python -m pip install --no-cache-dir --upgrade pip \
 && pip install --no-cache-dir -r requirements.txt

RUN python -c "import clip; clip.load('ViT-B/32', device = 'cpu', jit=False)"

# Copy app code
COPY --chown=user . /app

# Expose the default Spaces port
EXPOSE 7860

# Run FastAPI server (Spaces sets $PORT, default to 7860)
CMD ["bash", "-lc", "uvicorn app:app --host 0.0.0.0 --port ${PORT:-7860}"]