File size: 2,280 Bytes
bd35930
 
 
 
 
 
d590959
 
d3eef5b
bd35930
58c9975
bd35930
 
 
 
 
 
5f521ca
 
 
 
 
 
 
 
ad3b22f
 
bd35930
 
 
 
 
01f73ee
 
bd35930
01f73ee
 
 
 
 
 
 
 
 
bb785f5
01f73ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1550607
 
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
62
63
64
import requests
import pyrebase
import urllib
from retinaface import RetinaFace
from deepface import DeepFace
from fastapi import FastAPI
from PIL import Image
from io import BytesIO
import tensorflow
app = FastAPI()

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

@app.get("/verify/")
def verify_image(url1):
    firebaseConfig ={
      "apiKey": "AIzaSyClnRJAnrJgAgkYjuYnlvu-CJ6Cxyklebo",
      "authDomain": "socioverse-2025.firebaseapp.com",
      "projectId": "socioverse-2025",
      "storageBucket": "socioverse-2025.appspot.com",
      "messagingSenderId": "689574504641",
      "appId": "1:689574504641:web:a22f6a2fa343e4221acc40",
      "databaseURL": "https://console.firebase.google.com/project/socioverse-2025/storage/socioverse-2025.appspot.com/files",
      "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
    username = "Not Found"
    
    for file in files:
        if file.name.endswith((".jpg", ".jpeg")):
            url = storage.child(file.name).get_url(None)
            try:
                # Retrieve the image from URL
                response = requests.get(url)
                response.raise_for_status()  # Raise an exception for HTTP errors
                # Open the image using PIL
                img = Image.open(BytesIO(response.content))
                # Verify the image
                result = DeepFace.verify(url1, url, model_name="Facenet", distance_metric='cosine')
                if result['verified']:
                    flag = True
                    # Extract username from the file name
                    start_index = file.name.rfind('/')
                    end_index = file.name.rfind('$')
                    if start_index != -1 and end_index != -1:
                        username = file.name[start_index + 1:end_index]
                    break  # No need to continue loop if verified
            except Exception as e:
                print(f"Error processing image: {e}")
    
    if flag:
        return {"username": username}
    else:
        print("Not Verified")
        return {"username": "Not Found"}