File size: 1,610 Bytes
7a4f715
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
58
59
60
61
62
63
64
65
66
67
# Use Python 3.11 slim image as base
FROM python:3.11-slim

# Set up a new user named "user" with user ID 1000 (HF requirement)
RUN useradd -m -u 1000 user

# Switch to the "user" user
USER user

# Set home to the user's home directory
ENV HOME=/home/user \
    PATH=/home/user/.local/bin:$PATH

# Set the working directory to the user's home directory
WORKDIR $HOME/app

# Install system dependencies for OpenCV, Graphviz, and other packages
# Switch to root temporarily for system package installation
USER root
RUN apt-get update && apt-get install -y \
    graphviz \
    libgraphviz-dev \
    libglib2.0-0 \
    libsm6 \
    libxext6 \
    libxrender-dev \
    libgomp1 \
    libgl1-mesa-glx \
    libgtk-3-0 \
    libavcodec-dev \
    libavformat-dev \
    libswscale-dev \
    libv4l-dev \
    libxvidcore-dev \
    libx264-dev \
    libjpeg-dev \
    libpng-dev \
    libtiff-dev \
    libatlas-base-dev \
    python3-dev \
    && rm -rf /var/lib/apt/lists/*

# Switch back to user
USER user

# Copy requirements first for better caching (with proper ownership)
COPY --chown=user requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip
RUN pip install --no-cache-dir -r requirements.txt

# Copy the application code (with proper ownership)
COPY --chown=user . $HOME/app

# Create necessary directories with proper permissions
RUN mkdir -p data/demos data/working data/output data/templates

# Set environment variables
ENV PYTHONPATH=$HOME/app
ENV PYTHONUNBUFFERED=1

# Expose the port that Gradio uses
EXPOSE 7860

# Run the application
CMD ["python", "app.py"]