23A475R commited on
Commit
ace4c32
1 Parent(s): 74c5764

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -58
app.py CHANGED
@@ -18,58 +18,6 @@ emotion_classifier = load_model(emotion_model_path, compile=False)
18
  EMOTIONS = ['neutral','happiness','surprise','sadness','anger','disgust','fear','contempt','unknown']
19
 
20
 
21
- # def predict(frame):
22
-
23
- # frame = imutils.resize(frame, width=300)
24
- # gray = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
25
- # faces = face_detection.detectMultiScale(gray, scaleFactor=1.1,
26
- # minNeighbors=5, minSize=(30, 30),
27
- # flags=cv2.CASCADE_SCALE_IMAGE)
28
-
29
- # frameClone = frame.copy()
30
- # if len(faces) > 0:
31
- # faces = sorted(faces, reverse=True,
32
- # key=lambda x: (x[2] - x[0]) * (x[3] - x[1]))[0]
33
- # (fX, fY, fW, fH) = faces
34
- # # Extract the ROI of the face from the grayscale image, resize it to a fixed 28x28 pixels, and then prepare
35
- # # the ROI for classification via the CNN
36
- # roi = gray[fY:fY + fH, fX:fX + fW]
37
- # roi = cv2.resize(roi, (48, 48))
38
- # roi = roi.astype("float") / 255.0
39
- # roi = img_to_array(roi)
40
- # roi = np.expand_dims(roi, axis=0)
41
-
42
- # preds = emotion_classifier.predict(roi)[0]
43
- # label = EMOTIONS[preds.argmax()]
44
- # else:
45
- # return frameClone, "Can't find your face"
46
-
47
- # probs = {}
48
- # cv2.putText(frameClone, label, (fX, fY - 10),
49
- # cv2.FONT_HERSHEY_DUPLEX, 1, (238, 164, 64), 1)
50
- # cv2.rectangle(frameClone, (fX, fY), (fX + fW, fY + fH),
51
- # (238, 164, 64), 2)
52
-
53
- # for (i, (emotion, prob)) in enumerate(zip(EMOTIONS, preds)):
54
- # probs[emotion] = float(prob)
55
-
56
- # return frameClone, probs
57
-
58
- # inp = gr.components.Image(sources="webcam", label="Your face")
59
- # out = [
60
- # gr.components.Image(label="Predicted Emotion"),
61
- # gr.components.Label(num_top_classes=2, label="Top 2 Probabilities")
62
- # ]
63
- # title = "Facial Emotion Recognition"
64
- # description = "How well can this model predict your emotions? Take a picture with your webcam, and it will guess if" \
65
- # " you are: happy, sad, angry, disgusted, scared, surprised, or neutral."
66
- # thumbnail = "https://raw.githubusercontent.com/gradio-app/hub-emotion-recognition/master/thumbnail.png"
67
-
68
- # # gr.Interface(predict, inp, out, capture_session=True, title=title, thumbnail=thumbnail,
69
- # # description=description).launch(inbrowser=True)
70
- # gr.Interface(fn=predict, inputs=inp, outputs=out, title=title, thumbnail=thumbnail).launch()
71
-
72
- ######################################################################################################################################################
73
  def predict(frame):
74
 
75
  frame = imutils.resize(frame, width=300)
@@ -107,17 +55,16 @@ def predict(frame):
107
 
108
  return frameClone, probs
109
 
110
- inp = gr.components.Video(sources="webcam", label="Your face")
111
  out = [
112
- gr.components.Video(label="Predicted Emotion"),
113
  gr.components.Label(num_top_classes=2, label="Top 2 Probabilities")
114
- ]
115
-
116
  title = "Facial Emotion Recognition"
117
  description = "How well can this model predict your emotions? Take a picture with your webcam, and it will guess if" \
118
  " you are: happy, sad, angry, disgusted, scared, surprised, or neutral."
119
  thumbnail = "https://raw.githubusercontent.com/gradio-app/hub-emotion-recognition/master/thumbnail.png"
120
 
 
 
121
  gr.Interface(fn=predict, inputs=inp, outputs=out, title=title, thumbnail=thumbnail).launch()
122
-
123
-
 
18
  EMOTIONS = ['neutral','happiness','surprise','sadness','anger','disgust','fear','contempt','unknown']
19
 
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  def predict(frame):
22
 
23
  frame = imutils.resize(frame, width=300)
 
55
 
56
  return frameClone, probs
57
 
58
+ inp = gr.components.Image(sources="webcam", label="Your face")
59
  out = [
60
+ gr.components.Image(label="Predicted Emotion"),
61
  gr.components.Label(num_top_classes=2, label="Top 2 Probabilities")
62
+ ]
 
63
  title = "Facial Emotion Recognition"
64
  description = "How well can this model predict your emotions? Take a picture with your webcam, and it will guess if" \
65
  " you are: happy, sad, angry, disgusted, scared, surprised, or neutral."
66
  thumbnail = "https://raw.githubusercontent.com/gradio-app/hub-emotion-recognition/master/thumbnail.png"
67
 
68
+ # gr.Interface(predict, inp, out, capture_session=True, title=title, thumbnail=thumbnail,
69
+ # description=description).launch(inbrowser=True)
70
  gr.Interface(fn=predict, inputs=inp, outputs=out, title=title, thumbnail=thumbnail).launch()