Skip to content

Commit

Permalink
dev(narugo): fix errors on operate
Browse files Browse the repository at this point in the history
  • Loading branch information
narugo1992 committed Sep 17, 2024
1 parent e239573 commit 10514ed
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions imgutils/operate/censor_.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
A tool for obscuring specified regions on an image.
"""
from functools import lru_cache
from typing import Tuple, Type, List
from typing import Tuple, Type, List, Optional

from PIL import Image, ImageFilter

Expand Down Expand Up @@ -317,7 +317,7 @@ def censor_areas(image: ImageTyping, method: str,


def censor_nsfw(image: ImageTyping, method: str, nipple_f: bool = False, penis: bool = True, pussy: bool = True,
level: str = 's', version: str = 'v1.0', max_infer_size=640,
level: str = 's', version: str = 'v1.0', model_name: Optional[str] = None,
conf_threshold: float = 0.3, iou_threshold: float = 0.7, **kwargs):
"""
Applies censoring to sensitive areas in NSFW images based on object detection.
Expand Down Expand Up @@ -346,8 +346,9 @@ def censor_nsfw(image: ImageTyping, method: str, nipple_f: bool = False, penis:
:param version: The version of the NSFW object detection model. Default is ``v1.0``.
:type version: str
:param max_infer_size: The maximum size for inference. Default is ``640``.
:type max_infer_size: int
:param model_name: Optional custom model name. If not provided, it will be constructed
from the version and level.
:type model_name: Optional[str]
:param conf_threshold: The confidence threshold for object detection. Default is ``0.3``.
:type conf_threshold: float
Expand Down Expand Up @@ -382,7 +383,14 @@ def censor_nsfw(image: ImageTyping, method: str, nipple_f: bool = False, penis:
"""
image = load_image(image, mode='RGB')
areas = detect_censors(image, level, version, max_infer_size, conf_threshold, iou_threshold)
areas = detect_censors(
image=image,
level=level,
version=version,
model_name=model_name,
conf_threshold=conf_threshold,
iou_threshold=iou_threshold,
)

c_areas = []
for area, label, score in areas:
Expand Down

0 comments on commit 10514ed

Please sign in to comment.