File size: 2,514 Bytes
63c5889
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
FROM ubuntu:24.04

# ENV PIP_ROOT_USER_ACTION=ignore
ARG USERNAME=mcp_user
ARG USER_UID=1000
ARG APP_WORKDIR=app_srv

# Update OS and install packages
WORKDIR /tmp/
COPY requirements.txt packages.txt ./
RUN apt-get -y update && apt-get -y upgrade 
# RUN xargs apt -y install < packages.txt
RUN apt-get -y install ffmpeg git git-lfs htop iotop libxml2 libopenblas-dev libssl-dev python3-pip python3-wheel python3-setuptools python-is-python3 wget zlib1g net-tools curl

# Install CUDA 12.8 from Internet
RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb \
    && dpkg -i cuda-keyring_1.1-1_all.deb \
    && apt-get update \
    && apt-get -y install cuda-toolkit-12-8
# https://docs.nvidia.com/cuda/cuda-installation-guide-linux/#post-installation-actions
ENV PATH=/usr/local/cuda-12.8/bin:${PATH}									
ENV LD_LIBRARY_PATH=/usr/local/cuda-12.8/lib64:/usr/lib/x86_64-linux-gnu/

# Install cuDNN for CUDA 12
RUN wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb \
	&& dpkg -i cuda-keyring_1.1-1_all.deb \
	&& apt-get update \
	&& apt-get -y install cudnn-cuda-12

# Remove EXTERNALLY-MANAGED
RUN rm -f /usr/lib/python3.12/EXTERNALLY-MANAGED

# Install Pytorch for CUDA 12.8
RUN pip3 install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128

# Install other python packages
RUN pip3 install --no-cache-dir -r requirements.txt

# Final image cleanup
RUN apt-get clean
RUN rm -rf /tmp/*

# Preparing an image for HuggingFace Space
## Delete exist user with UID 1000
RUN userdel -r ubuntu || true

## Set up a new user with user ID 1000
## https://huggingface.co/docs/hub/spaces-sdks-docker#permissions
RUN useradd -s /bin/bash -m -u $USER_UID $USERNAME

## Switch to the "user" user
USER $USERNAME

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

## Copy the contents of the application directory to the /home/mcp_user/app_srv container directory, setting mcp_user as the user owner
RUN mkdir -p $HOME/$APP_WORKDIR
COPY --chown=$USERNAME ./$APP_WORKDIR/* $HOME/$APP_WORKDIR

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

# Gradio network configuration 
EXPOSE 7860
ENV GRADIO_SERVER_NAME="0.0.0.0"

# Temporarily set an environment variable for unbuffered output. The goal is to test the application.
ENV PYTHONUNBUFFERED=1

CMD ["python", "app_srv.py"]