sandygmaharaj commited on
Commit
9f7e9cc
·
1 Parent(s): 21764e5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -14,18 +14,19 @@ mtcnn = MTCNN(margin=40, keep_all=True, post_process=False, device=device)
14
  learn = load_learner('export.pkl')
15
 
16
  labels = learn.dls.vocab
17
-
18
  emotions = {"x": [], "y": [], "State": []}
19
 
20
  def predict(img):
21
  img = PILImage.create(img)
22
  boxes, _ = mtcnn.detect(img)
23
  o_img = img.copy()
24
- draw = ImageDraw.Draw(o_img)
 
25
  for box in boxes:
26
  coords = tuple(box.tolist())
27
  pred,pred_idx,probs = learn.predict(img.crop(coords))
28
- draw.rectangle(coords, outline=(0, 0, 0), width=1)
29
  draw.text((coords[0]-10, coords[1]-10), pred, font=ImageFont.truetype("arial.ttf"))
30
  return o_img
31
  '''
 
14
  learn = load_learner('export.pkl')
15
 
16
  labels = learn.dls.vocab
17
+ e_colors = {'confused':'orange', 'attentive':'green','bored':'red','interested':'blue','frustrated':'purple','thoughtful':'pink'}
18
  emotions = {"x": [], "y": [], "State": []}
19
 
20
  def predict(img):
21
  img = PILImage.create(img)
22
  boxes, _ = mtcnn.detect(img)
23
  o_img = img.copy()
24
+ #draw = ImageDraw.Draw(o_img)
25
+ draw = Image.new("RGBA", img.size, color = "white")
26
  for box in boxes:
27
  coords = tuple(box.tolist())
28
  pred,pred_idx,probs = learn.predict(img.crop(coords))
29
+ draw.rectangle(coords, fill=e_colors[pred], outline=(0, 0, 0), width=1)
30
  draw.text((coords[0]-10, coords[1]-10), pred, font=ImageFont.truetype("arial.ttf"))
31
  return o_img
32
  '''