Spaces:
Runtime error
Runtime error
| 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() | |