Jeysshon
commited on
Commit
•
9f94bb9
1
Parent(s):
2a1d5c1
Upload cosas.txt
Browse files
cosas.txt
ADDED
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from fastai.vision.all import *
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
# Cargar los modelos
|
6 |
+
learn_emotion = load_learner('emotions_jey.pkl')
|
7 |
+
learn_emotion_labels = learn_emotion.dls.vocab
|
8 |
+
|
9 |
+
learn_sentiment = load_learner('sentiment_jey.pkl')
|
10 |
+
learn_sentiment_labels = learn_sentiment.dls.vocab
|
11 |
+
|
12 |
+
# Diccionario de mapeo de etiquetas en inglés a etiquetas en español
|
13 |
+
label_mapping = {
|
14 |
+
'angry': 'enojado',
|
15 |
+
'disgust': 'asco',
|
16 |
+
'fear': 'miedo',
|
17 |
+
'happy': 'feliz',
|
18 |
+
'sad': 'triste',
|
19 |
+
'surprise': 'sorpresa',
|
20 |
+
'neutral': 'neutral',
|
21 |
+
'negative': 'negativo',
|
22 |
+
'positive': 'positivo'
|
23 |
+
}
|
24 |
+
|
25 |
+
# Función de predicción
|
26 |
+
def predict(img_path):
|
27 |
+
img = PILImage.create(img_path)
|
28 |
+
|
29 |
+
pred_emotion, pred_emotion_idx, probs_emotion = learn_emotion.predict(img)
|
30 |
+
pred_sentiment, pred_sentiment_idx, probs_sentiment = learn_sentiment.predict(img)
|
31 |
+
|
32 |
+
emotions = {label_mapping[label]: float(prob) for label, prob in zip(learn_emotion_labels, probs_emotion)}
|
33 |
+
sentiments = {label_mapping[label]: float(prob) for label, prob in zip(learn_sentiment_labels, probs_sentiment)}
|
34 |
+
|
35 |
+
return emotions, sentiments
|
36 |
+
|
37 |
+
# Interfaz de Gradio
|
38 |
+
title = "Detector de emociones y sentimientos faciales"
|
39 |
+
description = (
|
40 |
+
"Esta interfaz utiliza redes neuronales para detectar emociones y sentimientos a partir de imágenes faciales."
|
41 |
+
)
|
42 |
+
article = "Esta herramienta proporciona una forma rápida de analizar emociones y sentimientos en imágenes."
|
43 |
+
|
44 |
+
examples = [
|
45 |
+
'PrivateTest_10131363.jpg',
|
46 |
+
'angry1.png',
|
47 |
+
'angry2.jpg',
|
48 |
+
'happy1.jpg',
|
49 |
+
'happy2.jpg',
|
50 |
+
'neutral1.jpg',
|
51 |
+
'neutral2.jpg'
|
52 |
+
]
|
53 |
+
|
54 |
+
iface = gr.Interface(
|
55 |
+
fn=predict,
|
56 |
+
inputs=gr.Image(shape=(48, 48), image_mode='L'),
|
57 |
+
outputs=[gr.Label(label='Emoción'), gr.Label(label='Sentimiento')],
|
58 |
+
title=title,
|
59 |
+
examples=examples,
|
60 |
+
description=description,
|
61 |
+
article=article,
|
62 |
+
allow_flagging='never'
|
63 |
+
)
|
64 |
+
|
65 |
+
iface.launch(enable_queue=True)
|
66 |
+
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
+
#################
|
73 |
+
|
74 |
+
import os
|
75 |
+
from fastai.vision.all import *
|
76 |
+
import gradio as gr
|
77 |
+
|
78 |
+
# Cargar los modelos
|
79 |
+
learn_emotion = load_learner('emotions_jey.pkl')
|
80 |
+
learn_emotion_labels = learn_emotion.dls.vocab
|
81 |
+
|
82 |
+
learn_sentiment = load_learner('sentiment_jey.pkl')
|
83 |
+
learn_sentiment_labels = learn_sentiment.dls.vocab
|
84 |
+
|
85 |
+
# Función de predicción
|
86 |
+
def predict(img_path):
|
87 |
+
img = PILImage.create(img_path)
|
88 |
+
|
89 |
+
pred_emotion, pred_emotion_idx, probs_emotion = learn_emotion.predict(img)
|
90 |
+
pred_sentiment, pred_sentiment_idx, probs_sentiment = learn_sentiment.predict(img)
|
91 |
+
|
92 |
+
emotions = {label: float(prob) for label, prob in zip(learn_emotion_labels, probs_emotion)}
|
93 |
+
sentiments = {label: float(prob) for label, prob in zip(learn_sentiment_labels, probs_sentiment)}
|
94 |
+
|
95 |
+
return emotions, sentiments
|
96 |
+
|
97 |
+
# Interfaz de Gradio
|
98 |
+
title = "Detector de emociones y sentimientos faciales "
|
99 |
+
description = (
|
100 |
+
"Esta interfaz utiliza redes neuronales para detectar emociones y sentimientos a partir de imágenes faciales."
|
101 |
+
)
|
102 |
+
article = "Esta herramienta proporciona una forma rápida de analizar emociones y sentimientos en imágenes."
|
103 |
+
|
104 |
+
examples = [
|
105 |
+
'PrivateTest_10131363.jpg',
|
106 |
+
'angry1.png',
|
107 |
+
'angry2.jpg',
|
108 |
+
'happy1.jpg',
|
109 |
+
'happy2.jpg',
|
110 |
+
'neutral1.jpg',
|
111 |
+
'neutral2.jpg'
|
112 |
+
|
113 |
+
]
|
114 |
+
|
115 |
+
iface = gr.Interface(
|
116 |
+
fn=predict,
|
117 |
+
inputs=gr.Image(shape=(48, 48), image_mode='L'),
|
118 |
+
outputs=[gr.Label(label='Emotion'), gr.Label(label='Sentiment')],
|
119 |
+
title=title,
|
120 |
+
examples=examples,
|
121 |
+
description=description,
|
122 |
+
article=article,
|
123 |
+
allow_flagging='never'
|
124 |
+
)
|
125 |
+
|
126 |
+
iface.launch(enable_queue=True)
|
127 |
+
|
128 |
+
|