File size: 1,280 Bytes
1da3a1c
7a40dcb
1da3a1c
 
 
 
 
 
 
 
 
 
 
0e43eb4
d5fddc6
 
 
 
 
 
 
 
 
 
 
 
 
1da3a1c
0e43eb4
 
 
 
 
1da3a1c
 
 
 
 
 
 
 
896cf29
 
 
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
42
43
44
45
46
47
48
49
50
51
52
53
54
# Use official Python base (slim to keep image small)
FROM python:3.11.9


# 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/*
    
RUN apt-get update && apt-get install -y \
    libxi6 \
    libsm6 \
    libxrender1 \
    libgl1-mesa-glx \
    libglib2.0-0 \
    libxkbcommon-x11-0 \
    libxxf86vm1 \
    libxfixes3 \
    libegl1 \
    libgomp1 \
    # Clean up apt cache to reduce image size
    && 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 \
 && pip list

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}"]