Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,18 +71,19 @@ def register_user(image, user_id):
|
|
| 71 |
def recognize_user(image):
|
| 72 |
try:
|
| 73 |
new_embedding = generate_embedding(image)
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
return "User not recognized."
|
| 82 |
-
|
| 83 |
-
# Find the user ID(s) in the closest cluster
|
| 84 |
-
recognized_user_ids = [user_ids[i] for i, label in enumerate(kmeans.labels_) if label == cluster_label]
|
| 85 |
-
return f"Recognized User(s): {', '.join(recognized_user_ids)}"
|
| 86 |
except Exception as e:
|
| 87 |
return f"Error during recognition: {str(e)}"
|
| 88 |
|
|
|
|
| 71 |
def recognize_user(image):
|
| 72 |
try:
|
| 73 |
new_embedding = generate_embedding(image)
|
| 74 |
+
closest_user_id = None
|
| 75 |
+
closest_distance = float('inf')
|
| 76 |
+
|
| 77 |
+
for user_id, embedding in zip(user_ids, user_embeddings):
|
| 78 |
+
distance = cosine(new_embedding, embedding)
|
| 79 |
+
if distance < closest_distance:
|
| 80 |
+
closest_distance = distance
|
| 81 |
+
closest_user_id = user_id
|
| 82 |
+
|
| 83 |
+
if closest_distance <= RECOGNITION_THRESHOLD:
|
| 84 |
+
return f"Recognized User: {closest_user_id}"
|
| 85 |
+
else:
|
| 86 |
return "User not recognized."
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
except Exception as e:
|
| 88 |
return f"Error during recognition: {str(e)}"
|
| 89 |
|