Spaces:
Runtime error
Runtime error
Commit
•
c61108c
1
Parent(s):
e5d72ba
Update app.py
Browse files
app.py
CHANGED
@@ -1,77 +1,76 @@
|
|
1 |
-
import tensorflow as tf
|
2 |
-
import gradio as gr
|
3 |
-
import cv2
|
4 |
-
|
5 |
-
json_file=open(r"dark_s.json","r")
|
6 |
-
loaded_model_json=json_file.read()
|
7 |
-
json_file.close()
|
8 |
-
loaded_model= tf.keras.models.model_from_json(loaded_model_json)
|
9 |
-
loaded_model.load_weights("dark_s.h5")
|
10 |
-
|
11 |
-
json_file=open(r"eyes_d.json","r")
|
12 |
-
loaded_model_json=json_file.read()
|
13 |
-
json_file.close()
|
14 |
-
loaded_model1 = tf.keras.models.model_from_json(loaded_model_json)
|
15 |
-
loaded_model1.load_weights("eyes_d.h5")
|
16 |
-
|
17 |
-
json_file=open(r"wrinkl.json","r")
|
18 |
-
loaded_model_json=json_file.read()
|
19 |
-
json_file.close()
|
20 |
-
loaded_model2 = tf.keras.models.model_from_json(loaded_model_json)
|
21 |
-
loaded_model2.load_weights("wrinkl.h5")
|
22 |
-
|
23 |
-
|
24 |
-
def image_bounder(img1):
|
25 |
-
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades +'haarcascade_frontalface_default.xml')
|
26 |
-
eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades +'haarcascade_eye.xml')
|
27 |
-
gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
|
28 |
-
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
29 |
-
|
30 |
-
for (x,y,w,h) in faces:
|
31 |
-
cv2.rectangle(img1,(x,y),(x+w,y+h),(255,255,0),2)
|
32 |
-
roi_gray = gray[y:y+h, x:x+w]
|
33 |
-
roi_color = img1[y:y+h, x:x+w]
|
34 |
-
|
35 |
-
eyes = eye_cascade.detectMultiScale(roi_gray)
|
36 |
-
|
37 |
-
for (ex,ey,ew,eh) in eyes:
|
38 |
-
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,127,255),2)
|
39 |
-
|
40 |
-
return img1
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
result =
|
47 |
-
result
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
result =
|
54 |
-
result
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
result =
|
61 |
-
result
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
examples=[['42.jpg'],['71.jpg'],['11.jfif'],['56.jpg'],['1836.png']])
|
77 |
interface.launch()
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
import gradio as gr
|
3 |
+
import cv2
|
4 |
+
|
5 |
+
json_file=open(r"dark_s.json","r")
|
6 |
+
loaded_model_json=json_file.read()
|
7 |
+
json_file.close()
|
8 |
+
loaded_model= tf.keras.models.model_from_json(loaded_model_json)
|
9 |
+
loaded_model.load_weights("dark_s.h5")
|
10 |
+
|
11 |
+
json_file=open(r"eyes_d.json","r")
|
12 |
+
loaded_model_json=json_file.read()
|
13 |
+
json_file.close()
|
14 |
+
loaded_model1 = tf.keras.models.model_from_json(loaded_model_json)
|
15 |
+
loaded_model1.load_weights("eyes_d.h5")
|
16 |
+
|
17 |
+
json_file=open(r"wrinkl.json","r")
|
18 |
+
loaded_model_json=json_file.read()
|
19 |
+
json_file.close()
|
20 |
+
loaded_model2 = tf.keras.models.model_from_json(loaded_model_json)
|
21 |
+
loaded_model2.load_weights("wrinkl.h5")
|
22 |
+
|
23 |
+
|
24 |
+
def image_bounder(img1):
|
25 |
+
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades +'haarcascade_frontalface_default.xml')
|
26 |
+
eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades +'haarcascade_eye.xml')
|
27 |
+
gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
|
28 |
+
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
|
29 |
+
|
30 |
+
for (x,y,w,h) in faces:
|
31 |
+
cv2.rectangle(img1,(x,y),(x+w,y+h),(255,255,0),2)
|
32 |
+
roi_gray = gray[y:y+h, x:x+w]
|
33 |
+
roi_color = img1[y:y+h, x:x+w]
|
34 |
+
|
35 |
+
eyes = eye_cascade.detectMultiScale(roi_gray)
|
36 |
+
|
37 |
+
for (ex,ey,ew,eh) in eyes:
|
38 |
+
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,127,255),2)
|
39 |
+
|
40 |
+
return img1
|
41 |
+
|
42 |
+
def classifier(Imgarr):
|
43 |
+
l = []
|
44 |
+
img = Imgarr.reshape(-1, 50, 50, 3)
|
45 |
+
result = loaded_model.predict(img)
|
46 |
+
result = result[0]
|
47 |
+
if result[0] >= result[1]:
|
48 |
+
l.append("dark spots")
|
49 |
+
else:
|
50 |
+
l.append("no dark spots")
|
51 |
+
|
52 |
+
result = loaded_model1.predict(img)
|
53 |
+
result = result[0]
|
54 |
+
if result[0] >= result[1]:
|
55 |
+
l.append("no puffy eyes")
|
56 |
+
else:
|
57 |
+
l.append("puffy eyes")
|
58 |
+
|
59 |
+
result = loaded_model2.predict(img)
|
60 |
+
result = result[0]
|
61 |
+
if result[0] >= result[1]:
|
62 |
+
l.append("no wrinkles on face")
|
63 |
+
else:
|
64 |
+
l.append("wrinkles on face")
|
65 |
+
|
66 |
+
return "Predictions are : "+str(l)
|
67 |
+
|
68 |
+
def out(Imgarr):
|
69 |
+
return [image_bounder(Imgarr),classifier(Imgarr)]
|
70 |
+
|
71 |
+
interface = gr.Interface(out,gr.inputs.Image(shape=(300,300)),
|
72 |
+
outputs = ["image","text"],
|
73 |
+
description="Classifier of Aging Signs of Images",
|
74 |
+
title="Aging Signs Classifier",
|
75 |
+
examples=[['42.jpg'],['71.jpg'],['11.jfif'],['56.jpg'],['1836.png']])
|
|
|
76 |
interface.launch()
|