OMCHOKSI108 commited on
Commit
20a6573
·
1 Parent(s): 16426ad

Deploying Gradio face recognition app

Browse files
Files changed (3) hide show
  1. app.py +39 -0
  2. face_embeddings.pkl +3 -0
  3. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import cv2
3
+ import numpy as np
4
+ import pickle
5
+ import face_recognition
6
+
7
+ # Load trained model
8
+ def load_trained_model():
9
+ with open("face_embeddings.pkl", "rb") as f:
10
+ data = pickle.load(f)
11
+ return data["encodings"], data["names"]
12
+
13
+ def recognize_face(frame):
14
+ encodings, names = load_trained_model()
15
+ rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
16
+ faces = face_recognition.face_locations(rgb_frame)
17
+ face_encodings = face_recognition.face_encodings(rgb_frame, faces)
18
+
19
+ for face_encoding, face_location in zip(face_encodings, faces):
20
+ distances = face_recognition.face_distance(encodings, face_encoding)
21
+ min_distance = min(distances)
22
+ if min_distance < 0.6:
23
+ match_index = distances.argmin()
24
+ name = names[match_index]
25
+ else:
26
+ name = "Unknown"
27
+
28
+ top, right, bottom, left = face_location
29
+ cv2.rectangle(frame, (left, top), (right, bottom), (0, 255, 0), 2)
30
+ cv2.putText(frame, name, (left, top - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2)
31
+
32
+ return frame
33
+
34
+ # Gradio Interface
35
+ def process_image(image):
36
+ return recognize_face(image)
37
+
38
+ iface = gr.Interface(fn=process_image, inputs="image", outputs="image", title="Face Identification System")
39
+ iface.launch()
face_embeddings.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f9cef7ea99f8dd494ea4b1b18ece5010aaf6c77ac65f88cec161bd8534908809
3
+ size 18243204
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ opencv-python
3
+ numpy
4
+ face-recognition
5
+ pickle5