Spaces:
Runtime error
Runtime error
File size: 4,176 Bytes
8637ba8 7955acb ed1578c 7955acb 10dc93a ed1578c 7955acb 4ae29be 7955acb b22fdc9 ed1578c b22fdc9 ed1578c 35e9698 41110fd ed1578c 7955acb 8637ba8 49f2df0 8637ba8 7955acb 49f2df0 4ae29be 49f2df0 7955acb ed1578c 7955acb 4e4209c 49f2df0 b74c088 8637ba8 f466ae1 ce7293a f466ae1 2dcbcb2 f466ae1 2dcbcb2 f466ae1 3a35046 49f2df0 94c0a2d 49f2df0 09e42b2 3a35046 f466ae1 01becdf 2455836 35e9698 2455836 01becdf 2dcbcb2 09e42b2 01becdf 2dcbcb2 01becdf ce7293a 3a35046 3ec0898 3a35046 49f2df0 3a35046 8dbe620 3a35046 01becdf f466ae1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | import gradio as gr
from nudenet import NudeDetector
import cv2
import numpy as np
def circular_blur(image_path, detections, parts_to_blur):
image = cv2.imread(image_path)
for detection in detections:
label = detection['class']
if label in parts_to_blur:
x, y, width, height = map(int, detection['box'])
center_x, center_y = x + width // 2, y + height // 2
radius = int(min(width, height) / 2)
mask = np.zeros_like(image)
cv2.circle(mask, (center_x, center_y), radius, (255, 255, 255), -1)
#blurred_image = cv2.GaussianBlur(image, (51, 51), 50)
blurred_image = cv2.GaussianBlur(image, (201, 201), 200)
image = np.where(mask == 255, blurred_image, image)
blurred_image_path = 'blurred_' + image_path.split('/')[-1]
cv2.imwrite(blurred_image_path, image)
return blurred_image_path
def process(input_img, parts2blur):
detector = NudeDetector(model_path="640m.onnx", inference_resolution=640)
detections = detector.detect(input_img)
print(detections)
if len(parts2blur) == 0:
parts_to_blur = [
'FEMALE_GENITALIA_EXPOSED', 'MALE_GENITALIA_EXPOSED',
'FEMALE_BREAST_EXPOSED', 'BUTTOCKS_EXPOSED',
'MALE_BREAST_EXPOSED', 'ANUS_EXPOSED'
]
else:
parts_to_blur = parts2blur
blurred_image_path = circular_blur(input_img, detections, parts_to_blur)
return blurred_image_path
title = "Nudity Detector Vincent version 2.1"
theme = "Nymbo/Alyx_Theme"
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
input_image = gr.components.Image(type='filepath')
with gr.Column():
output_image = gr.components.Image(type='filepath')
with gr.Row():
submit_btn = gr.Button("submit", scale=1)
with gr.Row():
parts2blur = gr.CheckboxGroup(['FEMALE_GENITALIA_EXPOSED', 'MALE_GENITALIA_EXPOSED',
'FEMALE_BREAST_EXPOSED', 'BUTTOCKS_EXPOSED',
'MALE_BREAST_EXPOSED', 'ANUS_EXPOSED'], label="parts", info="Parts to Blur")
gr.Examples(
examples=[
[
"magazine_sample1.jpeg",
#"yolov10x",
#640,
#0.25,
#0.45,
],
[
"magazine_sample2.jpeg",
#"yolov10m",
#640,
#0.25,
#0.45,
],
[
"demo_sample1.jpg",
#"yolov10m",
#640,
#0.25,
#0.45,
],
[
"demo_sample2.jpg",
#"yolov10m",
#640,
#0.25,
#0.45,
],
[
"demo_sample3.jpg",
#"yolov10m",
#640,
#0.25,
#0.45,
],
[
"demo_sample4.jpg",
#"yolov10m",
#640,
#0.25,
#0.45,
],
[
"003071982_0144.jpg",
#"yolov10m",
#640,
#0.25,
#0.45,
],
],
fn=process,
inputs=[
input_image,
parts2blur,
#model_id,
#image_size,
#conf_threshold,
#iou_threshold,
],
outputs=[output_image],
cache_examples="lazy",
)
submit_btn.click(
fn=process,
inputs=[input_image, parts2blur],
outputs=[
output_image,
],
queue=False,
)
demo.queue().launch(share=True) |