Spaces:
Runtime error
Runtime error
Luis
commited on
Commit
·
30a2827
1
Parent(s):
239a35e
v4
Browse files- app.py +55 -3
- classifier.pkl +3 -0
- images/Copy of 35.jpg +0 -0
- images/Copy of Alex_Gonzalez_0001.jpg +0 -0
app.py
CHANGED
@@ -1,7 +1,59 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
|
|
5 |
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import cv2
|
3 |
+
import pickle
|
4 |
+
import skimage
|
5 |
+
from skimage.feature import local_binary_pattern
|
6 |
|
7 |
+
clf = None
|
8 |
+
with open('classifier.pkl', 'rb') as f:
|
9 |
+
clf = pickle.load(f)
|
10 |
|
11 |
+
|
12 |
+
def img2text(img):
|
13 |
+
# print(img)
|
14 |
+
# Resize the image to a specific width and height
|
15 |
+
image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
16 |
+
|
17 |
+
resized_image = cv2.resize(image, (24, 24))
|
18 |
+
|
19 |
+
# Compute the LBP feature vector
|
20 |
+
lbp_feature_vector = local_binary_pattern(resized_image, 8, 1, method="uniform")
|
21 |
+
|
22 |
+
# Print the feature vector
|
23 |
+
# print(lbp_feature_vector)
|
24 |
+
|
25 |
+
flattened_arr = lbp_feature_vector.reshape(-1)
|
26 |
+
# print(flattened_arr)
|
27 |
+
|
28 |
+
y_pred = clf.predict([flattened_arr])
|
29 |
+
return str(y_pred[0])
|
30 |
+
|
31 |
+
|
32 |
+
import gradio as gr
|
33 |
+
|
34 |
+
# gr.Interface(txt2img, gr.Image(), gr.Text(), title = 'Stable Diffusion 2.0 Colab with Gradio UI').launch(share = True, debug = True)
|
35 |
+
|
36 |
+
iface = gr.Interface(img2text, gr.Image(), gr.Text(), title = 'Face Detector: Local Binary Pattern method, Support Vector Machine algorithm')
|
37 |
iface.launch()
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
# file_path = 'images/Copy of 35.jpg'
|
43 |
+
|
44 |
+
# # Load the image
|
45 |
+
# image = cv2.imread(file_path)
|
46 |
+
# print(image.shape)
|
47 |
+
|
48 |
+
# # Resize the image to a specific width and height
|
49 |
+
# image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
50 |
+
|
51 |
+
# resized_image = cv2.resize(image, (24, 24))
|
52 |
+
|
53 |
+
# lbp_feature_vector = local_binary_pattern(resized_image, 8, 1, method="uniform")
|
54 |
+
|
55 |
+
# flattened_arr = lbp_feature_vector.reshape(-1)
|
56 |
+
|
57 |
+
|
58 |
+
# y_pred = clf.predict([flattened_arr])
|
59 |
+
# print(y_pred)
|
classifier.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8734e11d6f73c9d24a3a36b74c5a797cf3a8d559f2c91650158cb5cd18a07123
|
3 |
+
size 575021
|
images/Copy of 35.jpg
ADDED
![]() |
images/Copy of Alex_Gonzalez_0001.jpg
ADDED
![]() |