Fred808 commited on
Commit
68dc224
·
verified ·
1 Parent(s): b70de74

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +35 -15
Dockerfile CHANGED
@@ -1,20 +1,22 @@
1
  FROM python:3.11-slim-bullseye
2
 
3
- # Install system dependencies
4
  RUN sed -i 's/main/main contrib non-free/' /etc/apt/sources.list && \
5
  apt-get update && \
6
  apt-get install -y --no-install-recommends \
7
  unrar \
8
  libgl1 \
9
  libglib2.0-0 \
 
 
10
  && rm -rf /var/lib/apt/lists/*
11
-
12
  WORKDIR /app
13
 
14
  # Upgrade pip and install core dependencies first
15
  RUN pip install --no-cache-dir --upgrade pip setuptools wheel packaging
16
 
17
- # Install CPU-only PyTorch first
18
  RUN pip install --no-cache-dir \
19
  "numpy<2" \
20
  torch==2.1.2+cpu \
@@ -22,30 +24,48 @@ RUN pip install --no-cache-dir \
22
  torchaudio==2.1.2+cpu \
23
  --index-url https://download.pytorch.org/whl/cpu
24
 
25
- # Copy requirements and install with special handling for flash_attn
26
  COPY requirements.txt .
27
  RUN pip install --no-cache-dir \
28
  -r requirements.txt \
29
  --find-links https://download.pytorch.org/whl/cpu \
30
- --extra-index-url https://pypi.org/simple && \
31
- # Install remaining packages that might have been skipped
32
- pip install --no-cache-dir \
33
- accelerate \
 
34
  transformers==4.36.2 \
35
  timm==0.9.12 \
36
- einops==0.7.0
 
37
 
38
- # Copy application code
39
- COPY . .
 
 
40
 
41
- # Create non-root user
 
 
 
42
  RUN useradd -m -u 1000 user && \
43
- chown -R user:user /app
 
 
44
 
45
  USER user
46
 
47
- # Environment variables to suppress warnings
48
  ENV HF_HUB_DISABLE_PROGRESS=1
49
  ENV TF_CPP_MIN_LOG_LEVEL=3
 
 
 
 
 
 
 
 
 
50
 
51
- CMD ["uvicorn", "download_api:app", "--host", "0.0.0.0", "--port", "7860"]
 
1
  FROM python:3.11-slim-bullseye
2
 
3
+ # Install system dependencies with clean up in single RUN layer
4
  RUN sed -i 's/main/main contrib non-free/' /etc/apt/sources.list && \
5
  apt-get update && \
6
  apt-get install -y --no-install-recommends \
7
  unrar \
8
  libgl1 \
9
  libglib2.0-0 \
10
+ ffmpeg \ # For video processing
11
+ git \ # Some transformers dependencies need git
12
  && rm -rf /var/lib/apt/lists/*
13
+
14
  WORKDIR /app
15
 
16
  # Upgrade pip and install core dependencies first
17
  RUN pip install --no-cache-dir --upgrade pip setuptools wheel packaging
18
 
19
+ # Install optimized CPU-only PyTorch stack
20
  RUN pip install --no-cache-dir \
21
  "numpy<2" \
22
  torch==2.1.2+cpu \
 
24
  torchaudio==2.1.2+cpu \
25
  --index-url https://download.pytorch.org/whl/cpu
26
 
27
+ # Copy requirements and install with special handling
28
  COPY requirements.txt .
29
  RUN pip install --no-cache-dir \
30
  -r requirements.txt \
31
  --find-links https://download.pytorch.org/whl/cpu \
32
+ --extra-index-url https://pypi.org/simple
33
+
34
+ # Install transformers with specific version that works with BLIP-2
35
+ RUN pip install --no-cache-dir \
36
+ accelerate==0.27.2 \
37
  transformers==4.36.2 \
38
  timm==0.9.12 \
39
+ einops==0.7.0 \
40
+ bitsandbytes==0.42.0 # Helps with memory optimization
41
 
42
+ # For BLIP-2 specifically, we need these
43
+ RUN pip install --no-cache-dir \
44
+ protobuf==3.20.3 \
45
+ sentencepiece==0.2.0
46
 
47
+ # Copy application code with proper permissions
48
+ COPY --chown=1000:1000 . .
49
+
50
+ # Create non-root user and set permissions
51
  RUN useradd -m -u 1000 user && \
52
+ chown -R user:user /app && \
53
+ mkdir -p /app/downloads /app/extracted /app/extracted_frames /app/analysis_results && \
54
+ chown -R user:user /app/*
55
 
56
  USER user
57
 
58
+ # Environment variables for better performance and less logging
59
  ENV HF_HUB_DISABLE_PROGRESS=1
60
  ENV TF_CPP_MIN_LOG_LEVEL=3
61
+ ENV PYTORCH_NO_CUDA_MEMORY_CACHING=1
62
+ ENV TOKENIZERS_PARALLELISM=false
63
+ ENV PYTHONUNBUFFERED=1
64
+
65
+ # Set this if you're only using CPU
66
+ ENV CUDA_VISIBLE_DEVICES=""
67
+
68
+ # Pre-download the BLIP-2 model during build (optional)
69
+ # RUN python -c "from transformers import AutoModel; AutoModel.from_pretrained('Salesforce/blip2-opt-2.7b', trust_remote_code=True)"
70
 
71
+ CMD ["uvicorn", "download_api:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]