intuitive262 commited on
Commit
b189dad
·
1 Parent(s): c28eeae

Updated app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -5
app.py CHANGED
@@ -66,15 +66,21 @@ def process_image(image, operation_name, age_filters=[], gender_filters=[], sele
66
  # Create a temporary copy for drawing face boxes
67
  image_with_boxes = image_cv.copy()
68
 
 
69
  # Draw boxes around all detected faces with indices
70
  for i, pred in enumerate(predictions):
71
  box = np.array(pred['box'])
72
  x1, y1, x2, y2 = box.astype(int)
73
  # Draw box
74
- cv2.rectangle(image_with_boxes, (x1, y1), (x2, y2), (0, 255, 0), 2)
 
 
 
 
 
75
  # Draw index
76
- cv2.putText(image_with_boxes, f"#{i}: {pred['gender']}, {pred['age']}",
77
- (x1, y1-10), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2)
78
 
79
  # Convert to RGB for display
80
  image_with_boxes_rgb = cv2.cvtColor(image_with_boxes, cv2.COLOR_BGR2RGB)
@@ -122,7 +128,7 @@ def process_image(image, operation_name, age_filters=[], gender_filters=[], sele
122
  "selected_faces": [int(idx.strip()) for idx in selected_face_indices.split(",") if idx.strip().isdigit()] if selected_face_indices else []
123
  }
124
 
125
- return [image_with_boxes_rgb, processed_image_rgb, json.dumps(results_data, indent=2)]
126
 
127
  def process_video(video_path, operation_name, age_filters=[], gender_filters=[], progress=gr.Progress()):
128
  """Process a video with face blurring"""
@@ -256,11 +262,21 @@ with gr.Blocks(title="Face Privacy Protection Tool") as demo:
256
 
257
  with gr.TabItem("JSON Results"):
258
  json_output = gr.JSON(label="Detection Results")
 
 
 
 
 
 
 
 
 
 
259
 
260
  image_button.click(
261
  process_image,
262
  inputs=[image_input, operation_dropdown, age_filter, gender_filter, selected_faces],
263
- outputs=[image_with_boxes, image_output, json_output]
264
  )
265
 
266
  with gr.TabItem("Video Processing"):
 
66
  # Create a temporary copy for drawing face boxes
67
  image_with_boxes = image_cv.copy()
68
 
69
+ face_thumbnails = []
70
  # Draw boxes around all detected faces with indices
71
  for i, pred in enumerate(predictions):
72
  box = np.array(pred['box'])
73
  x1, y1, x2, y2 = box.astype(int)
74
  # Draw box
75
+ cv2.rectangle(image_with_boxes, (x1, y1), (x2, y2), (0, 255, 0), 1)
76
+ face_img = image_cv[y1:y2, x1:x2]
77
+ face_rgb = cv2.cvtColor(face_img, cv2.COLOR_BGR2RGB)
78
+
79
+ caption = f"Face #{i} | {pred['gender']} | {pred['age']}"
80
+ face_thumbnails.append({"face": face_rgb, "caption": caption})
81
  # Draw index
82
+ # cv2.putText(image_with_boxes, f"#{i}: {pred['gender']}, {pred['age']}",
83
+ # (x1, y1-10), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2)
84
 
85
  # Convert to RGB for display
86
  image_with_boxes_rgb = cv2.cvtColor(image_with_boxes, cv2.COLOR_BGR2RGB)
 
128
  "selected_faces": [int(idx.strip()) for idx in selected_face_indices.split(",") if idx.strip().isdigit()] if selected_face_indices else []
129
  }
130
 
131
+ return [image_with_boxes_rgb, processed_image_rgb, json.dumps(results_data, indent=2), face_thumbnails]
132
 
133
  def process_video(video_path, operation_name, age_filters=[], gender_filters=[], progress=gr.Progress()):
134
  """Process a video with face blurring"""
 
262
 
263
  with gr.TabItem("JSON Results"):
264
  json_output = gr.JSON(label="Detection Results")
265
+
266
+ with gr.TabItem("Detected Faces (Metadata)"):
267
+ face_gallery = gr.Gallery(
268
+ label="Detected Faces",
269
+ show_label=True,
270
+ columns=4,
271
+ height="auto",
272
+ object_fit="contain"
273
+ )
274
+
275
 
276
  image_button.click(
277
  process_image,
278
  inputs=[image_input, operation_dropdown, age_filter, gender_filter, selected_faces],
279
+ outputs=[image_with_boxes, image_output, json_output, face_gallery]
280
  )
281
 
282
  with gr.TabItem("Video Processing"):