Fred808 commited on
Commit
3e09e49
·
verified ·
1 Parent(s): 5dc1fad

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +63 -16
Dockerfile CHANGED
@@ -1,26 +1,73 @@
1
- FROM python:3.11-slim
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
- # Set working directory
4
  WORKDIR /app
5
 
6
- # Copy all project files
7
- COPY . .
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
- # Ensure non-root permissions
10
- RUN chmod -R 777 /app
 
 
 
11
 
12
- # Create user with UID 1000 and switch to it
13
- RUN useradd -m -u 1000 user
14
  USER user
15
 
16
- # Add user's pip scripts path to PATH
17
- ENV PATH="/home/user/.local/bin:$PATH"
 
 
 
 
18
 
19
- # Install Python dependencies
20
- RUN pip install --no-cache-dir --no-warn-script-location -r requirements.txt
21
 
22
- # Expose port used by FastAPI
23
- EXPOSE 7860
24
 
25
- # Start FastAPI app
26
- CMD ["uvicorn", "app: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
+ ffmpeg \
12
+ # git for transformers dependencies
13
+ git \
14
+ && rm -rf /var/lib/apt/lists/*
15
 
 
16
  WORKDIR /app
17
 
18
+ # Upgrade pip and install core dependencies first
19
+ RUN pip install --no-cache-dir --upgrade pip setuptools wheel packaging
20
+
21
+ # Install optimized CPU-only PyTorch stack
22
+ RUN pip install --no-cache-dir \
23
+ "numpy<2" \
24
+ torch==2.1.2+cpu \
25
+ torchvision==0.16.2+cpu \
26
+ torchaudio==2.1.2+cpu \
27
+ --index-url https://download.pytorch.org/whl/cpu
28
+
29
+ # Copy requirements and install with special handling
30
+ COPY requirements.txt .
31
+ RUN pip install --no-cache-dir \
32
+ -r requirements.txt \
33
+ --find-links https://download.pytorch.org/whl/cpu \
34
+ --extra-index-url https://pypi.org/simple
35
+
36
+ # # Install transformers with specific version that works with BLIP-2
37
+ # RUN pip install --no-cache-dir \
38
+ # accelerate==0.27.2 \
39
+ # transformers==4.36.2 \
40
+ # timm==0.9.12 \
41
+ # einops==0.7.0 \
42
+ # bitsandbytes==0.42.0 # Helps with memory optimization
43
+
44
+ # For BLIP-2 specifically, we need these
45
+ RUN pip install --no-cache-dir \
46
+ protobuf==3.20.3 \
47
+ sentencepiece==0.2.0
48
+
49
+ # Copy application code with proper permissions
50
+ COPY --chown=1000:1000 . .
51
 
52
+ # Create non-root user and set permissions
53
+ RUN useradd -m -u 1000 user && \
54
+ chown -R user:user /app && \
55
+ mkdir -p /app/downloads /app/extracted /app/extracted_frames /app/analysis_results && \
56
+ chown -R user:user /app/*
57
 
 
 
58
  USER user
59
 
60
+ # Environment variables for better performance and less logging
61
+ ENV HF_HUB_DISABLE_PROGRESS=1
62
+ ENV TF_CPP_MIN_LOG_LEVEL=3
63
+ ENV PYTORCH_NO_CUDA_MEMORY_CACHING=1
64
+ ENV TOKENIZERS_PARALLELISM=false
65
+ ENV PYTHONUNBUFFERED=1
66
 
67
+ # Set this if you're only using CPU
68
+ ENV CUDA_VISIBLE_DEVICES=""
69
 
70
+ # Pre-download the BLIP-2 model during build (optional)
71
+ # RUN python -c "from transformers import AutoModel; AutoModel.from_pretrained('Salesforce/blip2-opt-2.7b', trust_remote_code=True)"
72
 
73
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]