akar49 commited on
Commit
8bbb76a
·
verified ·
1 Parent(s): e14daec

Upload 10 files

Browse files
Files changed (10) hide show
  1. angry1.png +0 -0
  2. angry2.jpg +0 -0
  3. app.py +44 -0
  4. emotions_vgg19.pkl +3 -0
  5. happy1.jpg +0 -0
  6. happy2.jpg +0 -0
  7. neutral1.jpg +0 -0
  8. neutral2.jpg +0 -0
  9. requirements.txt +1 -0
  10. sentiment_vgg19.pkl +3 -0
angry1.png ADDED
angry2.jpg ADDED
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Facial expression classifier
2
+ import os
3
+ from fastai.vision.all import *
4
+ import gradio as gr
5
+
6
+ # Emotion
7
+ learn_emotion = load_learner('emotions_vgg19.pkl')
8
+ learn_emotion_labels = learn_emotion.dls.vocab
9
+
10
+ # Sentiment
11
+ learn_sentiment = load_learner('sentiment_vgg19.pkl')
12
+ learn_sentiment_labels = learn_sentiment.dls.vocab
13
+
14
+ # Predict
15
+ def predict(img):
16
+ img = PILImage.create(img)
17
+
18
+ pred_emotion, pred_emotion_idx, probs_emotion = learn_emotion.predict(img)
19
+
20
+ pred_sentiment, pred_sentiment_idx, probs_sentiment = learn_sentiment.predict(img)
21
+
22
+ #emotions = {f'emotion_{learn_emotion_labels[i]}': float(probs_emotion[i]) for i in range(len(learn_emotion_labels))}
23
+ #sentiments = {f'sentiment_{learn_sentiment_labels[i]}': float(probs_sentiment[i]) for i in range(len(learn_sentiment_labels))}
24
+
25
+ emotions = {learn_emotion_labels[i]: float(probs_emotion[i]) for i in range(len(learn_emotion_labels))}
26
+ sentiments = {learn_sentiment_labels[i]: float(probs_sentiment[i]) for i in range(len(learn_sentiment_labels))}
27
+
28
+ return [emotions, sentiments] #{**emotions, **sentiments}
29
+
30
+ # Gradio
31
+ title = "Facial Emotion and Sentiment Detector"
32
+
33
+ enable_queue=True
34
+
35
+ examples = ['happy1.jpg', 'happy2.jpg', 'angry1.png', 'angry2.jpg', 'neutral1.jpg', 'neutral2.jpg']
36
+
37
+ gr.Interface(fn = predict,
38
+ inputs = gr.Image(shape=(48, 48), image_mode='L'),
39
+ outputs = [gr.Label(label='Emotion'), gr.Label(label='Sentiment')], #gr.Label(),
40
+ title = title,
41
+ examples = examples,
42
+ description = description,
43
+ article=article,
44
+ allow_flagging='never').launch(enable_queue=enable_queue)
emotions_vgg19.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
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ fastai
sentiment_vgg19.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e6fc0f18d5a082cd835b6b8cbd32041170be0ac20b7ca555df1209e2e4d181c3
3
+ size 82957497