sandygmaharaj commited on
Commit
e7f36bd
·
1 Parent(s): 63233a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -1,13 +1,20 @@
1
  import gradio as gr
2
  from fastai.vision.all import *
3
  import skimage
 
 
 
 
 
 
4
 
5
  learn = load_learner('export.pkl')
6
 
7
  labels = learn.dls.vocab
8
  def predict(img):
9
  img = PILImage.create(img)
10
- pred,pred_idx,probs = learn.predict(img)
 
11
  return {labels[i]: float(probs[i]) for i in range(len(labels))}
12
 
13
  title = "Students emotion classifer"
 
1
  import gradio as gr
2
  from fastai.vision.all import *
3
  import skimage
4
+ from facenet_pytorch import MTCNN
5
+ import torch
6
+ device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
7
+ print('Running on device: {}'.format(device))
8
+
9
+ mtcnn = MTCNN(keep_all=True, device=device)
10
 
11
  learn = load_learner('export.pkl')
12
 
13
  labels = learn.dls.vocab
14
  def predict(img):
15
  img = PILImage.create(img)
16
+ boxes, _ = mtcnn.detect(img)
17
+ pred,pred_idx,probs = learn.predict(img.crop(tuple(boxes[0].tolist())))
18
  return {labels[i]: float(probs[i]) for i in range(len(labels))}
19
 
20
  title = "Students emotion classifer"