MonkeyDBoa commited on
Commit
91ccdf2
·
1 Parent(s): 29a3b95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -25,12 +25,36 @@ def greet(name):
25
  df2=pd.read_csv("names.csv")
26
  my_custom_list2=df2.values.tolist()
27
 
 
 
28
  # creating a image object (main image)
29
  im1 = Image.fromarray(name)
30
  # save a image using extension
31
  im1 = im1.save(test_image_path)
32
  test_image = face_recognition.load_image_file(test_image_path)
33
- return len(df)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  iface = gr.Interface(fn=greet, inputs=gr.inputs.Image(), outputs="text")
36
  iface.launch()
 
25
  df2=pd.read_csv("names.csv")
26
  my_custom_list2=df2.values.tolist()
27
 
28
+ encodings=my_custom_list
29
+ names=my_custom_list2
30
  # creating a image object (main image)
31
  im1 = Image.fromarray(name)
32
  # save a image using extension
33
  im1 = im1.save(test_image_path)
34
  test_image = face_recognition.load_image_file(test_image_path)
35
+ #test_image_path="/content/cropped_images/chris_evans/chris_evans1.png"
36
+ known_face_encodings=encodings
37
+ known_face_names=names
38
+ face_names=[]
39
+ test_image = face_recognition.load_image_file(test_image_path)
40
+ test_face_encodings = face_recognition.face_encodings(test_image)
41
+ for face_encoding in test_face_encodings:
42
+ matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
43
+ name = "Unknown"
44
+ # Or instead, use the known face with the smallest distance to the new face
45
+ face_distances = face_recognition.face_distance(known_face_encodings, face_encoding)
46
+ best_match_index = np.argmin(face_distances)
47
+ if matches[best_match_index]:name = known_face_names[best_match_index]
48
+ face_names.append(name)
49
+ #print("All faces found in an image for test_image are:-")
50
+ if face_names==[]:return("unknown")
51
+ else:return(*face_names)
52
+
53
+
54
+
55
+
56
+
57
+
58
 
59
  iface = gr.Interface(fn=greet, inputs=gr.inputs.Image(), outputs="text")
60
  iface.launch()