Spaces:
Sleeping
Sleeping
saniaE commited on
Commit ·
11c0d05
1
Parent(s): 1d13a4b
trying out a fix
Browse files- Dockerfile +9 -12
- app.py +16 -9
Dockerfile
CHANGED
|
@@ -2,25 +2,23 @@ FROM nvcr.io/nvidia/tensorflow:20.12-tf1-py3
|
|
| 2 |
|
| 3 |
USER root
|
| 4 |
|
| 5 |
-
# Fix GPG Keys and
|
| 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 |
-
#
|
| 13 |
RUN useradd -m -u 1000 user
|
| 14 |
RUN mkdir -p /home/user/app && chown -R user:user /home/user/app
|
| 15 |
|
| 16 |
-
# Force the
|
| 17 |
-
|
| 18 |
-
ENV
|
| 19 |
-
|
| 20 |
|
| 21 |
WORKDIR /home/user/app
|
| 22 |
|
| 23 |
-
#
|
| 24 |
COPY requirements.txt .
|
| 25 |
RUN /usr/bin/python3 -m pip install --no-cache-dir --upgrade "pip<23.0"
|
| 26 |
RUN /usr/bin/python3 -m pip install --no-cache-dir -r requirements.txt
|
|
@@ -29,6 +27,5 @@ COPY --chown=user:user . .
|
|
| 29 |
|
| 30 |
USER user
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
# This ensures it doesn't accidentally jump into Python 3.8
|
| 34 |
CMD ["/usr/bin/python3", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
| 2 |
|
| 3 |
USER root
|
| 4 |
|
| 5 |
+
# Fix GPG Keys and system dependencies
|
| 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 |
+
# Create user and app directory
|
| 11 |
RUN useradd -m -u 1000 user
|
| 12 |
RUN mkdir -p /home/user/app && chown -R user:user /home/user/app
|
| 13 |
|
| 14 |
+
# CRITICAL: Force the path to prioritize NVIDIA's Python 3.7 site-packages over system 3.8
|
| 15 |
+
ENV PYTHONPATH=/usr/local/lib/python3.6/dist-packages:/usr/local/lib/python3.7/dist-packages:/home/user/app
|
| 16 |
+
ENV HF_HOME=/home/user/app/.cache
|
| 17 |
+
ENV PATH=/home/user/.local/bin:$PATH
|
| 18 |
|
| 19 |
WORKDIR /home/user/app
|
| 20 |
|
| 21 |
+
# We use /usr/bin/python3 because in this image it is linked to the TF1.15 build
|
| 22 |
COPY requirements.txt .
|
| 23 |
RUN /usr/bin/python3 -m pip install --no-cache-dir --upgrade "pip<23.0"
|
| 24 |
RUN /usr/bin/python3 -m pip install --no-cache-dir -r requirements.txt
|
|
|
|
| 27 |
|
| 28 |
USER user
|
| 29 |
|
| 30 |
+
# Final Command: Absolute path to ensure we don't hit Python 3.8
|
|
|
|
| 31 |
CMD ["/usr/bin/python3", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
|
@@ -5,17 +5,24 @@ import numpy as np
|
|
| 5 |
import tensorflow as tf
|
| 6 |
import sys
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
try:
|
| 9 |
-
|
| 10 |
-
# For TF 1.15 compatibility
|
| 11 |
-
from tensorflow import keras
|
| 12 |
-
import tensorflow.python.keras.engine as KE
|
| 13 |
-
|
| 14 |
-
# Inject into sys.modules so 'import keras' works for mrcnn
|
| 15 |
-
sys.modules['keras'] = keras
|
| 16 |
-
sys.modules['keras.engine'] = KE
|
| 17 |
except ImportError:
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
from fastapi import FastAPI, File, UploadFile
|
| 21 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 5 |
import tensorflow as tf
|
| 6 |
import sys
|
| 7 |
|
| 8 |
+
import tensorflow as tf
|
| 9 |
+
# Force TF 1.15 behavior if not already set
|
| 10 |
+
if hasattr(tf, 'compat') and hasattr(tf.compat, 'v1'):
|
| 11 |
+
tf.compat.v1.disable_v2_behavior()
|
| 12 |
+
|
| 13 |
try:
|
| 14 |
+
from tensorflow.python.keras import engine as KE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
except ImportError:
|
| 16 |
+
# Some TF 1.15 versions hide it here
|
| 17 |
+
import tensorflow.keras.backend as K
|
| 18 |
+
from tensorflow.python.keras.api._v1.keras import engine as KE
|
| 19 |
+
|
| 20 |
+
# Inject these into sys.modules so 'import keras.engine' works
|
| 21 |
+
import tensorflow.python.keras as keras
|
| 22 |
+
sys.modules['keras'] = keras
|
| 23 |
+
sys.modules['keras.engine'] = KE
|
| 24 |
+
sys.modules['keras.layers'] = keras.layers
|
| 25 |
+
sys.modules['keras.models'] = keras.models
|
| 26 |
|
| 27 |
from fastapi import FastAPI, File, UploadFile
|
| 28 |
from fastapi.middleware.cors import CORSMiddleware
|