|
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 |
|
|
|
import pickle |
|
|
|
|
|
|
|
|
|
new_model = tf.keras.models.load_model('modelo_entrenado.h5') |
|
objects = ('angry', 'disgust', 'fear', 'happy', 'sad', 'surprise', 'neutral') |
|
y_pos = np.arange(len(objects)) |
|
print(y_pos) |
|
|
|
|
|
|
|
def emotion_analysis(emotions): |
|
objects = ['angry', 'disgust', 'fear', 'happy', 'sad', 'surprise', 'neutral'] |
|
y_pos = np.arange(len(objects)) |
|
plt.bar(y_pos, emotions, align='center', alpha=0.9) |
|
plt.tick_params(axis='x', which='both', pad=10,width=4,length=10) |
|
plt.xticks(y_pos, objects) |
|
plt.ylabel('percentage') |
|
plt.title('emotion') |
|
plt.show() |
|
|
|
|
|
def predict_image(pic): |
|
|
|
|
|
|
|
x = image.img_to_array(pic) |
|
|
|
|
|
|
|
|
|
|
|
custom = new_model.predict(x.reshape(0,48,48,1)) |
|
|
|
emotion_analysis(custom[0]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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",shape=(48,48)) |
|
], |
|
|
|
"text", |
|
|
|
|
|
interpretation="default", |
|
title = 'FER', |
|
description = 'El ', |
|
theme = 'grass' |
|
) |
|
|
|
|
|
|
|
iface.launch() |
|
|