import tensorflow as tf import gradio as gr import cv2 json_file=open(r"dark_s.json","r") loaded_model_json=json_file.read() json_file.close() loaded_model= tf.keras.models.model_from_json(loaded_model_json) loaded_model.load_weights("dark_s.h5") json_file=open(r"eyes_d.json","r") loaded_model_json=json_file.read() json_file.close() loaded_model1 = tf.keras.models.model_from_json(loaded_model_json) loaded_model1.load_weights("eyes_d.h5") json_file=open(r"wrinkl.json","r") loaded_model_json=json_file.read() json_file.close() loaded_model2 = tf.keras.models.model_from_json(loaded_model_json) loaded_model2.load_weights("wrinkl.h5") def image_bounder(img1): face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades +'haarcascade_frontalface_default.xml') eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades +'haarcascade_eye.xml') gray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 5) for (x,y,w,h) in faces: cv2.rectangle(img1,(x,y),(x+w,y+h),(255,255,0),2) roi_gray = gray[y:y+h, x:x+w] roi_color = img1[y:y+h, x:x+w] eyes = eye_cascade.detectMultiScale(roi_gray) for (ex,ey,ew,eh) in eyes: cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,127,255),2) return img1 def classifier(Imgarr): l = [] img = Imgarr.reshape(-1, 50, 50, 3) result = loaded_model.predict(img) result = result[0] if result[0] >= result[1]: l.append("dark spots") else: l.append("no dark spots") result = loaded_model1.predict(img) result = result[0] if result[0] >= result[1]: l.append("no puffy eyes") else: l.append("puffy eyes") result = loaded_model2.predict(img) result = result[0] if result[0] >= result[1]: l.append("no wrinkles on face") else: l.append("wrinkles on face") return "Predictions are : "+str(l) def out(Imgarr): return [image_bounder(Imgarr),classifier(Imgarr)] interface = gr.Interface(out,gr.inputs.Image(shape=(300,300)), outputs = ["image","text"], description="Classifier of Aging Signs of Images", title="Aging Signs Classifier", examples=[['42.jpg'],['778.jpg'],['1836.png'],['71.jpg'],['56.jpg']]) interface.launch()