Rockk08 commited on
Commit
18d5c88
·
verified ·
1 Parent(s): 2e34b35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -22
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
- # url1 = "https://api.time.com/wp-content/uploads/2023/04/shah-rukh-khan-time100-2023-1.jpg"
 
32
  for file in files:
33
- if (file.name.endswith(".jpg") or file.name.endswith(".jpeg")) :
34
- # print(file.name)
35
- url = storage.child(f"{file.name}").get_url(None)
36
- # print(url)
37
- with requests.get(url) as response:
38
- result = DeepFace.verify(f"{url1}",url, model_name="Facenet", distance_metric='cosine')
39
- if result['verified']:
40
- flag = True
41
- start_index = file.name.rfind('/')
42
- end_index = file.name.rfind('$')
43
- if start_index != -1 and end_index != -1:
44
- name = file.name[start_index + 1:end_index]
45
- return {"username": name}
46
-
47
-
48
- if flag == False:
49
- print("Not Verified")
50
- return {"username": "Not Found"}
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"}