Jeysshon
commited on
Commit
•
55316a9
1
Parent(s):
144db47
Upload 10 files
Browse files- PrivateTest_10131363.jpg +0 -0
- angry1.png +0 -0
- angry2.jpg +0 -0
- app.py +47 -0
- emotions_jey.pkl +3 -0
- happy1.jpg +0 -0
- happy2.jpg +0 -0
- neutral1.jpg +0 -0
- neutral2.jpg +0 -0
- sentiment_jey.pkl +3 -0
PrivateTest_10131363.jpg
ADDED
angry1.png
ADDED
angry2.jpg
ADDED
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
from fastai.vision.all import *
|
3 |
+
import gradio as gr
|
4 |
+
|
5 |
+
# Cargar los modelos
|
6 |
+
learn_emotion = load_learner('/content/drive/MyDrive/carpeta de PIB/emotions_javier_almeida.pkl')
|
7 |
+
learn_emotion_labels = learn_emotion.dls.vocab
|
8 |
+
|
9 |
+
learn_sentiment = load_learner('/content/drive/MyDrive/carpeta de PIB/sentiment_javier_almeida.pkl')
|
10 |
+
learn_sentiment_labels = learn_sentiment.dls.vocab
|
11 |
+
|
12 |
+
# Función de predicción
|
13 |
+
def predict(img_path):
|
14 |
+
img = PILImage.create(img_path)
|
15 |
+
|
16 |
+
pred_emotion, pred_emotion_idx, probs_emotion = learn_emotion.predict(img)
|
17 |
+
pred_sentiment, pred_sentiment_idx, probs_sentiment = learn_sentiment.predict(img)
|
18 |
+
|
19 |
+
emotions = {label: float(prob) for label, prob in zip(learn_emotion_labels, probs_emotion)}
|
20 |
+
sentiments = {label: float(prob) for label, prob in zip(learn_sentiment_labels, probs_sentiment)}
|
21 |
+
|
22 |
+
return emotions, sentiments
|
23 |
+
|
24 |
+
# Interfaz de Gradio
|
25 |
+
title = "Detector de emociones y sentimientos faciales para parciales finales de PIB"
|
26 |
+
description = (
|
27 |
+
"Esta interfaz utiliza redes neuronales para detectar emociones y sentimientos a partir de imágenes faciales."
|
28 |
+
)
|
29 |
+
article = "Esta herramienta proporciona una forma rápida de analizar emociones y sentimientos en imágenes."
|
30 |
+
|
31 |
+
examples = [
|
32 |
+
'/content/drive/MyDrive/carpeta de PIB/angry1.png',
|
33 |
+
'/content/drive/MyDrive/carpeta de PIB/neutral1.jpg'
|
34 |
+
]
|
35 |
+
|
36 |
+
iface = gr.Interface(
|
37 |
+
fn=predict,
|
38 |
+
inputs=gr.Image(shape=(48, 48), image_mode='L'),
|
39 |
+
outputs=[gr.Label(label='Emotion'), gr.Label(label='Sentiment')],
|
40 |
+
title=title,
|
41 |
+
examples=examples,
|
42 |
+
description=description,
|
43 |
+
article=article,
|
44 |
+
allow_flagging='never'
|
45 |
+
)
|
46 |
+
|
47 |
+
iface.launch(enable_queue=True)
|
emotions_jey.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:335570ccf5133bc1fc0d4cc9bb7835b72fd457a64c0cdefbbc863f1c24cc4454
|
3 |
+
size 82965753
|
happy1.jpg
ADDED
happy2.jpg
ADDED
neutral1.jpg
ADDED
neutral2.jpg
ADDED
sentiment_jey.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e6fc0f18d5a082cd835b6b8cbd32041170be0ac20b7ca555df1209e2e4d181c3
|
3 |
+
size 82957497
|