Files changed (1) hide show
  1. app/main.py +1 -6
app/main.py CHANGED
@@ -1,6 +1,6 @@
1
  # app/main.py
2
  import os
3
- os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2" # quiet TF/MediaPipe logs
4
  from absl import logging as absl_logging
5
  absl_logging.set_verbosity(absl_logging.ERROR)
6
 
@@ -136,10 +136,8 @@ def blur_faces_oval(img_bgr: np.ndarray, boxes):
136
  rh, rw = roi.shape[:2]
137
 
138
  k_base = int(KERNEL_FRAC * max(w, h))
139
- # clamp to ROI and ensure odd
140
  k = odd(max(MIN_KERNEL, min(MAX_KERNEL, k_base, rh - (rh % 2 == 0), rw - (rw % 2 == 0))))
141
  if k < 9:
142
- # fallback to pixelation if ROI too small
143
  small = cv2.resize(roi, (max(1, rw // 10), max(1, rh // 10)), interpolation=cv2.INTER_LINEAR)
144
  roi_blur = cv2.resize(small, (rw, rh), interpolation=cv2.INTER_NEAREST)
145
  else:
@@ -177,13 +175,11 @@ async def upload_image(request: Request, file: UploadFile = File(...)):
177
  "request": request, "error": "Could not decode image.", "result": None
178
  })
179
 
180
- # Optional downscale for very large images
181
  H, W = img.shape[:2]
182
  scale = min(1.0, float(MAX_SIDE) / max(H, W))
183
  if scale < 1.0:
184
  img = cv2.resize(img, (int(W * scale), int(H * scale)), interpolation=cv2.INTER_AREA)
185
 
186
- # Detection pipeline
187
  img_proc = gentle_contrast_boost(img)
188
  boxes = detect_faces_mediapipe(img_proc)
189
  faces_count = len(boxes)
@@ -191,7 +187,6 @@ async def upload_image(request: Request, file: UploadFile = File(...)):
191
  preview = draw_unblurred_preview(img_proc, boxes)
192
  blurred = blur_faces_oval(img_proc, boxes)
193
 
194
- # Save to /tmp and serve via /results
195
  uid = uuid.uuid4().hex
196
  annot_name = f"{uid}_annot.jpg"
197
  blur_name = f"{uid}_blur.jpg"
 
1
  # app/main.py
2
  import os
3
+ os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
4
  from absl import logging as absl_logging
5
  absl_logging.set_verbosity(absl_logging.ERROR)
6
 
 
136
  rh, rw = roi.shape[:2]
137
 
138
  k_base = int(KERNEL_FRAC * max(w, h))
 
139
  k = odd(max(MIN_KERNEL, min(MAX_KERNEL, k_base, rh - (rh % 2 == 0), rw - (rw % 2 == 0))))
140
  if k < 9:
 
141
  small = cv2.resize(roi, (max(1, rw // 10), max(1, rh // 10)), interpolation=cv2.INTER_LINEAR)
142
  roi_blur = cv2.resize(small, (rw, rh), interpolation=cv2.INTER_NEAREST)
143
  else:
 
175
  "request": request, "error": "Could not decode image.", "result": None
176
  })
177
 
 
178
  H, W = img.shape[:2]
179
  scale = min(1.0, float(MAX_SIDE) / max(H, W))
180
  if scale < 1.0:
181
  img = cv2.resize(img, (int(W * scale), int(H * scale)), interpolation=cv2.INTER_AREA)
182
 
 
183
  img_proc = gentle_contrast_boost(img)
184
  boxes = detect_faces_mediapipe(img_proc)
185
  faces_count = len(boxes)
 
187
  preview = draw_unblurred_preview(img_proc, boxes)
188
  blurred = blur_faces_oval(img_proc, boxes)
189
 
 
190
  uid = uuid.uuid4().hex
191
  annot_name = f"{uid}_annot.jpg"
192
  blur_name = f"{uid}_blur.jpg"