vinay0123 commited on
Commit
e0ad483
·
verified ·
1 Parent(s): 960b0ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -12
app.py CHANGED
@@ -286,18 +286,26 @@ def get_users():
286
  return jsonify({"users": [user['username'] for user in users], "count": user_count})
287
 
288
  def load_embeddings_from_db():
289
- # Collection name 'data' is already correctly used here
290
- users = list(mongo.db.data.find())
291
- face_data = []# facenet embeddings
292
- labels = [] # id 1,2,3,..
293
- names = {} #dict of id and roll number
294
- # {"1":vinay,"2":shahank}
295
- for user in users:
296
- face_data.append(user["embeddings"])
297
- labels.append(user['id']) # Keep the ObjectId
298
- names[user['id']] = user['RollNumber'] # Use ObjectId as key
299
-
300
- return (face_data, labels, names) if face_data else ([], [], {})
 
 
 
 
 
 
 
 
301
 
302
  # Load face embeddings from MongoDB initially
303
  face_data, labels, names = load_embeddings_from_db()
 
286
  return jsonify({"users": [user['username'] for user in users], "count": user_count})
287
 
288
  def load_embeddings_from_db():
289
+ if mongo is None:
290
+ print("MongoDB not connected - returning empty embeddings")
291
+ return [], [], {}
292
+
293
+ try:
294
+ users = list(mongo.db.data.find())
295
+ face_data = []# facenet embeddings
296
+ labels = [] # id 1,2,3,..
297
+ names = {} #dict of id and roll number
298
+ # {"1":vinay,"2":shahank}
299
+ for user in users:
300
+ face_data.append(user["embeddings"])
301
+ labels.append(user['id']) # Keep the ObjectId
302
+ names[user['id']] = user['RollNumber'] # Use ObjectId as key
303
+
304
+ print(f"Loaded {len(face_data)} user embeddings from database")
305
+ return (face_data, labels, names) if face_data else ([], [], {})
306
+ except Exception as e:
307
+ print(f"Error loading embeddings from database: {e}")
308
+ return [], [], {}
309
 
310
  # Load face embeddings from MongoDB initially
311
  face_data, labels, names = load_embeddings_from_db()