FaceRecognition / app.py
MHRDYN7's picture
Update app.py
cc87cf3
raw
history blame
784 Bytes
import face_recognition
import cv2
import joblib
import gradio as gr
encodings = joblib.load('/FaceRecognition/saved_encodings')
names = joblib.load('/FaceRecognition/saved_names')
def FaceRec(img):
img_enc = face_recognition.face_encodings(img)[0]
results = face_recognition.compare_faces((encodings), img_enc)
for i in range(len(results)):
if results[i]:
name = names[i]
(top, right, bottom, left) = face_recognition.face_locations(img)[0]
cv2.rectangle(img, (left, top), (right, bottom), (0, 0, 255), 2)
cv2.putText(img, name, (left+2, bottom+20), cv2.FONT_HERSHEY_PLAIN, 1, (255, 255, 255), 1)
return img
interface = gr.Interface(FaceRec, gr.inputs.Image(shape=(200,200)), "image")
interface.launch(debug = True, inline = False)