Spaces:
Runtime error
Runtime error
File size: 2,293 Bytes
ea4718c 535badf eb9ad04 ea4718c eb9ad04 356decd 29a3b95 356decd eb9ad04 d6938f5 29a3b95 91ccdf2 356decd a398c05 356decd d6938f5 91ccdf2 41f70ec c17f7e6 91ccdf2 eb9ad04 70ca40e eb9ad04 |
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
import os
import face_recognition
import sklearn
from sklearn import svm
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
import pickle
import numpy as np
import gradio as gr
# Importing Image module from PIL package
from PIL import Image
import PIL
import pandas as pd
def greet(name):
test_image_path="geeks.jpg"
df=pd.read_csv("encodings.csv")
my_custom_list=df.values.tolist()
df2=pd.read_csv("names.csv")
my_custom_list2=df2.values.tolist()
encodings=my_custom_list
names=my_custom_list2
# creating a image object (main image)
im1 = Image.fromarray(name)
# save a image using extension
im1 = im1.save(test_image_path)
test_image = face_recognition.load_image_file(test_image_path)
#test_image_path="/content/cropped_images/chris_evans/chris_evans1.png"
known_face_encodings=encodings
known_face_names=names
face_names=[]
test_image = face_recognition.load_image_file(test_image_path)
test_face_encodings = face_recognition.face_encodings(test_image)
for face_encoding in test_face_encodings:
matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
name = "Unknown"
# Or instead, use the known face with the smallest distance to the new face
face_distances = face_recognition.face_distance(known_face_encodings, face_encoding)
best_match_index = np.argmin(face_distances)
if matches[best_match_index]:name = known_face_names[best_match_index]
face_names.append(name)
#print("All faces found in an image for test_image are:-")
ans="Recognized Avengers either from robert_downey_jr, chris_hemsworth, chris_evans, mark_ruffalo or scarlett_johansson is or are:-"
if face_names==[]:return(ans+"No one is present in the image")
#for l in face_names:
#for x in l:
#ans=ans+","+x.upper()
return(ans+str(face_names))
iface = gr.Interface(fn=greet, inputs=gr.inputs.Image(),title="Detect the famous avengers filmstars", description="Choose any one or multiple avengers casts from images of robert_downey_jr, chris_hemsworth, chris_evans, mark_ruffalo or scarlett_johansson ", outputs="text", theme="grass")
iface.launch()
|