File size: 768 Bytes
be8bae6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import face_recognition
import cv2
import joblib
import gradio as gr

encodings = joblib.load('/content/saved_encodings')
names = joblib.load('/content/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)