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

trying out a fix

Browse files
Files changed (2) hide show
  1. Dockerfile +8 -15
  2. app.py +5 -3
Dockerfile CHANGED
@@ -2,39 +2,32 @@ FROM nvcr.io/nvidia/tensorflow:20.12-tf1-py3
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"]
 
2
 
3
  USER root
4
 
5
+ # Fix GPG Keys
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
  # Set up user
11
  RUN useradd -m -u 1000 user
12
  RUN mkdir -p /home/user/app && chown -R user:user /home/user/app
13
 
14
+ # Force the environment to use the NVIDIA Python 3.7 site-packages
15
  ENV HOME=/home/user \
16
  PATH=/home/user/.local/bin:/usr/local/bin:/usr/bin:/sbin:/bin \
17
+ PYTHONPATH=/usr/local/lib/python3.7/dist-packages \
18
  HF_HOME=/home/user/app/.cache
19
 
20
  WORKDIR /home/user/app
21
 
22
+ # Use the absolute path to the binary provided by NVIDIA
23
+ RUN /usr/bin/python3 -m pip install --no-cache-dir --upgrade "pip<23.0" "setuptools<60"
24
 
 
25
  COPY requirements.txt .
26
+ RUN /usr/bin/python3 -m pip install --no-cache-dir -r requirements.txt
27
 
28
  COPY --chown=user:user . .
29
 
30
  USER user
31
 
32
+ # Use the absolute path for the CMD to ensure no version drift
33
+ CMD ["/usr/bin/python3", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py CHANGED
@@ -6,10 +6,12 @@ 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
 
6
  import sys
7
 
8
  try:
9
+ import tensorflow.compat.v1 as tf
10
+ tf.disable_v2_behavior() # Force TF1 behavior
11
  from tensorflow import keras
12
+ except ImportError:
13
+ import keras
14
+
15
  import keras.engine as KE
16
  sys.modules['keras.engine'] = keras.engine
17
  sys.modules['keras.layers'] = keras.layers