File size: 1,803 Bytes
87f0e66
7395d35
 
87f0e66
 
 
7395d35
3d24b7c
87f0e66
3d24b7c
 
 
 
 
 
 
 
 
 
87f0e66
3d24b7c
 
 
 
 
7395d35
87f0e66
 
 
092dbd4
 
 
 
87f0e66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7395d35
87f0e66
 
7395d35
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
55
56
57
# Use an official Python runtime as a parent image
FROM python:3.9

# Set environment variables that don't depend on the user
ENV PYTHONUNBUFFERED 1
ENV PIP_NO_CACHE_DIR=1 

# Install system dependencies required by OpenCV and other libraries
# These commands need to run as root
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    libgl1-mesa-glx \
    libgl1 \
    libglx-mesa0 \
    libopengl0 \
    libglib2.0-0 \
    libsm6 \
    libxext6 \
    libxrender-dev \
    # ffmpeg is useful for video processing if cv2 needs it for certain codecs.
    # Add it if you encounter video format issues.
    # ffmpeg \ 
    && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Now, create and switch to the non-root user
RUN useradd -m -u 1000 user
USER user

# Set PATH for the non-root user
# Comments for ENV should be on a separate line above
ENV PATH="/home/user/.local/bin:${PATH}"

# Set the working directory in the container (as the non-root user)
WORKDIR /app

# Copy the requirements file into the container at /app
# Ensure the user owns this file after copying
COPY --chown=user:user ./requirements.txt requirements.txt

# Install any needed packages specified in requirements.txt
# This will run as the non-root user, installing packages into the user's site-packages
RUN pip install --no-cache-dir --upgrade pip && \
    pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application code into the container at /app
# Ensure the user owns these files
COPY --chown=user:user . /app

# Expose port (Hugging Face Spaces typically use 7860 for web apps)
EXPOSE 7860

# Command to run the application using uvicorn
# It will listen on all available network interfaces (0.0.0.0)
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]