File size: 2,150 Bytes
bd35930
 
61abda0
bd35930
 
 
 
58c9975
bd35930
58c9975
bd35930
 
 
 
 
 
ad3b22f
0efe0ec
adb762e
 
 
 
 
 
ad3b22f
 
bd35930
 
 
 
 
 
 
3215a1b
bd35930
 
 
 
 
 
 
 
 
 
 
ee79f62
 
 
 
 
 
 
1d3e1a5
bd35930
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import requests
import pyrebase
import os
import urllib
from retinaface import RetinaFace
from deepface import DeepFace
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
    return {"Hello": "World"}

@app.get("/verify/")
def verify_image(url1):
    firebaseConfig = {
      "apiKey": f'{os.getenv("API_KEY")}',
      "authDomain": f'{os.getenv("AUTH_DOMAIN")}',
      "projectId": f'{os.getenv("PROJECT_ID")}',
      "storageBucket": f'{os.getenv("STORAGE_BKT")}',
      "messagingSenderId": f'{os.getenv("S_ID")}',
      "appId": f'{os.getenv("APP_ID")}',
      "databaseURL": f'{os.getenv("DBMS_URL")}',
      "serviceAccount":"Firebase_Service_Account_Keys.json"
    };
    firebase = pyrebase.initialize_app(firebaseConfig)
    storage = firebase.storage()
    path = "Faces/"
    files = storage.bucket.list_blobs(prefix=path)
    flag = False
    # url1 = "https://api.time.com/wp-content/uploads/2023/04/shah-rukh-khan-time100-2023-1.jpg"
    for file in files:
      if (file.name.endswith(".jpg") or file.name.endswith(".jpeg")) :
        # print(file.name)
        url = storage.child(f"{file.name}").get_url(None)
        # print(url)
        with requests.get(url) as response:
          result = DeepFace.verify(f"{url1}",url, model_name="Facenet", distance_metric='cosine')
          if result['verified']:
            flag = True
            start_index = file.name.rfind('/')
            end_index = file.name.rfind('$')
            if start_index != -1 and end_index != -1:
              name = file.name[start_index + 1:end_index]
              # path = f"{name}/"
              # files_username = storage.bucket.list_blobs(prefix=path)
              # for file_username in files_username:
              #   if (file_username.name.endswith(".json")):
              #     url_username = storage.child(f"{file_username.name}").get_url(None)
              #     with requests.get(url_username) as response_username:
              #       metadata = response_username.json()
              return {"username": name}

    if flag == False:
      print("Not Verified")
      return {"username": "Not Found"}