ImanAmran commited on
Commit
8557945
1 Parent(s): 9a3eba9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -35,20 +35,25 @@ def register_user(image, user_id):
35
 
36
  # Recognize user
37
  def recognize_user(image):
38
- new_embedding = generate_embedding(image)
39
- min_distance = float('inf')
40
- recognized_user_id = "Unknown"
41
-
42
- for user_id, embedding in user_embeddings.items():
43
- distance = cosine(new_embedding, embedding)
44
- if distance < min_distance:
45
- min_distance = distance
46
- recognized_user_id = user_id
47
-
48
- if min_distance > RECOGNITION_THRESHOLD:
49
- return "User not recognized."
50
- else:
51
- return f"Recognized User: {recognized_user_id}"
 
 
 
 
 
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)