FER / app.py
KikoDM's picture
Update app.py
9567e44
raw
history blame
1.97 kB
import gradio as gr
import pandas as pd
import numpy as np
import os
import cv2
from tqdm import tqdm
import tensorflow as tf
from tensorflow import keras
from keras.utils import np_utils
from tensorflow.python.keras.preprocessing import image
from tensorflow.python.keras.preprocessing.image import ImageDataGenerator
from skimage import io
import matplotlib.pyplot as plt
from tensorflow.python.keras.utils import np_utils
new_model = tf.keras.models.load_model('my_model')
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):
img = image.load_img(pic, grayscale=True, target_size=(48, 48))
show_img=image.load_img(pic, grayscale=False, target_size=(200, 200))
x = image.img_to_array(img)
x = np.expand_dims(x, axis = 0)
x /= 255
custom = new_model.predict(x)
emotion_analysis(custom[0])
x = np.array(x, 'float32')
x = x.reshape([48, 48]);
plt.gray()
plt.imshow(show_img)
plt.show()
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,
[
gradio.inputs.Image(self, shape=None, image_mode="RGB", invert_colors=False, source="upload", tool="editor", type="numpy", label=None, optional=False)
],
"text",
,
interpretation="default",
title = 'FER',
description = 'El ',
theme = 'grass'
)
iface.launch()