Rockk08 commited on
Commit
1550607
·
verified ·
1 Parent(s): 113dd90

Update app.py

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