MogensR commited on
Commit
3afcb9b
Β·
verified Β·
1 Parent(s): 5e08b76

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +37 -54
Dockerfile CHANGED
@@ -1,7 +1,7 @@
1
  # ===============================
2
- # Hugging Face Space β€” Hardened Dockerfile
3
  # CUDA 12.1.1 + PyTorch 2.5.1 (cu121) + Streamlit
4
- # SAM2 from source; MatAnyone via pip (repo)
5
  # ===============================
6
  ARG PYTHON_VERSION=3.10
7
  ARG BUILD_TS
@@ -25,10 +25,8 @@ ENV DEBIAN_FRONTEND=noninteractive \
25
  STREAMLIT_SERVER_PORT=7860 \
26
  STREAMLIT_SERVER_HEADLESS=true \
27
  STREAMLIT_BROWSER_GATHER_USAGE_STATS=false \
28
- PYTHONPATH=/home/user/app:/home/user/app/third_party:/home/user/app/third_party/sam2 \
29
  FFMPEG_BIN=ffmpeg \
30
- THIRD_PARTY_SAM2_DIR=/home/user/app/third_party/sam2 \
31
- ENABLE_MATANY=1 \
32
  SAM2_DEVICE=cuda \
33
  MATANY_DEVICE=cuda \
34
  TF_CPP_MIN_LOG_LEVEL=2 \
@@ -46,15 +44,14 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
46
  build-essential gcc g++ pkg-config \
47
  libffi-dev libssl-dev libc6-dev \
48
  libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 libxrender1 libgomp1 \
49
- libopus0 libvpx7 libsrtp2-1 && \
50
  rm -rf /var/lib/apt/lists/*
51
 
52
- # ---- Install FFmpeg with Codecs ----
53
  RUN apt-get update && apt-get install -y --no-install-recommends \
54
- ffmpeg libx264-dev libvpx-dev && \
55
- rm -rf /var/lib/apt/lists/* && \
56
  ffmpeg -version && \
57
- ffmpeg -codecs | grep ffv1 || (echo "Warning: FFmpeg ffv1 codec missing!")
58
 
59
  # ---- Python Bootstrap ----
60
  RUN python3 -m pip install --no-cache-dir --upgrade pip setuptools wheel
@@ -62,37 +59,27 @@ RUN python3 -m pip install --no-cache-dir --upgrade pip setuptools wheel
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 - <<'PY'
66
  import torch
67
- print("PyTorch:", torch.__version__)
68
- print("CUDA available:", torch.cuda.is_available())
69
- print("torch.version.cuda:", getattr(torch.version, "cuda", None))
70
- PY
71
 
72
- # ---- Copy and Install Requirements ----
73
- ENV BUILD_TS_ENV=${BUILD_TS}
74
- COPY --chown=user:user requirements.txt ./
75
- RUN python3 -m pip install --no-cache-dir -r requirements.txt && \
76
- python3 - <<'PY'
77
- import sys, annotated_types, pydantic, pydantic_core
78
- print("Python:", sys.version.split()[0])
79
- print("annotated_types:", annotated_types.__version__)
80
- print("pydantic:", pydantic.__version__, "| pydantic-core:", pydantic_core.__version__)
81
- PY
82
 
83
  # ---- Install MatAnyone ----
84
  RUN echo "Installing MatAnyone..." && \
85
- (python3 -m pip install --no-cache-dir -v git+https://github.com/pq-yang/MatAnyone@main#egg=matanyone || \
86
- python3 -m pip install --no-cache-dir -v git+https://github.com/pq-yang/MatAnyone@0.1.0#egg=matanyone) && \
87
- python3 - <<'PY'
88
- import matanyone
89
- print("βœ… MatAnyone import OK:", getattr(matanyone, "__version__", "unknown"))
90
- PY
91
 
92
  # ---- Install SAM2 (Editable) ----
93
  RUN echo "Installing SAM2..." && \
94
  git clone --depth=1 https://github.com/facebookresearch/segment-anything-2.git third_party/sam2 && \
95
- cd third_party/sam2 && python3 -m pip install --no-cache-dir -e .
 
96
 
97
  # ---- Download SAM2 Checkpoints ----
98
  RUN echo "Downloading SAM2 checkpoints..." && \
@@ -101,46 +88,42 @@ RUN echo "Downloading SAM2 checkpoints..." && \
101
  wget -q --show-progress https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_large.pt && \
102
  echo "βœ… SAM2 checkpoint downloaded"
103
 
104
- # ---- Download SAM2 Config ----
105
- RUN echo "Attempting to download SAM2 configs..." && \
106
- mkdir -p /home/user/app/configs/sam2.1 && \
107
- cd /home/user/app/configs/sam2.1 && \
108
- (wget --timeout=30 --tries=2 -q https://raw.githubusercontent.com/facebookresearch/segment-anything-2/main/configs/sam2.1/sam2.1_hiera_l.yaml && \
109
- echo "βœ… SAM2 config downloaded") || \
110
- echo "⚠️ Config download failed - app will use Hugging Face fallback"
111
 
112
- # ---- Copy App Code ----
113
  COPY --chown=user:user . .
114
 
115
- # ---- Create Writable Directories ----
116
- # ---- Create Writable Directories ----
117
- RUN mkdir -p /home/user/app/checkpoints /home/user/app/.hf /home/user/app/.torch /home/user/app/storage && \
118
- chown -R user:user /home/user/app && \
119
- chmod -R 755 /home/user/app && \
120
- find /home/user/app -type d -exec chmod 755 {} \; && \
121
- find /home/user/app -type f -exec chmod 644 {} \;
122
-
123
  # ---- Healthcheck ----
124
  HEALTHCHECK --interval=30s --timeout=8s --retries=3 CMD \
125
- python3 -c "import torch, streamlit, app; print('torch', torch.__version__, '| cuda', torch.cuda.is_available(), '| streamlit', streamlit.__version__); import subprocess; subprocess.run(['ffmpeg', '-version'])"
 
 
 
 
 
 
126
 
127
  # ---- Runtime Startup ----
128
  USER user
129
  EXPOSE 7860
130
  CMD ["sh", "-c", "\
131
  echo '===========================================' && \
132
- echo '=== STREAMLIT CONTAINER STARTUP ===' && \
133
  echo '===========================================' && \
134
  echo 'Disk free: $(df -h /home/user/app/storage | tail -1)' && \
135
  python3 --version && \
136
  pip --version && \
137
  ffmpeg -version && \
138
  if [ -f streamlit_app.py ]; then \
139
- python3 -B -c 'import streamlit; print(\"βœ… Streamlit:\", streamlit.__version__)'; \
140
- python3 -B -c 'import streamlit_app; print(\"βœ… streamlit_app.py imports OK\")'; \
141
  else \
142
  echo '❌ ERROR: streamlit_app.py not found!' && exit 1; \
143
  fi && \
144
- streamlit run --server.port=${PORT} --server.address=0.0.0.0 --server.maxUploadSize=200 --server.enableCORS=false --server.enableXsrfProtection=false --logger.level=debug streamlit_app.py \
 
 
 
145
  "]
146
-
 
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
  ARG BUILD_TS
 
25
  STREAMLIT_SERVER_PORT=7860 \
26
  STREAMLIT_SERVER_HEADLESS=true \
27
  STREAMLIT_BROWSER_GATHER_USAGE_STATS=false \
28
+ PYTHONPATH=/home/user/app:/home/user/app/pipeline:/home/user/app/models \
29
  FFMPEG_BIN=ffmpeg \
 
 
30
  SAM2_DEVICE=cuda \
31
  MATANY_DEVICE=cuda \
32
  TF_CPP_MIN_LOG_LEVEL=2 \
 
44
  build-essential gcc g++ pkg-config \
45
  libffi-dev libssl-dev libc6-dev \
46
  libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 libxrender1 libgomp1 \
47
+ libopus0 libvpx7 libsrtp2-1 libx264-dev libx265-dev libmp3lame-dev && \
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
 
59
  # ---- Install PyTorch (CUDA 12.1) ----
60
  RUN python3 -m pip install --no-cache-dir --index-url https://download.pytorch.org/whl/cu121 \
61
  torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 && \
62
+ python3 -c "
63
  import torch
64
+ print('PyTorch:', torch.__version__)
65
+ print('CUDA available:', torch.cuda.is_available())
66
+ print('CUDA version:', torch.version.cuda)
67
+ "
68
 
69
+ # ---- Copy Requirements First ----
70
+ COPY requirements.txt .
71
+ RUN python3 -m pip install --no-cache-dir -r requirements.txt
 
 
 
 
 
 
 
72
 
73
  # ---- Install MatAnyone ----
74
  RUN echo "Installing MatAnyone..." && \
75
+ python3 -m pip install --no-cache-dir git+https://github.com/pq-yang/MatAnyone@main && \
76
+ python3 -c "import matanyone; print('βœ… MatAnyone installed:', getattr(matanyone, '__version__', 'unknown'))"
 
 
 
 
77
 
78
  # ---- Install SAM2 (Editable) ----
79
  RUN echo "Installing SAM2..." && \
80
  git clone --depth=1 https://github.com/facebookresearch/segment-anything-2.git third_party/sam2 && \
81
+ cd third_party/sam2 && \
82
+ python3 -m pip install --no-cache-dir -e .
83
 
84
  # ---- Download SAM2 Checkpoints ----
85
  RUN echo "Downloading SAM2 checkpoints..." && \
 
88
  wget -q --show-progress https://dl.fbaipublicfiles.com/segment_anything_2/092824/sam2.1_hiera_large.pt && \
89
  echo "βœ… SAM2 checkpoint downloaded"
90
 
91
+ # ---- Create Directory Structure ----
92
+ RUN mkdir -p /home/user/app/pipeline /home/user/app/models /home/user/app/checkpoints /home/user/app/storage && \
93
+ chown -R user:user /home/user/app && \
94
+ chmod -R 755 /home/user/app
 
 
 
95
 
96
+ # ---- Copy Application Code ----
97
  COPY --chown=user:user . .
98
 
 
 
 
 
 
 
 
 
99
  # ---- Healthcheck ----
100
  HEALTHCHECK --interval=30s --timeout=8s --retries=3 CMD \
101
+ python3 -c "
102
+ import torch, streamlit
103
+ print('torch', torch.__version__, '| cuda', torch.cuda.is_available())
104
+ print('streamlit', streamlit.__version__)
105
+ import subprocess
106
+ subprocess.run(['ffmpeg', '-version'], check=False)
107
+ "
108
 
109
  # ---- Runtime Startup ----
110
  USER user
111
  EXPOSE 7860
112
  CMD ["sh", "-c", "\
113
  echo '===========================================' && \
114
+ echo '=== BACKGROUNDFX PRO STARTUP ===' && \
115
  echo '===========================================' && \
116
  echo 'Disk free: $(df -h /home/user/app/storage | tail -1)' && \
117
  python3 --version && \
118
  pip --version && \
119
  ffmpeg -version && \
120
  if [ -f streamlit_app.py ]; then \
121
+ python3 -c 'import streamlit_app; print(\"βœ… streamlit_app.py imports OK\")'; \
 
122
  else \
123
  echo '❌ ERROR: streamlit_app.py not found!' && exit 1; \
124
  fi && \
125
+ streamlit run --server.port=${PORT} --server.address=0.0.0.0 \
126
+ --server.maxUploadSize=200 --server.enableCORS=false \
127
+ --server.enableXsrfProtection=false --logger.level=debug \
128
+ streamlit_app.py \
129
  "]