File size: 808 Bytes
cd83a2a
dabc461
6e4fcd7
3d83403
4f92b40
cd83a2a
dabc461
 
 
 
a5a461a
 
 
 
 
 
 
5056ec5
 
 
 
 
 
 
 
 
 
 
6e4fcd7
4a4a28f
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
import gradio as gr
from keras.models import model_from_json
from tensorflow.keras.preprocessing import image
import numpy as np






def predict_age_gender(image):
    json_file = open('xception.json', 'r')
    loaded_file_json = json_file.read()
    json_file.close()
    
    model = model_from_json(loaded_file_json)
    model.load_weights('xception_modelv2.h5')
    img_pixels = np.expand_dims(image, axis=0)
    img_pixels = image.astype('float')
    img_pixels = img_pixels.reshape((1, 128, 128, 3))
    img_pixels /= 255

    predict = model.predict(img_pixels)
    gender_predict = predict[0]
    age_predict = predict[1]
    return {'Gender': ['Fmale' if gender_predict > 0.5 else 'Male'], 'Age': age_predict[0][0]}


iface = gr.Interface(predict_age_gender, gr.Image(), gr.Text())
iface.launch()