saniaE commited on
Commit
e4fc75d
·
1 Parent(s): c3d6865

trying out a fix

Browse files
Files changed (2) hide show
  1. Dockerfile +18 -16
  2. app.py +13 -6
Dockerfile CHANGED
@@ -2,37 +2,39 @@ FROM nvcr.io/nvidia/tensorflow:20.12-tf1-py3
2
 
3
  USER root
4
 
5
- # Fix GPG Keys and install only necessary system graphics/glib libs
6
  RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub \
7
- && apt-get update && apt-get install -y \
8
- libgl1-mesa-glx \
9
- libglib2.0-0 \
10
  && rm -rf /var/lib/apt/lists/*
11
 
12
- # Set up user and permissions
 
 
 
 
 
 
13
  RUN useradd -m -u 1000 user
14
  RUN mkdir -p /home/user/app && chown -R user:user /home/user/app
15
 
16
- # NVIDIA's Python 3.7 is typically at /usr/local/bin/python3
17
- # We create a symlink so 'python3.7' command works specifically
18
- RUN ln -s $(which python3) /usr/local/bin/python3.7
19
-
20
- # Force paths
21
  ENV HOME=/home/user \
22
- PATH=/home/user/.local/bin:$PATH \
23
- PYTHONPATH=/usr/local/lib/python3.7/dist-packages \
24
  HF_HOME=/home/user/app/.cache
25
 
26
  WORKDIR /home/user/app
27
 
28
- # Now use the symlink we just created
29
- RUN python3.7 -m pip install --no-cache-dir --upgrade "pip<23.0"
30
 
 
31
  COPY requirements.txt .
32
- RUN python3.7 -m pip install --no-cache-dir -r requirements.txt
33
 
34
  COPY --chown=user:user . .
35
 
36
  USER user
37
 
38
- CMD ["python3.7", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
 
2
 
3
  USER root
4
 
5
+ # Fix GPG Keys and install system libs
6
  RUN apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub \
7
+ && apt-get update && apt-get install -y libgl1-mesa-glx libglib2.0-0 \
 
 
8
  && rm -rf /var/lib/apt/lists/*
9
 
10
+ # FORCE Python 3.7 as the only 'python' and 'python3'
11
+ # This stops the system from accidentally using 3.8
12
+ RUN ln -sf /usr/bin/python3.7 /usr/bin/python3 && \
13
+ ln -sf /usr/bin/python3.7 /usr/bin/python && \
14
+ ln -sf /usr/bin/python3.7 /usr/local/bin/python
15
+
16
+ # Set up user
17
  RUN useradd -m -u 1000 user
18
  RUN mkdir -p /home/user/app && chown -R user:user /home/user/app
19
 
20
+ # Strict Environment Paths
 
 
 
 
21
  ENV HOME=/home/user \
22
+ PATH=/home/user/.local/bin:/usr/local/bin:/usr/bin:/sbin:/bin \
23
+ PYTHONPATH=/usr/local/lib/python3.7/dist-packages:/home/user/app \
24
  HF_HOME=/home/user/app/.cache
25
 
26
  WORKDIR /home/user/app
27
 
28
+ # Upgrade pip for 3.7 specifically
29
+ RUN python -m pip install --no-cache-dir --upgrade "pip<23.0" "setuptools<60"
30
 
31
+ # Install requirements
32
  COPY requirements.txt .
33
+ RUN python -m pip install --no-cache-dir -r requirements.txt
34
 
35
  COPY --chown=user:user . .
36
 
37
  USER user
38
 
39
+ # Using 'python -m uvicorn' ensures we use the version linked above
40
+ CMD ["python", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py CHANGED
@@ -1,14 +1,21 @@
1
- try:
2
- import keras
3
- except ImportError:
4
- from tensorflow import keras
5
- import sys
6
- sys.modules['keras'] = keras
7
 
8
  import os
9
  import io
10
  import numpy as np
11
  import tensorflow as tf
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  from fastapi import FastAPI, File, UploadFile
13
  from fastapi.middleware.cors import CORSMiddleware
14
  from PIL import Image
 
 
 
 
 
 
 
1
 
2
  import os
3
  import io
4
  import numpy as np
5
  import tensorflow as tf
6
+ import sys
7
+
8
+ try:
9
+ import keras
10
+ except ImportError:
11
+ from tensorflow import keras
12
+
13
+ import keras.engine as KE
14
+ sys.modules['keras.engine'] = keras.engine
15
+ sys.modules['keras.layers'] = keras.layers
16
+ sys.modules['keras.models'] = keras.models
17
+ sys.modules['keras.utils'] = keras.utils
18
+
19
  from fastapi import FastAPI, File, UploadFile
20
  from fastapi.middleware.cors import CORSMiddleware
21
  from PIL import Image