MogensR commited on
Commit
4e70c9a
Β·
verified Β·
1 Parent(s): d19b4ae

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +48 -39
Dockerfile CHANGED
@@ -1,7 +1,7 @@
1
  # ===============================
2
- # BackgroundFX Pro β€” Hardened Dockerfile
3
  # CUDA 12.1.1 + PyTorch 2.5.1 (cu121) + Streamlit
4
- # Optimized for SAM2 + MatAnyone with Audio Support
5
  # ===============================
6
  ARG PYTHON_VERSION=3.10
7
  FROM nvidia/cuda:12.1.1-cudnn8-runtime-ubuntu22.04
@@ -36,7 +36,7 @@ RUN useradd -m -u 1000 user
36
  ENV HOME=/home/user
37
  WORKDIR $HOME/app
38
 
39
- # ---- System Dependencies ----
40
  RUN apt-get update && apt-get install -y --no-install-recommends \
41
  git wget curl ca-certificates \
42
  python3 python3-pip python3-venv python3-dev \
@@ -44,34 +44,39 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
44
  libffi-dev libssl-dev libc6-dev \
45
  libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 libxrender1 libgomp1 \
46
  libopus0 libvpx7 libsrtp2-1 libx264-dev libx265-dev libmp3lame-dev \
47
- libblas-dev liblapack-dev gfortran && \
48
- rm -rf /var/lib/apt/lists/*
 
49
 
50
- # ---- Install FFmpeg with Full Codec Support ----
51
- RUN apt-get update && apt-get install -y --no-install-recommends \
52
- ffmpeg && \
53
- ffmpeg -version && \
54
- ffmpeg -codecs | grep -E 'ffv1|libx264|libx265|aac|mp3' || echo "Warning: Some FFmpeg codecs missing"
55
 
56
  # ---- Python Bootstrap ----
57
  RUN python3 -m pip install --no-cache-dir --upgrade pip setuptools wheel
58
 
59
- # ---- Install NumPy ----
60
  RUN python3 -m pip install --no-cache-dir numpy==1.24.4
61
 
 
 
 
62
  # ---- Install PyTorch (CUDA 12.1) ----
63
  RUN python3 -m pip install --no-cache-dir --index-url https://download.pytorch.org/whl/cu121 \
64
- torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 && \
65
- python3 -c "import torch; print('PyTorch:', torch.__version__); print('CUDA available:', torch.cuda.is_available()); print('CUDA version:', torch.version.cuda)"
66
 
67
- # ---- Copy Requirements First ----
68
  COPY requirements.txt .
69
  RUN python3 -m pip install --no-cache-dir -r requirements.txt
70
 
 
 
 
71
  # ---- Install MatAnyone ----
72
  RUN echo "Installing MatAnyone..." && \
73
- python3 -m pip install --no-cache-dir git+https://github.com/pq-yang/MatAnyone.git && \
74
- python3 -c "import matanyone; print('βœ… MatAnyone installed:', getattr(matanyone, '__version__', 'unknown'))"
75
 
76
  # ---- Install SAM2 (Editable) ----
77
  RUN echo "Installing SAM2..." && \
@@ -80,14 +85,12 @@ RUN echo "Installing SAM2..." && \
80
  python3 -m pip install --no-cache-dir -e .
81
 
82
  # ---- Download SAM2 Checkpoints ----
83
- RUN echo "Downloading SAM2 checkpoints..." && \
84
- mkdir -p /home/user/app/checkpoints && \
85
- cd /home/user/app/checkpoints && \
86
- wget -q --show-progress https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_large.pt && \
87
- echo "βœ… SAM2 checkpoint downloaded"
88
 
89
  # ---- Create Directory Structure ----
90
- RUN mkdir -p /home/user/app/pipeline /home/user/app/models /home/user/app/checkpoints /home/user/app/storage && \
91
  chown -R user:user /home/user/app && \
92
  chmod -R 755 /home/user/app
93
 
@@ -96,26 +99,32 @@ COPY --chown=user:user . .
96
 
97
  # ---- Healthcheck ----
98
  HEALTHCHECK --interval=30s --timeout=8s --retries=3 CMD \
99
- python3 -c "import torch, streamlit, numpy; print('torch', torch.__version__, '| cuda', torch.cuda.is_available()); print('streamlit', streamlit.__version__); print('numpy', numpy.__version__); import subprocess; subprocess.run(['ffmpeg', '-version'], check=False)"
 
 
 
 
 
 
100
 
101
  # ---- Runtime Startup ----
102
  USER user
103
  EXPOSE 7860
104
- CMD ["sh", "-c", "\
105
- echo '===========================================' && \
106
- echo '=== BACKGROUNDFX PRO STARTUP ===' && \
107
- echo '===========================================' && \
108
- echo 'Disk free: $(df -h /home/user/app/storage | tail -1)' && \
109
- python3 --version && \
110
- pip --version && \
111
- ffmpeg -version && \
112
- if [ -f streamlit_app.py ]; then \
113
- python3 -c 'import streamlit_app; print(\"βœ… streamlit_app.py imports OK\")'; \
114
- else \
115
- echo '❌ ERROR: streamlit_app.py not found!' && exit 1; \
116
- fi && \
117
- streamlit run --server.port=${PORT} --server.address=0.0.0.0 \
118
  --server.maxUploadSize=200 --server.enableCORS=false \
119
  --server.enableXsrfProtection=false --logger.level=debug \
120
- streamlit_app.py \
121
- "]
 
1
  # ===============================
2
+ # BackgroundFX Pro β€” Final Dockerfile
3
  # CUDA 12.1.1 + PyTorch 2.5.1 (cu121) + Streamlit
4
+ # Optimized for SAM2 + MatAnyone + MediaPipe
5
  # ===============================
6
  ARG PYTHON_VERSION=3.10
7
  FROM nvidia/cuda:12.1.1-cudnn8-runtime-ubuntu22.04
 
36
  ENV HOME=/home/user
37
  WORKDIR $HOME/app
38
 
39
+ # ---- System Dependencies (Including NumPy/Matplotlib Requirements) ----
40
  RUN apt-get update && apt-get install -y --no-install-recommends \
41
  git wget curl ca-certificates \
42
  python3 python3-pip python3-venv python3-dev \
 
44
  libffi-dev libssl-dev libc6-dev \
45
  libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 libxrender1 libgomp1 \
46
  libopus0 libvpx7 libsrtp2-1 libx264-dev libx265-dev libmp3lame-dev \
47
+ libblas-dev liblapack-dev gfortran \
48
+ libfreetype6-dev libpng-dev libjpeg-dev \
49
+ && rm -rf /var/lib/apt/lists/*
50
 
51
+ # ---- Install FFmpeg ----
52
+ RUN apt-get update && apt-get install -y --no-install-recommends ffmpeg \
53
+ && rm -rf /var/lib/apt/lists/*
 
 
54
 
55
  # ---- Python Bootstrap ----
56
  RUN python3 -m pip install --no-cache-dir --upgrade pip setuptools wheel
57
 
58
+ # ---- Install NumPy First (Critical) ----
59
  RUN python3 -m pip install --no-cache-dir numpy==1.24.4
60
 
61
+ # ---- Install Matplotlib with System Dependencies ----
62
+ RUN python3 -m pip install --no-cache-dir matplotlib==3.5.0
63
+
64
  # ---- Install PyTorch (CUDA 12.1) ----
65
  RUN python3 -m pip install --no-cache-dir --index-url https://download.pytorch.org/whl/cu121 \
66
+ torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 \
67
+ && python3 -c "import torch; print('PyTorch:', torch.__version__); print('CUDA available:', torch.cuda.is_available())"
68
 
69
+ # ---- Copy Requirements ----
70
  COPY requirements.txt .
71
  RUN python3 -m pip install --no-cache-dir -r requirements.txt
72
 
73
+ # ---- Install MediaPipe (After NumPy/Matplotlib) ----
74
+ RUN python3 -m pip install --no-cache-dir mediapipe==0.10.11
75
+
76
  # ---- Install MatAnyone ----
77
  RUN echo "Installing MatAnyone..." && \
78
+ python3 -m pip install --no-cache-dir git+https://github.com/pq-yang/MatAnyone.git \
79
+ && python3 -c "import matanyone; print('βœ… MatAnyone installed')"
80
 
81
  # ---- Install SAM2 (Editable) ----
82
  RUN echo "Installing SAM2..." && \
 
85
  python3 -m pip install --no-cache-dir -e .
86
 
87
  # ---- Download SAM2 Checkpoints ----
88
+ RUN mkdir -p /home/user/app/checkpoints && \
89
+ wget -q --show-progress -O /home/user/app/checkpoints/sam2.1_hiera_large.pt \
90
+ https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_large.pt
 
 
91
 
92
  # ---- Create Directory Structure ----
93
+ RUN mkdir -p /home/user/app/pipeline /home/user/app/models /home/user/app/storage && \
94
  chown -R user:user /home/user/app && \
95
  chmod -R 755 /home/user/app
96
 
 
99
 
100
  # ---- Healthcheck ----
101
  HEALTHCHECK --interval=30s --timeout=8s --retries=3 CMD \
102
+ python3 -c "
103
+ import numpy; print('NumPy:', numpy.__version__)
104
+ import matplotlib; print('Matplotlib:', matplotlib.__version__)
105
+ import torch; print('PyTorch:', torch.__version__)
106
+ import mediapipe; print('MediaPipe:', mediapipe.__version__)
107
+ import subprocess; subprocess.run(['ffmpeg', '-version'], check=False)
108
+ "
109
 
110
  # ---- Runtime Startup ----
111
  USER user
112
  EXPOSE 7860
113
+ CMD ["sh", "-c", "
114
+ echo '==========================================='
115
+ echo '=== BACKGROUNDFX PRO STARTUP ==='
116
+ echo '==========================================='
117
+ echo 'Disk free: $(df -h /home/user/app/storage | tail -1)'
118
+ python3 --version
119
+ pip --version
120
+ ffmpeg -version
121
+ if [ -f streamlit_app.py ]; then
122
+ python3 -c 'import streamlit_app; print(\"βœ… streamlit_app.py imports OK\")'
123
+ else
124
+ echo '❌ ERROR: streamlit_app.py not found!' && exit 1
125
+ fi
126
+ exec streamlit run --server.port=${PORT} --server.address=0.0.0.0 \
127
  --server.maxUploadSize=200 --server.enableCORS=false \
128
  --server.enableXsrfProtection=false --logger.level=debug \
129
+ streamlit_app.py
130
+ "]