drsaikirant88 commited on
Commit
19bbbb0
1 Parent(s): 9a9684f

initial commit

Browse files
Files changed (8) hide show
  1. angry1.png +0 -0
  2. angry2.jpg +0 -0
  3. app.py +41 -0
  4. happy1.jpg +0 -0
  5. happy2.jpg +0 -0
  6. neutral1.jpg +0 -0
  7. neutral2.jpg +0 -0
  8. requirements.txt +1 -0
angry1.png ADDED
angry2.jpg ADDED
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ return {**emotions, **sentiments}
26
+
27
+ # Gradio
28
+ title = "Facial Expression Sentiment Classifier"
29
+ description = "A model to detect emotion and sentiment from facial expressions trained on FER2013 dataset using FastAi. Created as a demo for AI Course."
30
+ article = 'Sample images are taken from VG & AftenPoften webpages. Copyrights belong to respective brands. All rights reserved.'
31
+ interpretation='default'
32
+ enable_queue=True
33
+
34
+ examples = ['happy1.jpg', 'happy2.jpg', 'angry1.jpg', 'angry2.jpg', 'neutral1.jpg', 'neutral2.jpg']
35
+
36
+ gr.Interface(fn = predict,
37
+ inputs = gr.Image(shape=(48, 48), image_mode='L'),
38
+ outputs = gr.Label(),
39
+ title = title,
40
+ description = description,
41
+ article=article).launch(share=True, enable_queue=enable_queue)
happy1.jpg ADDED
happy2.jpg ADDED
neutral1.jpg ADDED
neutral2.jpg ADDED
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ fastai