MonkeyDBoa/AvengersDetector
2
1import os2 3import face_recognition4import sklearn5from sklearn import svm6 7from sklearn.model_selection import train_test_split8from sklearn.metrics import accuracy_score9import pickle10import numpy as np11 12import gradio as gr13# Importing Image module from PIL package 14from PIL import Image 15import PIL 16import pandas as pd17 18 19def greet(name):20 test_image_path="geeks.jpg"21 22 df=pd.read_csv("encodings.csv")23 my_custom_list=df.values.tolist()24 25 df2=pd.read_csv("names.csv")26 my_custom_list2=df2.values.tolist()27 28 encodings=my_custom_list29 names=my_custom_list230 # creating a image object (main image) 31 im1 = Image.fromarray(name)32 # save a image using extension33 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=encodings37 known_face_names=names38 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 face45 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 ans="Recognized Avengers either from robert_downey_jr, chris_hemsworth, chris_evans, mark_ruffalo or scarlett_johansson is or are:-"51 if face_names==[]:return(ans+"No one is present in the image")52 53 #for l in face_names:54 #for x in l:55 #ans=ans+","+x.upper()56 return(ans+str(face_names))57 58 59 60 61 62 63 64iface = 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")65iface.launch()66 