Update app.py
Browse files
app.py
CHANGED
@@ -2,61 +2,28 @@ import gradio as gr
|
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
4 |
import os
|
5 |
-
#import cv2
|
6 |
from tqdm import tqdm
|
7 |
import tensorflow as tf
|
8 |
from tensorflow import keras
|
9 |
from keras.utils import np_utils
|
10 |
-
#from tensorflow.python.keras.preprocessing import image
|
11 |
-
#from tensorflow.python.keras.preprocessing.image import ImageDataGenerator
|
12 |
from keras.preprocessing import image
|
13 |
from keras.preprocessing.image import ImageDataGenerator
|
14 |
-
#from skimage import io
|
15 |
import matplotlib.pyplot as plt
|
16 |
-
#from tensorflow.python.keras.utils import np_utils
|
17 |
-
import pickle
|
18 |
-
#with Path("modelo_entrenado.pkl").open("br")as f:
|
19 |
-
# new_model=pickle.load(f)
|
20 |
-
#new_model = pickle.load(open("modelo_entrenado.pkl", 'rb'))
|
21 |
|
22 |
new_model = tf.keras.models.load_model('modelo_entrenado.h5')
|
23 |
objects = ('angry', 'disgust', 'fear', 'happy', 'sad', 'surprise', 'neutral')
|
24 |
y_pos = np.arange(len(objects))
|
25 |
-
print(y_pos)
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
def emotion_analysis(emotions):
|
30 |
-
objects = ['angry', 'disgust', 'fear', 'happy', 'sad', 'surprise', 'neutral']
|
31 |
-
y_pos = np.arange(len(objects))
|
32 |
-
plt.bar(y_pos, emotions, align='center', alpha=0.9)
|
33 |
-
plt.tick_params(axis='x', which='both', pad=10,width=4,length=10)
|
34 |
-
plt.xticks(y_pos, objects)
|
35 |
-
plt.ylabel('percentage')
|
36 |
-
plt.title('emotion')
|
37 |
-
plt.show()
|
38 |
|
39 |
|
40 |
def predict_image(pic):
|
41 |
img = image.load_img(pic, grayscale=True, target_size=(48, 48))
|
42 |
-
#show_img=image.load_img(pic, grayscale=False, target_size=(200, 200))
|
43 |
-
#pic = pic.reshape(-1,48, 48,1])
|
44 |
x = image.img_to_array(img)
|
45 |
|
46 |
x = np.expand_dims(x, axis = 0)
|
47 |
|
48 |
x /= 255
|
49 |
-
#x = x.reshape(1,48,48,1)
|
50 |
-
custom = new_model.predict(x)
|
51 |
-
|
52 |
-
#emotion_analysis(custom[0])
|
53 |
-
|
54 |
-
#x = np.array(x, 'float32')
|
55 |
-
#x = x.reshape([48, 48]);
|
56 |
|
57 |
-
|
58 |
-
#plt.imshow(show_img)
|
59 |
-
#plt.show()
|
60 |
|
61 |
m=0.000000000000000000001
|
62 |
a=custom[0]
|
@@ -70,17 +37,16 @@ def predict_image(pic):
|
|
70 |
iface = gr.Interface(
|
71 |
predict_image,
|
72 |
[
|
73 |
-
|
74 |
-
|
75 |
-
gr.inputs.Image(source="upload",type="filepath")
|
76 |
],
|
77 |
|
78 |
"text",
|
79 |
|
80 |
|
81 |
interpretation="default",
|
82 |
-
title = 'FER',
|
83 |
-
description = '
|
84 |
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"]],
|
85 |
theme = 'grass'
|
86 |
)
|
|
|
2 |
import pandas as pd
|
3 |
import numpy as np
|
4 |
import os
|
|
|
5 |
from tqdm import tqdm
|
6 |
import tensorflow as tf
|
7 |
from tensorflow import keras
|
8 |
from keras.utils import np_utils
|
|
|
|
|
9 |
from keras.preprocessing import image
|
10 |
from keras.preprocessing.image import ImageDataGenerator
|
|
|
11 |
import matplotlib.pyplot as plt
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
new_model = tf.keras.models.load_model('modelo_entrenado.h5')
|
14 |
objects = ('angry', 'disgust', 'fear', 'happy', 'sad', 'surprise', 'neutral')
|
15 |
y_pos = np.arange(len(objects))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
|
18 |
def predict_image(pic):
|
19 |
img = image.load_img(pic, grayscale=True, target_size=(48, 48))
|
|
|
|
|
20 |
x = image.img_to_array(img)
|
21 |
|
22 |
x = np.expand_dims(x, axis = 0)
|
23 |
|
24 |
x /= 255
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
custom = new_model.predict(x)
|
|
|
|
|
27 |
|
28 |
m=0.000000000000000000001
|
29 |
a=custom[0]
|
|
|
37 |
iface = gr.Interface(
|
38 |
predict_image,
|
39 |
[
|
40 |
+
|
41 |
+
gr.inputs.Image(source="upload",type="filepath", label="Imagen")
|
|
|
42 |
],
|
43 |
|
44 |
"text",
|
45 |
|
46 |
|
47 |
interpretation="default",
|
48 |
+
title = 'FER - Facial Expression Recognition',
|
49 |
+
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/ ',
|
50 |
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"]],
|
51 |
theme = 'grass'
|
52 |
)
|