gurwindersingh commited on
Commit
2678eae
·
1 Parent(s): f3bacbe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -7
app.py CHANGED
@@ -29,6 +29,16 @@ for cls in myList:
29
  st.write(classnames)
30
 
31
 
 
 
 
 
 
 
 
 
 
 
32
  def findEncodings(Images):
33
  encodeList = []
34
  for img in Images:
@@ -37,6 +47,12 @@ def findEncodings(Images):
37
  encodeList.append(encode)
38
  return encodeList
39
 
 
 
 
 
 
 
40
 
41
  encodeListknown = findEncodings(Images)
42
  st.write('Encoding Complete')
@@ -69,12 +85,29 @@ if img_file_buffer is not None:
69
  cv2.rectangle(image,(x1,y1),(x2,y2),(0,255,0),2)
70
  cv2.rectangle(image,(x1,y2-35),(x2,y2),(0,255,0),cv2.FILLED)
71
  cv2.putText(image,name,(x1+6,y2-6),cv2.FONT_HERSHEY_COMPLEX,1,(255, 255, 255),2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
- ##############
74
- url = "https://kiwi-whispering-plier.glitch.me/update"
75
 
76
- data = {
77
- 'name': name,
78
- }
79
- else:
80
- st.write("Please smile")
 
29
  st.write(classnames)
30
 
31
 
32
+ json_file = open("facialemotionmodel.json", "r")
33
+ model_json = json_file.read()
34
+ json_file.close()
35
+ model = model_from_json(model_json)
36
+
37
+ model.load_weights("facialemotionmodel.h5")
38
+ haar_file=cv2.data.haarcascades + 'haarcascade_frontalface_default.xml'
39
+ face_cascade=cv2.CascadeClassifier(haar_file)
40
+
41
+
42
  def findEncodings(Images):
43
  encodeList = []
44
  for img in Images:
 
47
  encodeList.append(encode)
48
  return encodeList
49
 
50
+ def extract_features(image):
51
+ feature = np.array(image)
52
+ feature = feature.reshape(1,48,48,1)
53
+ return feature/255.0
54
+
55
+ labels = {0 : 'angry', 1 : 'disgust', 2 : 'fear', 3 : 'happy', 4 : 'neutral', 5 : 'sad', 6 : 'surprise'}
56
 
57
  encodeListknown = findEncodings(Images)
58
  st.write('Encoding Complete')
 
85
  cv2.rectangle(image,(x1,y1),(x2,y2),(0,255,0),2)
86
  cv2.rectangle(image,(x1,y2-35),(x2,y2),(0,255,0),cv2.FILLED)
87
  cv2.putText(image,name,(x1+6,y2-6),cv2.FONT_HERSHEY_COMPLEX,1,(255, 255, 255),2)
88
+
89
+ faces=face_cascade.detectMultiScale(image,1.3,5)
90
+ st.write("close")
91
+ try:
92
+ for (p,q,r,s) in faces:
93
+
94
+ cv2.rectangle(im,(p,q),(p+r,q+s),(255,0,0),2)
95
+ image = cv2.resize(image,(48,48))
96
+ img = extract_features(image)
97
+ pred = model.predict(img)
98
+ prediction_label = labels[pred.argmax()]
99
+ # print("Predicted Output:", prediction_label)
100
+ # cv2.putText(im,prediction_label)
101
+ cv2.putText(image, '% s' %(prediction_label), (p-10, q-10),cv2.FONT_HERSHEY_COMPLEX_SMALL,2, (0,0,255))
102
+ st.write("success")
103
+
104
+
105
 
106
+ # ##############
107
+ # url = "https://kiwi-whispering-plier.glitch.me/update"
108
 
109
+ # data = {
110
+ # 'name': name,
111
+ # }
112
+ # else:
113
+ # st.write("Please smile")