File size: 2,046 Bytes
8aac212
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a9216f4
 
 
ad1bb3e
a9216f4
 
 
8aac212
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
import numpy as np
import cv2
from keras.models import load_model
import gradio as gr

model_info=load_model("GenderPredict_Model.h5",compile=True)

def Gender_prediction(img,choice):
  value=-1
  if(choice=="Through_Id_Card"):
    face_classifier = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
    scale_percent = 60 # percent of original size
    width = int(img.shape[1] * scale_percent / 100)
    height = int(img.shape[0] * scale_percent / 100)
    dim = (width, height)
    image = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    faces = face_classifier.detectMultiScale(gray, 1.3, 5)
    if faces is ():
      print("No faces found")
    for (x, y, w, h) in faces:
      x = x - 25 # Padding trick to take the whole face not just Haarcascades points
      y = y - 40 # Same here...
      cv2.rectangle(image, (x, y), (x + w + 50, y + h + 70), (27, 200, 10), 2)
    for (x, y, width, height) in faces:
      roi = image[y:y+height, x:x+width]
      cv2.imwrite("face.jpg",roi)  
    img=cv2.resize(cv2.imread("face.jpg"),(224,224))
    result=model_info.predict(img.reshape(1,224,224,3))
    value=result.argmax()
  elif(choice=="Through_Image"):
    img=cv2.resize(img,(224,224))
    result=model_info.predict(img.reshape(1,224,224,3))
    value=result.argmax()
  if(value==0):
    return "You are Female"
  elif(value==1):
    return "You are male"
  else:
    return "No Predict please Choose any option"

interface=gr.Interface(fn=Gender_prediction,inputs=[gr.components.Image(label="Choose Image",type="numpy"),gr.components.Radio(['Through_Id_Card','Through_Image'],type="value",label="Select any One")],
                       outputs=[gr.components.Textbox(label="Your Result")],
                      examples=[
                          ["Girl_Id.jpg"],
                          ["Male_id.jpg"],
                          ["Female.jpg"],
                          ["Men.jpg"]
                      ])
interface.launch(debug=True)