Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -21,7 +21,7 @@ import numpy as np
|
|
21 |
|
22 |
|
23 |
from keras.models import model_from_json
|
24 |
-
|
25 |
#from keras.applications.vgg16 import VGG16, preprocess_input
|
26 |
#import heapq
|
27 |
|
@@ -30,7 +30,7 @@ model_json2 = file.read()
|
|
30 |
#file.close()
|
31 |
loaded_model = model_from_json(model_json2)
|
32 |
#loaded_model = model_from_json("focusondriving.json")
|
33 |
-
loaded_model.load_weights("focusondriving.h5")
|
34 |
|
35 |
class_dict = {
|
36 |
'c0': 'hands on the wheel',
|
@@ -46,26 +46,26 @@ class_dict = {
|
|
46 |
}
|
47 |
|
48 |
def predict_image(pic):
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
txt3="pepe"
|
70 |
return txt3
|
71 |
|
@@ -82,7 +82,7 @@ iface = gr.Interface(
|
|
82 |
|
83 |
|
84 |
interpretation="default",
|
85 |
-
title = 'FER - Facial Expression
|
86 |
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/ ',
|
87 |
|
88 |
theme = 'grass'
|
|
|
21 |
|
22 |
|
23 |
from keras.models import model_from_json
|
24 |
+
from keras.preprocessing import image
|
25 |
#from keras.applications.vgg16 import VGG16, preprocess_input
|
26 |
#import heapq
|
27 |
|
|
|
30 |
#file.close()
|
31 |
loaded_model = model_from_json(model_json2)
|
32 |
#loaded_model = model_from_json("focusondriving.json")
|
33 |
+
#loaded_model.load_weights("focusondriving.h5")
|
34 |
|
35 |
class_dict = {
|
36 |
'c0': 'hands on the wheel',
|
|
|
46 |
}
|
47 |
|
48 |
def predict_image(pic):
|
49 |
+
img = image.load_img(pic, target_size=(224, 224))
|
50 |
+
x = image.img_to_array(img)
|
51 |
+
x = np.expand_dims(x, axis=0)
|
52 |
+
#x = preprocess_input(x)
|
53 |
+
preds = loaded_model.predict(x)
|
54 |
+
preds = list(preds[0])
|
55 |
|
56 |
+
list_desc_order = heapq.nlargest(2, range(len(preds)), key=preds.__getitem__)
|
57 |
+
result1 = f'c{list_desc_order[0]}'
|
58 |
+
result2 = '-'
|
59 |
+
result2_ = 0
|
60 |
+
if preds[list_desc_order[1]] > 0.3:
|
61 |
+
result2 = f'c{list_desc_order[1]}'
|
62 |
+
result2_ = round(preds[list_desc_order[1]], 2)
|
63 |
+
txt = f"category {directory} result 1 {result1} {round(preds[list_desc_order[0]],2)} | result2 {result2} {result2_}"
|
64 |
+
txt = f"categoria {directory}"
|
65 |
|
66 |
+
score = round(preds[list_desc_order[0]], 2)*100
|
67 |
+
score = int(score)
|
68 |
+
txt2 = f"resultado: {class_dict.get(result1)} probabilidad {score}%"
|
69 |
txt3="pepe"
|
70 |
return txt3
|
71 |
|
|
|
82 |
|
83 |
|
84 |
interpretation="default",
|
85 |
+
title = 'FER - Facial Expression Recognitionllll',
|
86 |
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/ ',
|
87 |
|
88 |
theme = 'grass'
|