3v324v23 commited on
Commit
35626f1
·
1 Parent(s): 8d52736

refactor: update app.py to optimize facial expression inference pipeline performance

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -14,9 +14,13 @@ def detect_emotion(image):
14
  Hàm xử lý ảnh đầu vào, gọi model RMN và trả về ảnh đã vẽ bounding box.
15
  """
16
  if image is None:
17
- return None
18
 
19
- # Chuyển đổi từ PIL / Gradio RGB sang OpenCV BGR để tương thích với RMN
 
 
 
 
20
  image_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
21
 
22
  # Dự đoán cảm xúc
 
14
  Hàm xử lý ảnh đầu vào, gọi model RMN và trả về ảnh đã vẽ bounding box.
15
  """
16
  if image is None:
17
+ return None, "Please upload an image first."
18
 
19
+ # Xử kênh màu: ảnh từ webcam thường 4 kênh (RGBA), cần chuyển về 3 kênh (RGB)
20
+ if len(image.shape) == 3 and image.shape[2] == 4:
21
+ image = image[:, :, :3]
22
+
23
+ # Chuyển đổi từ RGB sang OpenCV BGR để tương thích với RMN
24
  image_bgr = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
25
 
26
  # Dự đoán cảm xúc