File size: 1,682 Bytes
a5e0c71
 
 
 
 
 
 
 
a1bb2a0
1ac949f
a5e0c71
 
7242ff5
a5e0c71
 
 
 
 
6b572ff
 
bf0e2a9
faf4dab
f52b50a
5547529
a5e0c71
d58313d
e813b86
a5e0c71
 
 
 
 
 
 
 
 
 
 
 
 
e813b86
 
a5e0c71
 
 
 
38397f0
a5e0c71
e813b86
 
be4e77b
a5e0c71
a403ed6
a5e0c71
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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 tensorflow.keras.preprocessing import image
from tensorflow.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()