eyad222 commited on
Commit
74b7c12
·
verified ·
1 Parent(s): bc5f502

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -10
app.py CHANGED
@@ -12,21 +12,14 @@ label_names = np.load("model/label_names.npy")
12
  with open("model/img_shape.txt", "r") as f:
13
  img_h, img_w = map(int, f.read().strip().split())
14
 
15
- # Distance threshold (tune based on performance)
16
  THRESHOLD = 8000
17
 
18
  def recognize_face_from_frame(frame):
19
- # Convert to grayscale
20
  img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
21
- # Resize to training size
22
  img = cv2.resize(img, (img_w, img_h))
23
- # Flatten and normalize
24
  img_flat = img.flatten()
25
  img_centered = img_flat - mean_face
26
- # Project to eigenface space
27
  projected = np.dot(img_centered, eigenfaces.T)
28
-
29
- # Compare with stored projections
30
  dists = euclidean_distances([projected], projections)[0]
31
  min_dist = np.min(dists)
32
  min_index = np.argmin(dists)
@@ -37,13 +30,12 @@ def recognize_face_from_frame(frame):
37
  else:
38
  return "😕 Unknown face"
39
 
40
- # Web UI
41
  iface = gr.Interface(
42
  fn=recognize_face_from_frame,
43
- inputs=gr.Camera(),
44
  outputs="text",
45
  title="🔍 EigenFace Recognition",
46
- description="Scan your face. If you're in the dataset, the system will recognize you."
47
  )
48
 
49
  iface.launch()
 
12
  with open("model/img_shape.txt", "r") as f:
13
  img_h, img_w = map(int, f.read().strip().split())
14
 
 
15
  THRESHOLD = 8000
16
 
17
  def recognize_face_from_frame(frame):
 
18
  img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
 
19
  img = cv2.resize(img, (img_w, img_h))
 
20
  img_flat = img.flatten()
21
  img_centered = img_flat - mean_face
 
22
  projected = np.dot(img_centered, eigenfaces.T)
 
 
23
  dists = euclidean_distances([projected], projections)[0]
24
  min_dist = np.min(dists)
25
  min_index = np.argmin(dists)
 
30
  else:
31
  return "😕 Unknown face"
32
 
 
33
  iface = gr.Interface(
34
  fn=recognize_face_from_frame,
35
+ inputs=gr.Image(tool="editor", type="numpy"),
36
  outputs="text",
37
  title="🔍 EigenFace Recognition",
38
+ description="Upload a face image or take a picture with your webcam."
39
  )
40
 
41
  iface.launch()