hoda.fakhar commited on
Commit
5e0e5c7
·
1 Parent(s): 368c8bf

fix: use tensorflow/tensorflow:2.15.0 base image to avoid 300MB pip download

Browse files
Files changed (2) hide show
  1. Dockerfile +11 -28
  2. requirements.txt +0 -1
Dockerfile CHANGED
@@ -1,56 +1,39 @@
1
- # VISION.AI - Hugging Face Spaces (Optimized)
2
- FROM python:3.10-slim
 
3
 
4
- # Set environment variables for non-root user
5
  ENV DEEPFACE_HOME=/home/user
6
- ENV MPLCONFIGDIR=/home/user/.matplotlib
7
- ENV HF_HOME=/home/user/.cache/huggingface
8
  ENV PORT=7860
9
  ENV PYTHONUNBUFFERED=1
10
 
11
- # Install system dependencies for OpenCV and DeepFace
12
  RUN apt-get update && apt-get install -y \
13
  libgl1 \
14
  libglib2.0-0 \
15
  libsm6 \
16
  libxext6 \
17
  libxrender-dev \
18
- git \
19
  && rm -rf /var/lib/apt/lists/*
20
 
21
- # Setup non-root user (Standard for Hugging Face Spaces)
22
  RUN useradd -m -u 1000 user
23
  USER user
24
  WORKDIR /home/user/app
25
-
26
- # Set PATH for the new user
27
  ENV PATH="/home/user/.local/bin:${PATH}"
28
 
29
- # Prepare directories with correct permissions (Hugging Face /home/user is writable)
30
  RUN mkdir -p /home/user/.deepface/weights \
31
  && mkdir -p /home/user/app/static/uploads
32
 
33
- # Install core dependencies first (TensorFlow is the largest)
34
  COPY --chown=user:user requirements.txt .
35
- RUN pip install --no-cache-dir --upgrade pip
36
- RUN echo ">>> Installing tensorflow-cpu (large download, may take 5-10 min)..." && \
37
- pip install --no-cache-dir tensorflow-cpu==2.15.1 && \
38
- echo ">>> tensorflow-cpu done."
39
- RUN echo ">>> Installing remaining dependencies..." && \
40
- pip install --no-cache-dir -r requirements.txt && \
41
- echo ">>> All dependencies done."
42
-
43
- # Pre-download models during BUILD phase (Ensures runtime stability)
44
  COPY --chown=user:user scripts/build_models.py scripts/build_models.py
45
  RUN python scripts/build_models.py
46
 
47
- # Copy the rest of the application
48
  COPY --chown=user:user . .
49
 
50
- # Ensure the upload folder is definitely writable by the app
51
- RUN chmod 777 /home/user/app/static/uploads
52
-
53
  EXPOSE 7860
54
-
55
- # CMD to start the Gunicorn server
56
- CMD ["gunicorn", "-w", "1", "-b", "0.0.0.0:7860", "--timeout", "300", "run:app"]
 
1
+ # VISION.AI - Hugging Face Spaces
2
+ # Use tensorflow base image - tensorflow pre-installed, no 300MB download
3
+ FROM tensorflow/tensorflow:2.15.0
4
 
 
5
  ENV DEEPFACE_HOME=/home/user
 
 
6
  ENV PORT=7860
7
  ENV PYTHONUNBUFFERED=1
8
 
9
+ # System dependencies for OpenCV
10
  RUN apt-get update && apt-get install -y \
11
  libgl1 \
12
  libglib2.0-0 \
13
  libsm6 \
14
  libxext6 \
15
  libxrender-dev \
 
16
  && rm -rf /var/lib/apt/lists/*
17
 
18
+ # Setup non-root user
19
  RUN useradd -m -u 1000 user
20
  USER user
21
  WORKDIR /home/user/app
 
 
22
  ENV PATH="/home/user/.local/bin:${PATH}"
23
 
 
24
  RUN mkdir -p /home/user/.deepface/weights \
25
  && mkdir -p /home/user/app/static/uploads
26
 
27
+ # Install remaining dependencies (no tensorflow here - already in base image)
28
  COPY --chown=user:user requirements.txt .
29
+ RUN pip install --no-cache-dir -r requirements.txt
30
+
31
+ # Download model weights from HF Hub
 
 
 
 
 
 
32
  COPY --chown=user:user scripts/build_models.py scripts/build_models.py
33
  RUN python scripts/build_models.py
34
 
35
+ # Copy application
36
  COPY --chown=user:user . .
37
 
 
 
 
38
  EXPOSE 7860
39
+ CMD ["gunicorn", "-w", "1", "-b", "0.0.0.0:7860", "--timeout", "300", "--access-logfile", "-", "--error-logfile", "-", "run:app"]
 
 
requirements.txt CHANGED
@@ -2,7 +2,6 @@ flask>=3.0.0
2
  flask-cors>=4.0.0
3
  opencv-python-headless>=4.8.0
4
  deepface>=0.0.86
5
- tensorflow-cpu==2.15.1
6
  numpy>=1.24.0,<2.0
7
  pillow>=10.0.0
8
  python-dotenv>=1.0.0
 
2
  flask-cors>=4.0.0
3
  opencv-python-headless>=4.8.0
4
  deepface>=0.0.86
 
5
  numpy>=1.24.0,<2.0
6
  pillow>=10.0.0
7
  python-dotenv>=1.0.0