File size: 799 Bytes
a433c93
be8bae6
 
 
 
d8d139a
 
a433c93
 
be8bae6
 
 
 
 
 
 
 
 
 
 
 
 
 
d8d139a
265fbb8
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
26
27
import os
import face_recognition
import cv2
import joblib
import gradio as gr


encodings = joblib.load(os.path.join('.', 'saved_encodings'))
names = joblib.load(os.path.join('.', '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)