Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -35,12 +35,8 @@ def calculate_similarity(image1, image2):
|
|
35 |
# Analyze the two cropped images for facial similarity
|
36 |
result = DeepFace.verify(face1_rgb, face2_rgb, model_name='VGG-Face', enforce_detection=False)
|
37 |
similarity_percentage = (1 - result['distance']) * 100 # Convert distance to similarity percentage
|
38 |
-
|
39 |
-
|
40 |
-
_, face1_encoded = cv2.imencode('.png', face1)
|
41 |
-
_, face2_encoded = cv2.imencode('.png', face2)
|
42 |
-
|
43 |
-
return similarity_percentage, face1_encoded.tobytes(), face2_encoded.tobytes()
|
44 |
except Exception as e:
|
45 |
return str(e), None, None
|
46 |
|
@@ -53,8 +49,8 @@ iface = gr.Interface(
|
|
53 |
],
|
54 |
outputs=[
|
55 |
gr.outputs.Textbox(label="Similarity Percentage"),
|
56 |
-
gr.outputs.Image(label="Cropped Face 1"),
|
57 |
-
gr.outputs.Image(label="Cropped Face 2"),
|
58 |
],
|
59 |
title="Face Similarity Checker",
|
60 |
description="Upload two images of faces to check their similarity. The faces will be detected and cropped automatically."
|
|
|
35 |
# Analyze the two cropped images for facial similarity
|
36 |
result = DeepFace.verify(face1_rgb, face2_rgb, model_name='VGG-Face', enforce_detection=False)
|
37 |
similarity_percentage = (1 - result['distance']) * 100 # Convert distance to similarity percentage
|
38 |
+
|
39 |
+
return similarity_percentage, face1_rgb, face2_rgb
|
|
|
|
|
|
|
|
|
40 |
except Exception as e:
|
41 |
return str(e), None, None
|
42 |
|
|
|
49 |
],
|
50 |
outputs=[
|
51 |
gr.outputs.Textbox(label="Similarity Percentage"),
|
52 |
+
gr.outputs.Image(label="Cropped Face 1", type="numpy"),
|
53 |
+
gr.outputs.Image(label="Cropped Face 2", type="numpy"),
|
54 |
],
|
55 |
title="Face Similarity Checker",
|
56 |
description="Upload two images of faces to check their similarity. The faces will be detected and cropped automatically."
|