amirgame197 commited on
Commit
7955acb
·
verified ·
1 Parent(s): be1eb30

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -2
app.py CHANGED
@@ -1,10 +1,33 @@
1
  import gradio as gr
2
  from nudenet import NudeDetector
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  def process(input_img):
5
  detector = NudeDetector(model_path="640m.onnx", inference_resolution=640)
6
- converted = detector.censor(input_img)
7
- return converted
 
 
 
 
 
 
 
8
 
9
  iface = gr.Interface(process, gr.components.Image(type='filepath'), gr.components.Image(type="filepath"))
10
 
 
1
  import gradio as gr
2
  from nudenet import NudeDetector
3
+ import cv2
4
+
5
+ def blur_image(image_path, detections, parts_to_blur):
6
+ image = cv2.imread(image_path)
7
+
8
+ for detection in detections:
9
+ label = detection['label']
10
+ if label in parts_to_blur:
11
+ x1, y1, x2, y2 = map(int, detection['box'])
12
+ roi = image[y1:y2, x1:x2]
13
+ roi = cv2.GaussianBlur(roi, (51, 51), 30)
14
+ image[y1:y2, x1:x2] = roi
15
+
16
+ blurred_image_path = 'blurred_' + image_path.split('/')[-1]
17
+ cv2.imwrite(blurred_image_path, image)
18
+ return blurred_image_path
19
 
20
  def process(input_img):
21
  detector = NudeDetector(model_path="640m.onnx", inference_resolution=640)
22
+ detections = detector.detect(input_img)
23
+ print(detections)
24
+ parts_to_blur = [
25
+ 'EXPOSED_GENITALIA_F', 'EXPOSED_GENITALIA_M',
26
+ 'EXPOSED_BREAST_F', 'EXPOSED_BUTTOCKS_F', 'EXPOSED_BUTTOCKS_M'
27
+ ]
28
+
29
+ blurred_image_path = blur_image(input_img, detections, parts_to_blur)
30
+ return blurred_image_path
31
 
32
  iface = gr.Interface(process, gr.components.Image(type='filepath'), gr.components.Image(type="filepath"))
33