Re-enabled the NSFW function (turn-off by default).

@refer to the PR #237 in the `experimental` branch.

Signed-off-by: Vic P <vic4key@gmail.com>
This commit is contained in:
Vic P
2024-08-21 02:02:00 +07:00
parent e4b494174d
commit 7313a332c8
5 changed files with 46 additions and 26 deletions

View File

@@ -6,11 +6,13 @@ from modules.typing import Frame
MAX_PROBABILITY = 0.85
model = None
def predict_frame(target_frame: Frame) -> bool:
image = Image.fromarray(target_frame)
image = opennsfw2.preprocess_image(image, opennsfw2.Preprocessing.YAHOO)
model = opennsfw2.make_open_nsfw_model()
global model
if model is None: model = opennsfw2.make_open_nsfw_model()
views = numpy.expand_dims(image, axis=0)
_, probability = model.predict(views)[0]
return probability > MAX_PROBABILITY