dreamtalk / Dockerfile
fffiloni's picture
Update Dockerfile
2f498ec verified
raw
history blame
3.3 kB
# Use the official PyTorch image as the base
FROM pytorch/pytorch:2.0.1-cuda11.7-cudnn8-runtime
# Set environment variables
ENV DEBIAN_FRONTEND=noninteractive \
MKL_THREADING_LAYER=GNU \
HOME=/home/user \
PYTHONPATH=/home/user/app \
PYTHONUNBUFFERED=1 \
GRADIO_ALLOW_FLAGGING=never \
GRADIO_NUM_PORTS=1 \
GRADIO_SERVER_NAME=0.0.0.0 \
GRADIO_THEME=huggingface \
GRADIO_SHARE=False \
SYSTEM=spaces \
CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \
CUDA_HOME=/usr/local/cuda \
LD_LIBRARY_PATH=/usr/local/cuda/lib64 \
TORCH_CUDA_ARCH_LIST="8.6" \
CMAKE_PREFIX_PATH="/usr/local/cuda:/usr/lib/x86_64-linux-gnu/"
# Override PATH so that system Python 3.9 takes precedence over Conda’s Python 3.10
ENV PATH="/usr/local/cuda/bin:/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/sbin"
# Install Python 3.9 and build dependencies (including those needed for NumPy)
RUN apt-get update && \
apt-get install -y --no-install-recommends \
python3.9 python3.9-dev python3.9-venv \
git wget libgl1-mesa-glx libglib2.0-0 ffmpeg libx264-dev pkg-config \
build-essential gfortran libopenblas-dev liblapack-dev \
cmake g++ software-properties-common gnupg2 && \
rm -rf /var/lib/apt/lists/*
# Set Python 3.9 as default for python3, install pip (using wget instead of curl), and create symlinks
RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 1 && \
update-alternatives --set python3 /usr/bin/python3.9 && \
wget -qO- https://bootstrap.pypa.io/get-pip.py | python3.9 && \
ln -sf /usr/bin/python3.9 /usr/bin/python && \
ln -sf /usr/bin/pip3 /usr/bin/pip
# Upgrade pip, setuptools, and wheel
RUN python3.9 -m pip install --upgrade pip setuptools wheel
# Add NVIDIA package repositories and install CUDA Toolkit and cuDNN
RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb && \
dpkg -i cuda-keyring_1.0-1_all.deb && \
apt-get update && \
apt-get install -y --no-install-recommends \
cuda-toolkit-11-7 libcudnn8 libcudnn8-dev && \
rm -rf /var/lib/apt/lists/*
# Create a non-root user and switch to it
RUN useradd -m -u 1000 user
USER user
# Set working directory
WORKDIR /home/user/app
# Clone the repository
RUN git clone -b dev https://github.com/fffiloni/dreamtalk .
# Download model checkpoints
RUN mkdir -p checkpoints && \
wget https://huggingface.co/camenduru/dreamtalk/resolve/main/damo/dreamtalk/checkpoints/denoising_network.pth -O checkpoints/denoising_network.pth && \
wget https://huggingface.co/camenduru/dreamtalk/resolve/main/damo/dreamtalk/checkpoints/renderer.pt -O checkpoints/renderer.pt
# Pre-install NumPy (version as specified in requirements_HF.txt) to avoid build issues
RUN python3.9 -m pip install numpy==1.26.4
# Copy and install remaining Python dependencies
COPY requirements_HF.txt .
RUN python3.9 -m pip install --no-cache-dir -r requirements_HF.txt && \
python3.9 -m pip install --no-cache-dir "moviepy<2" gradio
# Copy the application file
COPY app.py .
# Set additional CUDA environment variables if needed
ENV CUDA_DEVICE_ORDER=PCI_BUS_ID \
CUDA_VISIBLE_DEVICES=0
# Run the application explicitly with Python 3.9
CMD ["python3.9", "app.py"]