Skip to content

I made a version where user CHOOSE if replace NSFW & add watermark #354

@Mapleshade20

Description

@Mapleshade20

The choice remains to the people who use it. Therefore, I add two bool options in the first two lines of text2img.py, through which you can disable the safety checker or the invisible watermark adder. Decide it by yourself :D
Line 1:

replace_nsfw = False    #editable
add_invisi_watermark = False    #editable

Line 97:

def check_safety(x_image):
    if replace_nsfw:
        safety_checker_input = safety_feature_extractor(numpy_to_pil(x_image), return_tensors="pt")
        x_checked_image, has_nsfw_concept = safety_checker(images=x_image, clip_input=safety_checker_input.pixel_values)
        assert x_checked_image.shape[0] == len(has_nsfw_concept)
        for i in range(len(has_nsfw_concept)):
            if has_nsfw_concept[i]:
               x_checked_image[i] = load_replacement(x_checked_image[i])
    else:
        x_checked_image, has_nsfw_concept = x_image, None
    return x_checked_image, has_nsfw_concept

Line 330 & 347:

                                if add_invisi_watermark:
                                    img = put_watermark(img, wm_encoder)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions