Spaces:
Sleeping
Sleeping
remove nsfw checker
Browse files
app.py
CHANGED
|
@@ -186,15 +186,15 @@ def load_models(model_path, enable_compile=False, attention_backend="native"):
|
|
| 186 |
|
| 187 |
pipe.to("cuda", torch.bfloat16)
|
| 188 |
|
| 189 |
-
from diffusers.pipelines.stable_diffusion import StableDiffusionSafetyChecker
|
| 190 |
-
from transformers import CLIPImageProcessor
|
| 191 |
|
| 192 |
-
safety_model_id = "CompVis/stable-diffusion-safety-checker"
|
| 193 |
-
safety_feature_extractor = CLIPImageProcessor.from_pretrained(safety_model_id)
|
| 194 |
-
safety_checker = StableDiffusionSafetyChecker.from_pretrained(safety_model_id, torch_dtype=torch.float16).to("cuda")
|
| 195 |
|
| 196 |
-
pipe.safety_feature_extractor = safety_feature_extractor
|
| 197 |
-
pipe.safety_checker = safety_checker
|
| 198 |
return pipe
|
| 199 |
|
| 200 |
|
|
@@ -439,15 +439,15 @@ def generate(
|
|
| 439 |
if pipe is None:
|
| 440 |
raise gr.Error("Model not loaded.")
|
| 441 |
|
| 442 |
-
has_unsafe_concept = is_unsafe_prompt(
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
)
|
| 449 |
-
if has_unsafe_concept:
|
| 450 |
-
|
| 451 |
|
| 452 |
final_prompt = prompt
|
| 453 |
|
|
@@ -470,10 +470,10 @@ def generate(
|
|
| 470 |
shift=shift,
|
| 471 |
)
|
| 472 |
|
| 473 |
-
safety_checker_input = pipe.safety_feature_extractor([image], return_tensors="pt").pixel_values.cuda()
|
| 474 |
-
_, has_nsfw_concept = pipe.safety_checker(images=[torch.zeros(1)], clip_input=safety_checker_input)
|
| 475 |
-
has_nsfw_concept = has_nsfw_concept[0]
|
| 476 |
-
if has_nsfw_concept:
|
| 477 |
raise UnsafeContentError("input unsafe")
|
| 478 |
|
| 479 |
except UnsafeContentError:
|
|
|
|
| 186 |
|
| 187 |
pipe.to("cuda", torch.bfloat16)
|
| 188 |
|
| 189 |
+
# from diffusers.pipelines.stable_diffusion import StableDiffusionSafetyChecker
|
| 190 |
+
# from transformers import CLIPImageProcessor
|
| 191 |
|
| 192 |
+
# safety_model_id = "CompVis/stable-diffusion-safety-checker"
|
| 193 |
+
# safety_feature_extractor = CLIPImageProcessor.from_pretrained(safety_model_id)
|
| 194 |
+
# safety_checker = StableDiffusionSafetyChecker.from_pretrained(safety_model_id, torch_dtype=torch.float16).to("cuda")
|
| 195 |
|
| 196 |
+
# pipe.safety_feature_extractor = safety_feature_extractor
|
| 197 |
+
# pipe.safety_checker = safety_checker
|
| 198 |
return pipe
|
| 199 |
|
| 200 |
|
|
|
|
| 439 |
if pipe is None:
|
| 440 |
raise gr.Error("Model not loaded.")
|
| 441 |
|
| 442 |
+
# has_unsafe_concept = is_unsafe_prompt(
|
| 443 |
+
# pipe.text_encoder,
|
| 444 |
+
# pipe.tokenizer,
|
| 445 |
+
# system_prompt=UNSAFE_PROMPT_CHECK,
|
| 446 |
+
# user_prompt=prompt,
|
| 447 |
+
# max_new_token=UNSAFE_MAX_NEW_TOKEN,
|
| 448 |
+
# )
|
| 449 |
+
# if has_unsafe_concept:
|
| 450 |
+
# raise UnsafeContentError("Input unsafe")
|
| 451 |
|
| 452 |
final_prompt = prompt
|
| 453 |
|
|
|
|
| 470 |
shift=shift,
|
| 471 |
)
|
| 472 |
|
| 473 |
+
# safety_checker_input = pipe.safety_feature_extractor([image], return_tensors="pt").pixel_values.cuda()
|
| 474 |
+
# _, has_nsfw_concept = pipe.safety_checker(images=[torch.zeros(1)], clip_input=safety_checker_input)
|
| 475 |
+
# has_nsfw_concept = has_nsfw_concept[0]
|
| 476 |
+
# if has_nsfw_concept:
|
| 477 |
raise UnsafeContentError("input unsafe")
|
| 478 |
|
| 479 |
except UnsafeContentError:
|