skibi11 commited on
Commit
5788deb
·
verified ·
1 Parent(s): 1d4fbb5

error handling if two eyes not detected

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -108,9 +108,13 @@ async def full_detection_pipeline(image: UploadFile = File(...)):
108
 
109
  eye_crops, error_msg = detect_eyes_roboflow(temp_image_path, raw_image)
110
  if error_msg or len(eye_crops) != 2:
111
- return JSONResponse(status_code=200, content={"warnings": ["Exactly two eyes not detected."]})
112
-
113
- eye_crops.sort(key=lambda c: cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY))[0])
 
 
 
 
114
 
115
  # Prepare to store all our results
116
  flags = {}
 
108
 
109
  eye_crops, error_msg = detect_eyes_roboflow(temp_image_path, raw_image)
110
  if error_msg or len(eye_crops) != 2:
111
+ # This change returns a proper error that your frontend can catch.
112
+ return JSONResponse(
113
+ status_code=400,
114
+ content={"error": "Could not detect exactly two eyes. Please try another photo."}
115
+ )
116
+
117
+ eye_crops.sort(key=lambda c: cv2.boundingRect(cv2.cvtColor(c, cv2.COLOR_BGR2GRAY))[0])
118
 
119
  # Prepare to store all our results
120
  flags = {}