File size: 3,017 Bytes
fac7e31
30c62ef
67e3305
0ae4d18
30c62ef
fac7e31
30c62ef
 
 
 
 
 
10d49cc
 
d8472b3
 
 
7844438
 
 
30c62ef
fac7e31
30c62ef
 
 
 
 
 
10d49cc
 
30c62ef
 
 
 
 
 
 
 
 
 
fac7e31
30c62ef
 
 
 
 
0fc713e
 
 
 
30c62ef
0fc713e
 
30c62ef
 
 
0fc713e
 
 
30c62ef
 
 
 
 
 
 
 
 
 
 
fac7e31
30c62ef
 
fac7e31
 
 
30c62ef
 
 
 
fac7e31
30c62ef
 
7844438
0fc713e
 
7844438
0fc713e
 
 
fac7e31
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

# Use NVIDIA CUDA base image (Ubuntu 22.04 jammy)
FROM nvidia/cuda:12.3.2-devel-ubuntu22.04


# Non-interactive apt
ENV DEBIAN_FRONTEND=noninteractive
ENV PYTHONUNBUFFERED=1
ENV CUDA_HOME=/usr/local/cuda
ENV PATH=${CUDA_HOME}/bin:/usr/local/bin:${PATH}
ENV LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}

ENV OMP_NUM_THREADS=4

# Environment variables for off-screen rendering
ENV PYVISTA_OFF_SCREEN=true
ENV VTK_DEFAULT_RENDER_WINDOW_OFFSCREEN=1
ENV DISPLAY=:99
ENV LIBGL_ALWAYS_SOFTWARE=1
ENV MESA_GL_VERSION_OVERRIDE=3.3

# System deps + Deadsnakes PPA for Python 3.12
RUN apt-get update && apt-get install -y --no-install-recommends \
    software-properties-common \
    ca-certificates \
    curl wget git build-essential \
    libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 libxrender1 \
    libgomp1 libgcc-s1 \
    libosmesa6 libosmesa6-dev \
    libegl1-mesa libegl1-mesa-dev \
 && add-apt-repository ppa:deadsnakes/ppa -y \
 && apt-get update && apt-get install -y --no-install-recommends \
    python3.12 python3.12-dev python3.12-venv \
 && rm -rf /var/lib/apt/lists/*

# Install pip for Python 3.12
RUN curl -sS https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py \
 && python3.12 /tmp/get-pip.py \
 && rm /tmp/get-pip.py

# Make 'python' and 'pip' point to 3.12
RUN ln -sf /usr/bin/python3.12 /usr/bin/python && \
    ln -sf /usr/local/bin/pip3.12 /usr/local/bin/pip

# ---------------- Writable app data & HF cache ----------------
ENV APP_DATA_DIR=/data
ENV HF_HOME=/data/shared/hf_home
ENV HUGGINGFACE_HUB_CACHE=/data/shared/hf_home
ENV TRANSFORMERS_CACHE=/data/shared/hf_home
ENV MPLCONFIGDIR=/data/matplotlib

# Create shared directories (for models/HF cache) and per-user directories will be created at runtime
RUN mkdir -p /data/shared/weights /data/shared/hf_home /data/matplotlib \
 && chmod -R 777 /data

# ---------------- Install frpc for Gradio share=True ----------------
RUN mkdir -p /data/shared/hf_home/gradio/frpc && \
    wget https://cdn-media.huggingface.co/frpc-gradio-0.3/frpc_linux_amd64 -O /data/shared/hf_home/gradio/frpc/frpc_linux_amd64_v0.3 && \
    chmod +x /data/shared/hf_home/gradio/frpc/frpc_linux_amd64_v0.3

# ---------------- Application setup ----------------
WORKDIR /app

# Copy requirements first (better caching)
COPY requirements.txt .

# Install Python deps
RUN pip install --no-cache-dir --upgrade pip setuptools wheel \
 && pip install --no-cache-dir -r requirements.txt

# Copy the rest of the source
COPY . .

# Create cache directory for downloaded repos
RUN mkdir -p /app/cache && chmod 777 /app/cache

# Permissions
RUN chmod +x app.py
RUN chown -R 1000:1000 /app

# Expose Gradio port
EXPOSE 7860

# Set HOST and PORT via environment variables
# ENV HOST=0.0.0.0
# ENV PORT=7860

# Run app with trame.tools.serve; bind explicitly to 0.0.0.0:7860
# This uses the create_app factory pattern for proper multi-user session management
CMD ["python", "-m", "trame.tools.serve", "--exec", "app:create_app", "--host", "0.0.0.0", "--port", "7860"]