fffiloni commited on
Commit
fead15d
·
verified ·
1 Parent(s): fc0a8e9

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +39 -7
Dockerfile CHANGED
@@ -17,14 +17,20 @@ RUN apt-get update && apt-get install -y \
17
  g++ \
18
  && rm -rf /var/lib/apt/lists/*
19
 
 
20
  RUN ln -s /usr/bin/python3 /usr/bin/python || true
21
 
 
22
  RUN useradd -m -u 1000 user
 
23
  USER user
24
 
 
 
 
25
  ENV HOME=/home/user \
26
  PATH=/home/user/.local/bin:$PATH \
27
- PYTHONPATH=/home/user/app \
28
  PYTHONUNBUFFERED=1 \
29
  GRADIO_ALLOW_FLAGGING=never \
30
  GRADIO_NUM_PORTS=1 \
@@ -33,68 +39,94 @@ ENV HOME=/home/user \
33
  GRADIO_SHARE=False \
34
  SYSTEM=spaces
35
 
 
36
  ENV CUDA_HOME=/usr/local/cuda-11.8
37
  ENV TORCH_CUDA_ARCH_LIST="6.0;6.1;7.0;7.5;8.0;8.6+PTX;8.9;9.0"
38
  ENV LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}
 
 
39
  ENV CUDA_DEVICE_ORDER=PCI_BUS_ID
40
  ENV CUDA_VISIBLE_DEVICES=0
41
 
 
42
  RUN git clone https://github.com/google/RB-Modulation.git $HOME/app
43
 
 
44
  RUN if [ ! -d "$HOME/app/third_party/CSD" ]; then \
45
  echo "CSD directory not found in the expected location" && \
46
  exit 1; \
47
  fi
48
 
 
49
  WORKDIR $HOME/app
50
 
 
51
  RUN python3 -m pip install --upgrade pip setuptools wheel
52
 
 
53
  RUN cd third_party/StableCascade/models && \
54
  bash download_models.sh essential big-big bfloat16
55
 
 
56
  RUN cd third_party/StableCascade && \
57
  pip install --no-cache-dir -r requirements.txt && \
58
  pip install --no-cache-dir jupyter notebook opencv-python matplotlib ftfy
59
 
 
60
  RUN pip install --no-cache-dir gdown
61
 
 
62
  RUN gdown https://drive.google.com/uc?id=1FX0xs8p-C7Ob-h5Y4cUhTeOepHzXv_46 -O $HOME/app/third_party/CSD/checkpoint.pth
63
 
 
64
  RUN if [ ! -f "$HOME/app/third_party/CSD/checkpoint.pth" ]; then \
65
  echo "CSD checkpoint file not found" && exit 1; \
66
  fi
67
 
68
  RUN ls -la $HOME/app/third_party/CSD
 
 
69
  RUN touch $HOME/app/third_party/CSD/__init__.py
70
 
 
71
  ENV PYTHONPATH=$HOME/app:$HOME/app/third_party:$PYTHONPATH
72
 
 
73
  RUN python -c "import sys; print('\n'.join(sys.path))"
74
 
75
- RUN pip install --no-cache-dir pybind11>=2.12
76
- RUN pip install --no-cache-dir numpy==1.26.4
77
- RUN pip install --no-cache-dir transformers==4.31.0
78
 
 
79
  RUN python -c "from third_party.CSD import model; print('CSD model successfully imported')" || \
80
  python -c "import sys; sys.path.append('/home/user/app/third_party'); from CSD import model; print('CSD model successfully imported')"
81
 
82
- # Vérifie que torch est bien dispo avant GroundingDINO
83
  RUN python -c "import torch; print('torch ok:', torch.__version__)"
84
 
85
  # Install LangSAM dependencies
86
  RUN pip install --no-cache-dir segment-anything==1.0
87
 
88
- # Fix principal: désactiver le build isolation pour GroundingDINO
89
  RUN pip install --no-cache-dir --no-build-isolation git+https://github.com/IDEA-Research/GroundingDINO.git
90
 
 
 
91
  RUN git clone https://github.com/luca-medeiros/lang-segment-anything /tmp/lang-segment-anything && \
92
  cd /tmp/lang-segment-anything && \
93
  git checkout 9bdf77715fa70fca96452184abdc64a6666e0d46 && \
94
- pip install -e .
 
 
 
 
95
 
 
96
  RUN python3 -m pip install --no-cache-dir gradio==6.13.0 accelerate==1.0.1
97
 
 
98
  COPY --chown=user:user app.py .
99
 
 
100
  CMD ["python3", "app.py"]
 
17
  g++ \
18
  && rm -rf /var/lib/apt/lists/*
19
 
20
+ # Create a symlink for python
21
  RUN ln -s /usr/bin/python3 /usr/bin/python || true
22
 
23
+ # Create a non-root user
24
  RUN useradd -m -u 1000 user
25
+
26
  USER user
27
 
28
+ # Verify CUDA installation path
29
+ RUN find /usr/local -type d -name "cuda*"
30
+
31
  ENV HOME=/home/user \
32
  PATH=/home/user/.local/bin:$PATH \
33
+ PYTHONPATH=$HOME/app \
34
  PYTHONUNBUFFERED=1 \
35
  GRADIO_ALLOW_FLAGGING=never \
36
  GRADIO_NUM_PORTS=1 \
 
39
  GRADIO_SHARE=False \
40
  SYSTEM=spaces
41
 
42
+ # Set CUDA_HOME environment variable
43
  ENV CUDA_HOME=/usr/local/cuda-11.8
44
  ENV TORCH_CUDA_ARCH_LIST="6.0;6.1;7.0;7.5;8.0;8.6+PTX;8.9;9.0"
45
  ENV LD_LIBRARY_PATH=${CUDA_HOME}/lib64:${LD_LIBRARY_PATH}
46
+
47
+ # Set the environment variable to specify the GPU device
48
  ENV CUDA_DEVICE_ORDER=PCI_BUS_ID
49
  ENV CUDA_VISIBLE_DEVICES=0
50
 
51
+ # Clone the RB-Modulation repository
52
  RUN git clone https://github.com/google/RB-Modulation.git $HOME/app
53
 
54
+ # Ensure CSD directory exists and is in the correct location
55
  RUN if [ ! -d "$HOME/app/third_party/CSD" ]; then \
56
  echo "CSD directory not found in the expected location" && \
57
  exit 1; \
58
  fi
59
 
60
+ # Set the working directory
61
  WORKDIR $HOME/app
62
 
63
+ # Upgrade build tools
64
  RUN python3 -m pip install --upgrade pip setuptools wheel
65
 
66
+ # Download pretrained models
67
  RUN cd third_party/StableCascade/models && \
68
  bash download_models.sh essential big-big bfloat16
69
 
70
+ # Install StableCascade requirements
71
  RUN cd third_party/StableCascade && \
72
  pip install --no-cache-dir -r requirements.txt && \
73
  pip install --no-cache-dir jupyter notebook opencv-python matplotlib ftfy
74
 
75
+ # Install gdown for Google Drive downloads
76
  RUN pip install --no-cache-dir gdown
77
 
78
+ # Download pre-trained CSD weights
79
  RUN gdown https://drive.google.com/uc?id=1FX0xs8p-C7Ob-h5Y4cUhTeOepHzXv_46 -O $HOME/app/third_party/CSD/checkpoint.pth
80
 
81
+ # Verify the download
82
  RUN if [ ! -f "$HOME/app/third_party/CSD/checkpoint.pth" ]; then \
83
  echo "CSD checkpoint file not found" && exit 1; \
84
  fi
85
 
86
  RUN ls -la $HOME/app/third_party/CSD
87
+
88
+ # Ensure CSD is a proper Python package
89
  RUN touch $HOME/app/third_party/CSD/__init__.py
90
 
91
+ # Update PYTHONPATH
92
  ENV PYTHONPATH=$HOME/app:$HOME/app/third_party:$PYTHONPATH
93
 
94
+ # Print Python path
95
  RUN python -c "import sys; print('\n'.join(sys.path))"
96
 
97
+ RUN pip install --no-cache-dir pybind11>=2.12 && \
98
+ pip install --no-cache-dir numpy==1.26.4 && \
99
+ pip install --no-cache-dir transformers==4.31.0
100
 
101
+ # Verify CSD module can be imported (try different methods)
102
  RUN python -c "from third_party.CSD import model; print('CSD model successfully imported')" || \
103
  python -c "import sys; sys.path.append('/home/user/app/third_party'); from CSD import model; print('CSD model successfully imported')"
104
 
105
+ # Verify torch is available before installing GroundingDINO
106
  RUN python -c "import torch; print('torch ok:', torch.__version__)"
107
 
108
  # Install LangSAM dependencies
109
  RUN pip install --no-cache-dir segment-anything==1.0
110
 
111
+ # Important fix: disable build isolation for GroundingDINO
112
  RUN pip install --no-cache-dir --no-build-isolation git+https://github.com/IDEA-Research/GroundingDINO.git
113
 
114
+ # Install lang-segment-anything without dependencies
115
+ # to avoid reinstalling GroundingDINO in isolated build mode
116
  RUN git clone https://github.com/luca-medeiros/lang-segment-anything /tmp/lang-segment-anything && \
117
  cd /tmp/lang-segment-anything && \
118
  git checkout 9bdf77715fa70fca96452184abdc64a6666e0d46 && \
119
+ pip install --no-deps -e .
120
+
121
+ # Optional sanity checks
122
+ RUN python -c "import groundingdino; print('groundingdino ok')"
123
+ RUN python -c "import lang_sam; print('lang_sam ok')"
124
 
125
+ # Upgrade pip and install Gradio
126
  RUN python3 -m pip install --no-cache-dir gradio==6.13.0 accelerate==1.0.1
127
 
128
+ # Copy the app.py file from the host to the container
129
  COPY --chown=user:user app.py .
130
 
131
+ # Command to run the Gradio app
132
  CMD ["python3", "app.py"]