import gradio as gr from huggingface_hub import from_pretrained_keras import numpy as np import logging from PIL import Image def fun(a): Im=Image.fromarray(a).resize((48,48)) reloaded_model = from_pretrained_keras('jmparejaz/Facial_Age-gender-eth_Recognition') reloaded_model_eth = from_pretrained_keras('jmparejaz/Facial_eth_recognition') #img=load_img(a, grayscale=True) a=np.asarray(Im) a=a.reshape(1, 48, 48, 1) a=a/255 #reshape((-1,48,48,1)) pred=reloaded_model.predict(a) pred_eth=reloaded_model_eth.predict(a) #dict_gender={0:'Male',1:'Female'} #dict_eth={0:"White", 1:"Black", 2:"Asian", 3:"Indian", 4:"Hispanic"} #a = dict_gender[pred[0][0][0]] b = np.round(pred[1][0][0]) #c = dict_eth[np.argmax(pred_eth)] return pred[0][0][0],b,np.argmax(pred_eth) gr.Interface(fn=fun, inputs=gr.inputs.Image(image_mode='L',type='numpy',invert_colors=False), outputs=["text","text","text"]).launch()