Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -28,26 +28,32 @@ def verify_image(url1):
|
|
28 |
path = "Faces/"
|
29 |
files = storage.bucket.list_blobs(prefix=path)
|
30 |
flag = False
|
31 |
-
|
|
|
32 |
for file in files:
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
28 |
path = "Faces/"
|
29 |
files = storage.bucket.list_blobs(prefix=path)
|
30 |
flag = False
|
31 |
+
username = "Not Found"
|
32 |
+
|
33 |
for file in files:
|
34 |
+
if file.name.endswith((".jpg", ".jpeg")):
|
35 |
+
url = storage.child(file.name).get_url(None)
|
36 |
+
try:
|
37 |
+
# Retrieve the image from URL
|
38 |
+
response = requests.get(url)
|
39 |
+
response.raise_for_status() # Raise an exception for HTTP errors
|
40 |
+
# Open the image using PIL
|
41 |
+
img = Image.open(BytesIO(response.content))
|
42 |
+
# Verify the image
|
43 |
+
result = DeepFace.verify(url1, url, model_name="Facenet", distance_metric='cosine')
|
44 |
+
if result['verified']:
|
45 |
+
flag = True
|
46 |
+
# Extract username from the file name
|
47 |
+
start_index = file.name.rfind('/')
|
48 |
+
end_index = file.name.rfind('$')
|
49 |
+
if start_index != -1 and end_index != -1:
|
50 |
+
username = file.name[start_index + 1:end_index]
|
51 |
+
break # No need to continue loop if verified
|
52 |
+
except Exception as e:
|
53 |
+
print(f"Error processing image: {e}")
|
54 |
+
|
55 |
+
if flag:
|
56 |
+
return {"username": username}
|
57 |
+
else:
|
58 |
+
print("Not Verified")
|
59 |
+
return {"username": "Not Found"}
|