Jacobmadwed commited on
Commit
852fbd3
·
verified ·
1 Parent(s): c26f322

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +11 -3
handler.py CHANGED
@@ -9,6 +9,7 @@ import diffusers
9
  from diffusers.utils import load_image
10
  from diffusers.models import ControlNetModel
11
  from diffusers.pipelines.controlnet.multicontrolnet import MultiControlNetModel
 
12
  from insightface.app import FaceAnalysis
13
  from style_template import styles
14
  from pipeline_stable_diffusion_xl_instantid_full import StableDiffusionXLInstantIDPipeline, draw_kps
@@ -108,7 +109,7 @@ class EndpointHandler:
108
  pretrained_model_name_or_path,
109
  controlnet=[self.controlnet_identitynet],
110
  torch_dtype=dtype,
111
- safety_checker=None,
112
  feature_extractor=None,
113
  ).to(device)
114
 
@@ -264,7 +265,7 @@ class EndpointHandler:
264
  print(f"[Debug] Prompt: {inputs}, \n[Debug] Neg Prompt: {negative_prompt}")
265
 
266
  self.pipe.set_ip_adapter_scale(adapter_strength_ratio)
267
- images = self.pipe(
268
  prompt=inputs,
269
  negative_prompt=negative_prompt,
270
  image_embeds=face_emb,
@@ -277,7 +278,14 @@ class EndpointHandler:
277
  width=width,
278
  generator=generator,
279
  enhance_face_region=enhance_face_region
280
- ).images
 
 
 
 
 
 
 
281
 
282
  # Convert the output image to base64
283
  buffered = io.BytesIO()
 
9
  from diffusers.utils import load_image
10
  from diffusers.models import ControlNetModel
11
  from diffusers.pipelines.controlnet.multicontrolnet import MultiControlNetModel
12
+ from diffusers import StableDiffusionSafetyChecker
13
  from insightface.app import FaceAnalysis
14
  from style_template import styles
15
  from pipeline_stable_diffusion_xl_instantid_full import StableDiffusionXLInstantIDPipeline, draw_kps
 
109
  pretrained_model_name_or_path,
110
  controlnet=[self.controlnet_identitynet],
111
  torch_dtype=dtype,
112
+ safety_checker=StableDiffusionSafetyChecker.from_pretrained("CompVis/stable-diffusion-safety-checker"),
113
  feature_extractor=None,
114
  ).to(device)
115
 
 
265
  print(f"[Debug] Prompt: {inputs}, \n[Debug] Neg Prompt: {negative_prompt}")
266
 
267
  self.pipe.set_ip_adapter_scale(adapter_strength_ratio)
268
+ outputs = self.pipe(
269
  prompt=inputs,
270
  negative_prompt=negative_prompt,
271
  image_embeds=face_emb,
 
278
  width=width,
279
  generator=generator,
280
  enhance_face_region=enhance_face_region
281
+ )
282
+
283
+ images = outputs.images
284
+ nsfw_detected = outputs.nsfw_content_detected
285
+
286
+ # Check for NSFW content
287
+ if nsfw_detected[0]:
288
+ return {"error": "Generated image contains NSFW content and was discarded."}
289
 
290
  # Convert the output image to base64
291
  buffered = io.BytesIO()