Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
# Install required packages
|
2 |
-
import os
|
3 |
import subprocess
|
4 |
import sys
|
5 |
|
@@ -7,27 +7,54 @@ import sys
|
|
7 |
# and install packages if needed
|
8 |
if not os.path.exists("/.dockerenv") and not os.path.exists("/kaggle"):
|
9 |
try:
|
|
|
10 |
import gradio
|
11 |
-
import deepface
|
12 |
import cv2
|
13 |
import numpy as np
|
14 |
import matplotlib
|
15 |
import PIL
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
except ImportError:
|
17 |
print("Installing required packages...")
|
18 |
subprocess.check_call([sys.executable, "-m", "pip", "install",
|
19 |
-
"gradio", "
|
|
|
|
|
20 |
|
|
|
21 |
import gradio as gr
|
22 |
import json
|
23 |
import cv2
|
24 |
import numpy as np
|
25 |
-
from deepface import DeepFace
|
26 |
-
import matplotlib.pyplot as plt
|
27 |
from PIL import Image
|
28 |
import tempfile
|
29 |
import pandas as pd
|
30 |
import shutil
|
|
|
|
|
|
|
|
|
31 |
|
32 |
def verify_faces(img1, img2, threshold=0.70, model="VGG-Face"):
|
33 |
# Save uploaded images to temporary files
|
|
|
1 |
# Install required packages
|
2 |
+
import os
|
3 |
import subprocess
|
4 |
import sys
|
5 |
|
|
|
7 |
# and install packages if needed
|
8 |
if not os.path.exists("/.dockerenv") and not os.path.exists("/kaggle"):
|
9 |
try:
|
10 |
+
# Try importing the required packages
|
11 |
import gradio
|
|
|
12 |
import cv2
|
13 |
import numpy as np
|
14 |
import matplotlib
|
15 |
import PIL
|
16 |
+
|
17 |
+
# Special handling for TensorFlow and DeepFace dependencies
|
18 |
+
try:
|
19 |
+
import tensorflow as tf
|
20 |
+
tf_version = tf.__version__
|
21 |
+
print(f"TensorFlow version: {tf_version}")
|
22 |
+
|
23 |
+
# If TensorFlow version is >=2.16, we need to install tf-keras
|
24 |
+
if tf_version >= "2.16.0":
|
25 |
+
print("Installing tf-keras for compatibility with newer TensorFlow...")
|
26 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "tf-keras"])
|
27 |
+
|
28 |
+
# Now try to import deepface
|
29 |
+
import deepface
|
30 |
+
except ImportError as e:
|
31 |
+
print(f"Error importing dependencies: {str(e)}")
|
32 |
+
print("Installing deepface with specific dependencies...")
|
33 |
+
# First downgrade tensorflow to a compatible version if needed
|
34 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "tensorflow<2.16.0"])
|
35 |
+
# Then install deepface
|
36 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "deepface"])
|
37 |
+
|
38 |
except ImportError:
|
39 |
print("Installing required packages...")
|
40 |
subprocess.check_call([sys.executable, "-m", "pip", "install",
|
41 |
+
"gradio", "opencv-python-headless", "numpy", "matplotlib", "pillow"])
|
42 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "tensorflow<2.16.0"]) # Use older version
|
43 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "deepface"])
|
44 |
|
45 |
+
# Now import the required modules
|
46 |
import gradio as gr
|
47 |
import json
|
48 |
import cv2
|
49 |
import numpy as np
|
|
|
|
|
50 |
from PIL import Image
|
51 |
import tempfile
|
52 |
import pandas as pd
|
53 |
import shutil
|
54 |
+
import matplotlib.pyplot as plt
|
55 |
+
|
56 |
+
# Import DeepFace after ensuring dependencies are properly installed
|
57 |
+
from deepface import DeepFace
|
58 |
|
59 |
def verify_faces(img1, img2, threshold=0.70, model="VGG-Face"):
|
60 |
# Save uploaded images to temporary files
|