Skip to content

Commit

Permalink
remove NSFW filter and its dependency; if you still want it, find it …
Browse files Browse the repository at this point in the history
…in the extensions section
  • Loading branch information
AUTOMATIC1111 committed Dec 10, 2022
1 parent d065922 commit 991e2dc
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 49 deletions.
7 changes: 3 additions & 4 deletions modules/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from typing import Any, Dict, List, Optional

import modules.sd_hijack
from modules import devices, prompt_parser, masking, sd_samplers, lowvram, generation_parameters_copypaste
from modules import devices, prompt_parser, masking, sd_samplers, lowvram, generation_parameters_copypaste, script_callbacks
from modules.sd_hijack import model_hijack
from modules.shared import opts, cmd_opts, state
import modules.shared as shared
Expand Down Expand Up @@ -571,9 +571,8 @@ def infotext(iteration=0, position_in_batch=0):

devices.torch_gc()

if opts.filter_nsfw:
import modules.safety as safety
x_samples_ddim = modules.safety.censor_batch(x_samples_ddim)
if p.scripts is not None:
p.scripts.postprocess_batch(p, x_samples_ddim, batch_number=n)

for i, x_sample in enumerate(x_samples_ddim):
x_sample = 255. * np.moveaxis(x_sample.cpu().numpy(), 0, 2)
Expand Down
42 changes: 0 additions & 42 deletions modules/safety.py

This file was deleted.

20 changes: 20 additions & 0 deletions modules/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ def process_batch(self, p, *args, **kwargs):

pass

def postprocess_batch(self, p, *args, **kwargs):
"""
Same as process_batch(), but called for every batch after it has been generated.
**kwargs will have same items as process_batch, and also:
- batch_number - index of current batch, from 0 to number of batches-1
- images - torch tensor with all generated images, with values ranging from 0 to 1;
"""

pass

def postprocess(self, p, processed, *args):
"""
This function is called after processing ends for AlwaysVisible scripts.
Expand Down Expand Up @@ -347,6 +358,15 @@ def postprocess(self, p, processed):
print(f"Error running postprocess: {script.filename}", file=sys.stderr)
print(traceback.format_exc(), file=sys.stderr)

def postprocess_batch(self, p, images, **kwargs):
for script in self.alwayson_scripts:
try:
script_args = p.script_args[script.args_from:script.args_to]
script.postprocess_batch(p, *script_args, images=images, **kwargs)
except Exception:
print(f"Error running postprocess_batch: {script.filename}", file=sys.stderr)
print(traceback.format_exc(), file=sys.stderr)

def before_component(self, component, **kwargs):
for script in self.scripts:
try:
Expand Down
1 change: 0 additions & 1 deletion modules/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ def list_samplers():
"use_old_emphasis_implementation": OptionInfo(False, "Use old emphasis implementation. Can be useful to reproduce old seeds."),
"enable_batch_seeds": OptionInfo(True, "Make K-diffusion samplers produce same images in a batch as when making a single image"),
"comma_padding_backtrack": OptionInfo(20, "Increase coherency by padding from the last comma within n tokens when using more than 75 tokens", gr.Slider, {"minimum": 0, "maximum": 74, "step": 1 }),
"filter_nsfw": OptionInfo(False, "Filter NSFW content"),
'CLIP_stop_at_last_layers': OptionInfo(1, "Clip skip", gr.Slider, {"minimum": 1, "maximum": 12, "step": 1}),
"random_artist_categories": OptionInfo([], "Allowed categories for random artists selection when using the Roll button", gr.CheckboxGroup, {"choices": artist_db.categories()}),
}))
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
accelerate
basicsr
diffusers
fairscale==0.4.4
fonts
font-roboto
Expand Down
1 change: 0 additions & 1 deletion requirements_versions.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
transformers==4.19.2
diffusers==0.3.0
accelerate==0.12.0
basicsr==1.4.2
gfpgan==1.3.8
Expand Down

0 comments on commit 991e2dc

Please sign in to comment.