UPD: Processing state

This commit is contained in:
Евгений Гурьев | Eugene Gourieff | 古仁
2025-01-18 13:31:35 +07:00
parent c20f3a3aff
commit 260d8ebbba
2 changed files with 13 additions and 6 deletions
+9 -2
View File
@@ -361,11 +361,18 @@ class reactor:
pil_images = batch_tensor_to_pil(input_image)
# NSFW checker
logger.status("Checking for any unsafe content")
pil_images_sfw = []
tmp_img = "reactor_tmp.png"
for img in pil_images:
img.save("tmp.png")
if not sfw.nsfw_image("tmp.png",NSFWDET_MODEL_PATH):
if state.interrupted or model_management.processing_interrupted():
logger.status("Interrupted by User")
break
img.save(tmp_img)
if not sfw.nsfw_image(tmp_img, NSFWDET_MODEL_PATH):
pil_images_sfw.append(img)
if os.path.exists(tmp_img):
os.remove(tmp_img)
pil_images = pil_images_sfw
# # #
+4 -4
View File
@@ -7,7 +7,7 @@ SCORE = 0.85
logging.getLogger('transformers').setLevel(logging.ERROR)
def nsfw_image(img_path: str, model_path: str):
img = Image.open(img_path)
predict = pipeline("image-classification", model=model_path)
result = predict(img)
return True if result[0]["score"] > SCORE else False
with Image.open(img_path) as img:
predict = pipeline("image-classification", model=model_path)
result = predict(img)
return True if result[0]["score"] > SCORE else False