Giddycrypt commited on
Commit
251fe98
·
verified ·
1 Parent(s): 51ee15b

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -81,7 +81,6 @@ def health_check():
81
 
82
  @app.post("/predict")
83
  async def predict_age_gender(file: UploadFile = File(...)):
84
- tmp_path = None
85
  try:
86
  # Read and decode image
87
  contents = await file.read()
@@ -91,6 +90,15 @@ async def predict_age_gender(file: UploadFile = File(...)):
91
  if img is None:
92
  raise HTTPException(status_code=400, detail="Invalid or unreadable image file.")
93
 
 
 
 
 
 
 
 
 
 
94
  # Run MiVOLO prediction directly on the numpy image array
95
  pred = get_predictor()
96
  detected_objects, _ = pred.recognize(img)
@@ -124,8 +132,3 @@ async def predict_age_gender(file: UploadFile = File(...)):
124
  except Exception as e:
125
  logger.error(f"Prediction error: {str(e)}")
126
  raise HTTPException(status_code=500, detail=str(e))
127
-
128
- finally:
129
- # Always clean up temp file
130
- if tmp_path and os.path.exists(tmp_path):
131
- os.remove(tmp_path)
 
81
 
82
  @app.post("/predict")
83
  async def predict_age_gender(file: UploadFile = File(...)):
 
84
  try:
85
  # Read and decode image
86
  contents = await file.read()
 
90
  if img is None:
91
  raise HTTPException(status_code=400, detail="Invalid or unreadable image file.")
92
 
93
+ # Apply CLAHE (Contrast Limited Adaptive Histogram Equalization)
94
+ # This dramatically improves face visibility in bad webcam lighting
95
+ lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
96
+ l_channel, a_channel, b_channel = cv2.split(lab)
97
+ clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
98
+ cl = clahe.apply(l_channel)
99
+ limg = cv2.merge((cl, a_channel, b_channel))
100
+ img = cv2.cvtColor(limg, cv2.COLOR_LAB2BGR)
101
+
102
  # Run MiVOLO prediction directly on the numpy image array
103
  pred = get_predictor()
104
  detected_objects, _ = pred.recognize(img)
 
132
  except Exception as e:
133
  logger.error(f"Prediction error: {str(e)}")
134
  raise HTTPException(status_code=500, detail=str(e))