File size: 949 Bytes
6324c73
 
c585d1d
6324c73
 
c585d1d
6324c73
 
 
d9aac0b
6324c73
 
33d016f
6324c73
c585d1d
 
 
6324c73
 
c585d1d
6324c73
c585d1d
 
6324c73
 
 
 
 
 
 
c585d1d
 
6324c73
c585d1d
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
# Use a lightweight Python base image
FROM python:3.9-slim

# Set working directory
WORKDIR /code

# Install system dependencies required for OpenCV
# libgl1-mesa-glx and libglib2.0-0 are critical for cv2 to work in Docker
RUN apt-get update && apt-get install -y \
    libgl1\
    libglib2.0-0 \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements file first to leverage Docker caching
COPY requirements.txt .

# Install Python dependencies
# We use the CPU version of PyTorch to keep the image size small for deployment
RUN pip install --no-cache-dir --upgrade -r requirements.txt

# Copy the application code and the model
COPY . .

# Create a non-root user (Hugging Face security requirement)
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# Expose the port Hugging Face expects
EXPOSE 7860

# Command to run the application
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]