Jainam Jain
Updated
58c9975
raw
history blame
1.97 kB
import requests
import pyrebase
import urllib
from retinaface import RetinaFace
from deepface import DeepFace
from fastapi import FastAPI
import firebase_admin
from firebase_admin import credentials
from decouple import config
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/verify/")
def verify_image(url1):
firebase_config = {
"apiKey": config("FIREBASE_API_KEY"),
"authDomain": config("FIREBASE_AUTH_DOMAIN"),
"projectId": config("FIREBASE_PROJECT_ID"),
"storageBucket": config("FIREBASE_STORAGE_BUCKET"),
"messagingSenderId": config("FIREBASE_MESSAGING_SENDER_ID"),
"appId": config("FIREBASE_APP_ID"),
"databaseURL": config("FIREBASE_DATABASE_URL"),
"serviceAccount": config("FIREBASE_SERVICE_ACCOUNT_JSON")
}
# Initialize the Firebase app with the service account JSON
cred = credentials.Certificate(firebase_config['serviceAccount'])
firebase_admin
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]
return {"username": name}
break
if flag == False:
print("Not Verified")
return {"username": "Not Found"}