Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,22 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from nudenet import NudeDetector
|
| 3 |
import cv2
|
|
|
|
| 4 |
|
| 5 |
-
def
|
| 6 |
image = cv2.imread(image_path)
|
| 7 |
|
| 8 |
for detection in detections:
|
| 9 |
label = detection['class']
|
| 10 |
if label in parts_to_blur:
|
| 11 |
x, y, width, height = map(int, detection['box'])
|
| 12 |
-
|
| 13 |
-
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
print(f"Blurring region: {x1, y1, x2, y2} for label: {label}")
|
| 21 |
-
roi = image[y1:y2, x1:x2]
|
| 22 |
-
|
| 23 |
-
if roi.size == 0:
|
| 24 |
-
print(f"Skipping empty ROI for detection: {detection}")
|
| 25 |
-
continue
|
| 26 |
-
|
| 27 |
-
roi = cv2.GaussianBlur(roi, (51, 51), 30)
|
| 28 |
-
image[y1:y2, x1:x2] = roi
|
| 29 |
|
| 30 |
blurred_image_path = 'blurred_' + image_path.split('/')[-1]
|
| 31 |
cv2.imwrite(blurred_image_path, image)
|
|
@@ -41,7 +32,7 @@ def process(input_img):
|
|
| 41 |
'MALE_BREAST_EXPOSED', 'ANUS_EXPOSED'
|
| 42 |
]
|
| 43 |
|
| 44 |
-
blurred_image_path =
|
| 45 |
return blurred_image_path
|
| 46 |
|
| 47 |
iface = gr.Interface(process, gr.components.Image(type='filepath'), gr.components.Image(type="filepath"))
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from nudenet import NudeDetector
|
| 3 |
import cv2
|
| 4 |
+
import numpy as np
|
| 5 |
|
| 6 |
+
def circular_blur(image_path, detections, parts_to_blur):
|
| 7 |
image = cv2.imread(image_path)
|
| 8 |
|
| 9 |
for detection in detections:
|
| 10 |
label = detection['class']
|
| 11 |
if label in parts_to_blur:
|
| 12 |
x, y, width, height = map(int, detection['box'])
|
| 13 |
+
center_x, center_y = x + width // 2, y + height // 2
|
| 14 |
+
radius = int(min(width, height) / 2)
|
| 15 |
|
| 16 |
+
mask = np.zeros_like(image)
|
| 17 |
+
cv2.circle(mask, (center_x, center_y), radius, (255, 255, 255), -1)
|
| 18 |
+
blurred_image = cv2.GaussianBlur(image, (51, 51), 30)
|
| 19 |
+
image = np.where(mask == 255, blurred_image, image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
blurred_image_path = 'blurred_' + image_path.split('/')[-1]
|
| 22 |
cv2.imwrite(blurred_image_path, image)
|
|
|
|
| 32 |
'MALE_BREAST_EXPOSED', 'ANUS_EXPOSED'
|
| 33 |
]
|
| 34 |
|
| 35 |
+
blurred_image_path = circular_blur(input_img, detections, parts_to_blur)
|
| 36 |
return blurred_image_path
|
| 37 |
|
| 38 |
iface = gr.Interface(process, gr.components.Image(type='filepath'), gr.components.Image(type="filepath"))
|