Spaces:
Runtime error
Runtime error
File size: 961 Bytes
4ec72e6 d2cb493 86d024c d2cb493 ca47061 a7f8465 0fe6a90 d4ac851 f1c3359 86d024c 4374108 0b78266 d2cb493 f1c3359 fa76574 f1c3359 fa76574 4374108 0b78266 6ec5987 ac22fc1 6ec5987 a4c1f2f 6ec5987 a4c1f2f 6ec5987 4ec72e6 86d024c |
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 |
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[np.round(pred[0][0][0])]
b = np.round(pred[1][0][0])
c = dict_eth[np.argmax(pred_eth)]
return a,b,c
gr.Interface(fn=fun, inputs=gr.inputs.Image(image_mode='L',type='numpy',invert_colors=False), outputs=["text","text","text"]).launch() |