Spaces:
Runtime error
Runtime error
File size: 1,509 Bytes
cde3f1a 30a2827 cde3f1a 30a2827 cde3f1a 30a2827 747767c 30a2827 239a35e 30a2827 |
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 |
import gradio as gr
import cv2
import pickle
import skimage
from skimage.feature import local_binary_pattern
clf = None
with open('classifier.pkl', 'rb') as f:
clf = pickle.load(f)
def img2text(img):
# print(img)
# Resize the image to a specific width and height
image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
resized_image = cv2.resize(image, (24, 24))
# Compute the LBP feature vector
lbp_feature_vector = local_binary_pattern(resized_image, 8, 1, method="uniform")
# Print the feature vector
# print(lbp_feature_vector)
flattened_arr = lbp_feature_vector.reshape(-1)
# print(flattened_arr)
y_pred = clf.predict([flattened_arr])
if y_pred[0] == 0:
return 'face'
else:
return 'non-face'
import gradio as gr
# gr.Interface(txt2img, gr.Image(), gr.Text(), title = 'Stable Diffusion 2.0 Colab with Gradio UI').launch(share = True, debug = True)
iface = gr.Interface(img2text, gr.Image(), gr.Text(), title = 'Face Detector: Local Binary Pattern method, Support Vector Machine algorithm')
iface.launch()
# file_path = 'images/Copy of 35.jpg'
# # Load the image
# image = cv2.imread(file_path)
# print(image.shape)
# # Resize the image to a specific width and height
# image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# resized_image = cv2.resize(image, (24, 24))
# lbp_feature_vector = local_binary_pattern(resized_image, 8, 1, method="uniform")
# flattened_arr = lbp_feature_vector.reshape(-1)
# y_pred = clf.predict([flattened_arr])
# print(y_pred)
|