|
import gradio as gr |
|
|
|
|
|
|
|
def predict_age_gender(image): |
|
json_file = open('model2222.json', 'r') |
|
loaded_file_json = json_file.read() |
|
json_file.close() |
|
|
|
model = model_from_json(loaded_file_json) |
|
model.load_weights('saved_modelpb') |
|
|
|
|
|
|
|
|
|
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(share=True) |
|
|