nthnil commited on
Commit
982b802
1 Parent(s): a19a84d

Upload 2 files

Browse files
Files changed (3) hide show
  1. .gitattributes +1 -0
  2. app.py +67 -0
  3. model_9.keras +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ model_9.keras filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import cv2
4
+ import PIL
5
+ from PIL import Image
6
+ from mtcnn import MTCNN
7
+ import numpy as np
8
+ from tensorflow.keras.models import load_model
9
+ from keras.preprocessing.image import img_to_array
10
+
11
+ emotions = ['neutral','happiness','surprise','sadness','anger','disgust','fear','contempt','unknown']
12
+ classifier = load_model("model_9.keras")
13
+ face_detector_mtcnn = MTCNN()
14
+
15
+
16
+ def predict_emotion(image):
17
+
18
+ faces = face_detector_mtcnn.detect_faces(image)
19
+
20
+ for face in faces:
21
+ x,y,w,h = face['box']
22
+
23
+ roi = image[y:y+h,x:x+w]
24
+
25
+ # Converting the region of interest to grayscale, and resize
26
+ roi_gray = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
27
+ roi_gray = cv2.resize(roi_gray,(48,48),interpolation=cv2.INTER_AREA)
28
+
29
+ img = roi_gray.astype('float')/255.0
30
+ img = img_to_array(img)
31
+ img = np.expand_dims(img,axis=0)
32
+
33
+ prediction = classifier.predict(img)[0]
34
+ #top_indices = np.argsort(prediction)[-2:]
35
+ #top_emotion = top_indices[1]
36
+ #second_emotion = top_indices[0]
37
+ #label = emotions[top_emotion]
38
+ confidences = {emotions[i]: float(prediction[i]) for i in range(len(emotions))}
39
+
40
+ return confidences
41
+
42
+
43
+
44
+ demo = gr.Interface(
45
+ fn = predict_emotion,
46
+ inputs = gr.Image(type="numpy"),
47
+ outputs = gr.Label(num_top_classes=9),
48
+ #flagging_options=["blurry", "incorrect", "other"],
49
+ examples = [
50
+ os.path.join(os.path.dirname(__file__), "images/Image_1.jpg"),
51
+ os.path.join(os.path.dirname(__file__), "images/Image_2.jpg"),
52
+ os.path.join(os.path.dirname(__file__), "images/Image_3.jpg"),
53
+ os.path.join(os.path.dirname(__file__), "images/Image_4.jpg"),
54
+ os.path.join(os.path.dirname(__file__), "images/Image_5.jpg"),
55
+ os.path.join(os.path.dirname(__file__), "images/Image_6.jpg"),
56
+ os.path.join(os.path.dirname(__file__), "images/Image_7.jpg"),
57
+ os.path.join(os.path.dirname(__file__), "images/Image_8.jpg"),
58
+ os.path.join(os.path.dirname(__file__), "images/Image_9.jpg"),
59
+ #os.path.join(os.path.dirname(__file__), "images/Image_10.jpg"),
60
+ ],
61
+ title = "Whatchu feeling?"
62
+ )
63
+
64
+
65
+
66
+ if __name__ == "__main__":
67
+ demo.launch()
model_9.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:805a2ce0814a8910a68a06bf54b0bb1579595307972b8f211c5dadf35c59cdad
3
+ size 16531714