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