Factor Studios commited on
Commit
a01ae0c
·
verified ·
1 Parent(s): 559dedc

Create Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +67 -0
Dockerfile ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
23
+ # Copy requirements and install with special handling
24
+ COPY requirements.txt .
25
+ RUN pip install --no-cache-dir \
26
+ -r requirements.txt \
27
+ --find-links https://download.pytorch.org/whl/cpu \
28
+ --extra-index-url https://pypi.org/simple
29
+
30
+ # # Install transformers with specific version that works with BLIP-2
31
+ # RUN pip install --no-cache-dir \
32
+ # accelerate==0.27.2 \
33
+ # transformers==4.36.2 \
34
+ # timm==0.9.12 \
35
+ # einops==0.7.0 \
36
+ # bitsandbytes==0.42.0 # Helps with memory optimization
37
+
38
+ # For BLIP-2 specifically, we need these
39
+ RUN pip install --no-cache-dir \
40
+ protobuf==3.20.3 \
41
+ sentencepiece==0.2.0
42
+
43
+ # Copy application code with proper permissions
44
+ COPY --chown=1000:1000 . .
45
+
46
+ # Create non-root user and set permissions
47
+ RUN useradd -m -u 1000 user && \
48
+ chown -R user:user /app && \
49
+ mkdir -p /app/downloads /app/extracted /app/extracted_frames /app/analysis_results && \
50
+ chown -R user:user /app/*
51
+
52
+ USER user
53
+
54
+ # Environment variables for better performance and less logging
55
+ ENV HF_HUB_DISABLE_PROGRESS=1
56
+ ENV TF_CPP_MIN_LOG_LEVEL=3
57
+ ENV PYTORCH_NO_CUDA_MEMORY_CACHING=1
58
+ ENV TOKENIZERS_PARALLELISM=false
59
+ ENV PYTHONUNBUFFERED=1
60
+
61
+ # Set this if you're only using CPU
62
+ ENV CUDA_VISIBLE_DEVICES=""
63
+
64
+ # Pre-download the BLIP-2 model during build (optional)
65
+ # RUN python -c "from transformers import AutoModel; AutoModel.from_pretrained('Salesforce/blip2-opt-2.7b', trust_remote_code=True)"
66
+
67
+ CMD ["uvicorn", "app:test_ai_integration.py", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]