FER / app.py
KikoDM's picture
Update app.py
e813b86
raw
history blame
1.66 kB
import gradio as gr
import pandas as pd
import numpy as np
import os
from tqdm import tqdm
import tensorflow as tf
from tensorflow import keras
from keras.utils import np_utils
from keras.preprocessing import image
from keras.preprocessing.image import ImageDataGenerator
import matplotlib.pyplot as plt
new_model = tf.keras.models.load_model('modelo_entrenado.h5')
objects = ('angry', 'disgust', 'fear', 'happy', 'sad', 'surprise', 'neutral')
y_pos = np.arange(len(objects))
def predict_image(pic):
img = image.load_img(pic, grayscale=True, target_size=(48, 48))
x = image.img_to_array(img)
x = np.expand_dims(x, axis = 0)
x /= 255
custom = new_model.predict(x)
m=0.000000000000000000001
a=custom[0]
for i in range(0,len(a)):
if a[i]>m:
m=a[i]
ind=i
return ('Expression Prediction:',objects[ind])
iface = gr.Interface(
predict_image,
[
gr.inputs.Image(source="upload",type="filepath", label="Imagen")
],
"text",
interpretation="default",
title = 'FER - Facial Expression Recognition',
description = 'Probablemente nos daremos cuenta de que muchas veces se miente cuando se tratan las emociones, ¿pero nuestra cara también miente? https://saturdays.ai/2022/03/16/detectando-emociones-mediante-imagenes-con-inteligencia-artificial/ ',
examples=[["28860.png"], ["28790.png"], ["28953.png"], ["30369.png"], ["28722.png"], ["29026.png"], ["28857.png"], ["28795.png"], ["28880.png"], ["28735.png"], ["28757.png"], ["28727.png"], ["28874.png"], ["28723.png"]],
theme = 'grass'
)
iface.launch()