Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- app.py +51 -0
- haarcascade_eye.xml +0 -0
- haarcascade_frontalface_default.xml +0 -0
- hp.h5 +3 -0
- requirements.txt +16 -0
app.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import numpy as np
|
| 4 |
+
import cv2, joblib
|
| 5 |
+
import keras
|
| 6 |
+
from keras.models import load_model
|
| 7 |
+
|
| 8 |
+
face_cascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
|
| 9 |
+
eye_cascade = cv2.CascadeClassifier("haarcascade_eye.xml")
|
| 10 |
+
model = load_model("hp.h5")
|
| 11 |
+
label = {'Alan Rickman': 0,
|
| 12 |
+
'Daniel Radcliffe': 1,
|
| 13 |
+
'Emma Watson': 2,
|
| 14 |
+
'Gary Oldman': 3,
|
| 15 |
+
'Helena Bonham Carter': 4,
|
| 16 |
+
'Maggie Smith': 5,
|
| 17 |
+
'Michael Gambon': 6,
|
| 18 |
+
'Ralph Fiennes': 7,
|
| 19 |
+
'Robbie Coltrane': 8,
|
| 20 |
+
'Rupert Grint': 9,
|
| 21 |
+
'Tom Felton': 10}
|
| 22 |
+
def get_cropped_image_if_2_eyes(img):
|
| 23 |
+
if (img is not None):
|
| 24 |
+
gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
|
| 25 |
+
faces = face_cascade.detectMultiScale(gray,1.3,5)
|
| 26 |
+
for (x,y,w,h) in faces:
|
| 27 |
+
roi_gray = gray[y:y+h,x:x+w]
|
| 28 |
+
roi_color = img[y:y+h,x:x+w]
|
| 29 |
+
eyes = eye_cascade.detectMultiScale(roi_gray)
|
| 30 |
+
if len(eyes)>=2:
|
| 31 |
+
return roi_color
|
| 32 |
+
|
| 33 |
+
def predict(img):
|
| 34 |
+
if img is not None:
|
| 35 |
+
# read = Image.open(img,"r")
|
| 36 |
+
arr = np.array(img)
|
| 37 |
+
crp_img = get_cropped_image_if_2_eyes(arr)
|
| 38 |
+
|
| 39 |
+
if crp_img is not None:
|
| 40 |
+
crp_img = np.array(crp_img)
|
| 41 |
+
resized_img = cv2.resize(img,(180,180))
|
| 42 |
+
empty = np.zeros((100,180,180,3))
|
| 43 |
+
empty[0]= resized_img
|
| 44 |
+
empty= empty/255
|
| 45 |
+
prediction = model.predict(empty)
|
| 46 |
+
return {list(label.keys())[i]: prediction[0][i] for i in range(11)}
|
| 47 |
+
|
| 48 |
+
image = gr.Image(height=180, width=180)
|
| 49 |
+
labels = gr.Label(num_top_classes = 5)
|
| 50 |
+
gr.Interface(fn=predict, inputs= image, outputs = labels).launch(share=True)
|
| 51 |
+
|
haarcascade_eye.xml
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
haarcascade_frontalface_default.xml
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
hp.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f2ac4c57947f6c2c31d4586d43a587e512ff9e9223edd796d23cd58ac7227b20
|
| 3 |
+
size 16676936
|
requirements.txt
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
joblib
|
| 2 |
+
keras
|
| 3 |
+
matplotlib
|
| 4 |
+
matplotlib-inline
|
| 5 |
+
numpy
|
| 6 |
+
opencv-python
|
| 7 |
+
pickleshare
|
| 8 |
+
Pillow
|
| 9 |
+
streamlit
|
| 10 |
+
tensorboard
|
| 11 |
+
tensorboard-data-server
|
| 12 |
+
tensorflow
|
| 13 |
+
tensorflow-estimator
|
| 14 |
+
tensorflow-hub
|
| 15 |
+
tensorflow-io-gcs-filesystem
|
| 16 |
+
|