maxinethegreat commited on
Commit
0038cec
·
1 Parent(s): 7888f1d

try to reduce lag

Browse files
Files changed (1) hide show
  1. app.py +12 -14
app.py CHANGED
@@ -3,7 +3,6 @@ import gradio as gr
3
  import tensorflow as tf
4
  import cv2
5
  import numpy as np
6
- import time
7
 
8
 
9
  # Load the saved model
@@ -16,19 +15,18 @@ emotions = ['Angry', 'Disgust', 'Fear', 'Happy', 'Sad', 'Surprise', 'Neutral']
16
  # Define the predict_emotion function
17
  def predict_emotion(frame):
18
  gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
19
- time.sleep(.01)
20
- # faces = face_cascade.detectMultiScale(gray, 1.3, 5)
21
- # for (x, y, w, h) in faces:
22
- # face = gray[y:y+h, x:x+w]
23
- # face = cv2.resize(face, (48, 48))
24
- # face = np.expand_dims(face, axis=-1)
25
- # face = np.expand_dims(face, axis=0)
26
- # prediction = model.predict(face)
27
- # emotion = emotions[np.argmax(prediction)]
28
- # cv2.putText(frame, emotion, (x, y-10), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
29
- # cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
30
-
31
- return gray
32
 
33
  # Start the video capture and emotion detection
34
  # cap = cv2.VideoCapture(0)
 
3
  import tensorflow as tf
4
  import cv2
5
  import numpy as np
 
6
 
7
 
8
  # Load the saved model
 
15
  # Define the predict_emotion function
16
  def predict_emotion(frame):
17
  gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
18
+ faces = face_cascade.detectMultiScale(gray, 1.3, 5)
19
+ for (x, y, w, h) in faces:
20
+ face = gray[y:y+h, x:x+w]
21
+ face = cv2.resize(face, (48, 48))
22
+ face = np.expand_dims(face, axis=-1)
23
+ face = np.expand_dims(face, axis=0)
24
+ prediction = model.predict(face)
25
+ emotion = emotions[np.argmax(prediction)]
26
+ cv2.putText(frame, emotion, (x, y-10), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
27
+ cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 0, 0), 2)
28
+
29
+ return frame
 
30
 
31
  # Start the video capture and emotion detection
32
  # cap = cv2.VideoCapture(0)