Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -35,20 +35,25 @@ def register_user(image, user_id):
|
|
35 |
|
36 |
# Recognize user
|
37 |
def recognize_user(image):
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
# Gradio interface for registering users
|
54 |
register_interface = gr.Interface(
|
@@ -67,5 +72,5 @@ recognize_interface = gr.Interface(
|
|
67 |
)
|
68 |
|
69 |
if __name__ == "__main__":
|
70 |
-
register_interface.launch(share=True)
|
71 |
recognize_interface.launch(share=True)
|
|
|
35 |
|
36 |
# Recognize user
|
37 |
def recognize_user(image):
|
38 |
+
try:
|
39 |
+
new_embedding = generate_embedding(image)
|
40 |
+
min_distance = float('inf')
|
41 |
+
recognized_user_id = "Unknown"
|
42 |
+
|
43 |
+
for user_id, embedding in user_embeddings.items():
|
44 |
+
distance = cosine(new_embedding, embedding)
|
45 |
+
print(f"Distance for {user_id}: {distance}") # Debug: Print distances
|
46 |
+
if distance < min_distance:
|
47 |
+
min_distance = distance
|
48 |
+
recognized_user_id = user_id
|
49 |
+
|
50 |
+
print(f"Min distance: {min_distance}") # Debug: Print minimum distance
|
51 |
+
if min_distance > RECOGNITION_THRESHOLD:
|
52 |
+
return "User not recognized."
|
53 |
+
else:
|
54 |
+
return f"Recognized User: {recognized_user_id}"
|
55 |
+
except Exception as e:
|
56 |
+
return f"Error during recognition: {str(e)}"
|
57 |
|
58 |
# Gradio interface for registering users
|
59 |
register_interface = gr.Interface(
|
|
|
72 |
)
|
73 |
|
74 |
if __name__ == "__main__":
|
75 |
+
#register_interface.launch(share=True)
|
76 |
recognize_interface.launch(share=True)
|