Spaces:
Runtime error
Runtime error
unified safety_checker
Browse files- server/main.py +11 -2
- server/pipelines/IPcompositionHyperSD15.py +8 -26
- server/pipelines/IPcompositionHyperSDXL.py +9 -28
- server/pipelines/controlnet.py +6 -18
- server/pipelines/controlnetDepthFlashSD.py +6 -19
- server/pipelines/controlnetDepthHyperSD.py +6 -18
- server/pipelines/controlnetDepthHyperSDXL.py +7 -19
- server/pipelines/controlnetFlashSD.py +6 -18
- server/pipelines/controlnetFlashSDXL.py +7 -19
- server/pipelines/controlnetHyperSD.py +6 -18
- server/pipelines/controlnetHyperSDXL.py +7 -19
- server/pipelines/controlnetLoraSD15.py +7 -22
- server/pipelines/controlnetLoraSD15QRCode.py +4 -17
- server/pipelines/controlnetLoraSDXL-Lightning.py +1 -12
- server/pipelines/controlnetLoraSDXL.py +8 -24
- server/pipelines/controlnetMistoLineHyperSDXL.py +7 -19
- server/pipelines/controlnetPCMSD15.py +5 -18
- server/pipelines/controlnetSDTurbo.py +1 -12
- server/pipelines/controlnetSDXLTurbo.py +1 -12
- server/pipelines/controlnetSegmindVegaRT.py +6 -20
- server/pipelines/img2img.py +5 -17
- server/pipelines/img2imgSDTurbo.py +5 -17
- server/pipelines/img2imgSDXL-Lightning.py +1 -11
- server/pipelines/img2imgSDXLTurbo.py +5 -17
- server/pipelines/img2imgSDXS512.py +5 -18
- server/pipelines/img2imgSegmindVegaRT.py +6 -21
- server/pipelines/txt2img.py +2 -13
- server/pipelines/txt2imgLora.py +2 -13
- server/pipelines/txt2imgLoraSDXL.py +7 -21
- server/pipelines/utils/safety_checker.py +12 -6
server/main.py
CHANGED
|
@@ -4,7 +4,8 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
| 4 |
from fastapi.staticfiles import StaticFiles
|
| 5 |
from fastapi import Request
|
| 6 |
import markdown2
|
| 7 |
-
|
|
|
|
| 8 |
import logging
|
| 9 |
from config import config, Args
|
| 10 |
from connection_manager import ConnectionManager, ServerFullException
|
|
@@ -28,6 +29,8 @@ class App:
|
|
| 28 |
self.pipeline = pipeline
|
| 29 |
self.app = FastAPI()
|
| 30 |
self.conn_manager = ConnectionManager()
|
|
|
|
|
|
|
| 31 |
self.init_app()
|
| 32 |
|
| 33 |
def init_app(self):
|
|
@@ -113,8 +116,14 @@ class App:
|
|
| 113 |
if params.__dict__ == last_params.__dict__ or params is None:
|
| 114 |
await asyncio.sleep(THROTTLE)
|
| 115 |
continue
|
| 116 |
-
last_params = params
|
| 117 |
image = pipeline.predict(params)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
if image is None:
|
| 119 |
continue
|
| 120 |
frame = pil_to_frame(image)
|
|
|
|
| 4 |
from fastapi.staticfiles import StaticFiles
|
| 5 |
from fastapi import Request
|
| 6 |
import markdown2
|
| 7 |
+
from pipelines.utils.safety_checker import SafetyChecker
|
| 8 |
+
from PIL import Image
|
| 9 |
import logging
|
| 10 |
from config import config, Args
|
| 11 |
from connection_manager import ConnectionManager, ServerFullException
|
|
|
|
| 29 |
self.pipeline = pipeline
|
| 30 |
self.app = FastAPI()
|
| 31 |
self.conn_manager = ConnectionManager()
|
| 32 |
+
if self.args.safety_checker:
|
| 33 |
+
self.safety_checker = SafetyChecker(device=device.type)
|
| 34 |
self.init_app()
|
| 35 |
|
| 36 |
def init_app(self):
|
|
|
|
| 116 |
if params.__dict__ == last_params.__dict__ or params is None:
|
| 117 |
await asyncio.sleep(THROTTLE)
|
| 118 |
continue
|
| 119 |
+
last_params: SimpleNamespace = params
|
| 120 |
image = pipeline.predict(params)
|
| 121 |
+
|
| 122 |
+
if self.args.safety_checker:
|
| 123 |
+
image, has_nsfw_concept = self.safety_checker(image)
|
| 124 |
+
if has_nsfw_concept:
|
| 125 |
+
image = None
|
| 126 |
+
|
| 127 |
if image is None:
|
| 128 |
continue
|
| 129 |
frame = pil_to_frame(image)
|
server/pipelines/IPcompositionHyperSD15.py
CHANGED
|
@@ -101,22 +101,13 @@ class Pipeline:
|
|
| 101 |
torch_dtype=torch.float16,
|
| 102 |
).to(device)
|
| 103 |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
)
|
| 112 |
-
else:
|
| 113 |
-
self.pipe = DiffusionPipeline.from_pretrained(
|
| 114 |
-
model_id,
|
| 115 |
-
safety_checker=None,
|
| 116 |
-
torch_dtype=torch_dtype,
|
| 117 |
-
image_encoder=image_encoder,
|
| 118 |
-
variant="fp16",
|
| 119 |
-
)
|
| 120 |
|
| 121 |
self.pipe.load_ip_adapter(
|
| 122 |
ip_adapter_model,
|
|
@@ -199,13 +190,4 @@ class Pipeline:
|
|
| 199 |
output_type="pil",
|
| 200 |
)
|
| 201 |
|
| 202 |
-
|
| 203 |
-
results.nsfw_content_detected[0]
|
| 204 |
-
if "nsfw_content_detected" in results
|
| 205 |
-
else False
|
| 206 |
-
)
|
| 207 |
-
if nsfw_content_detected:
|
| 208 |
-
return None
|
| 209 |
-
result_image = results.images[0]
|
| 210 |
-
|
| 211 |
-
return result_image
|
|
|
|
| 101 |
torch_dtype=torch.float16,
|
| 102 |
).to(device)
|
| 103 |
|
| 104 |
+
self.pipe = DiffusionPipeline.from_pretrained(
|
| 105 |
+
model_id,
|
| 106 |
+
safety_checker=None,
|
| 107 |
+
torch_dtype=torch_dtype,
|
| 108 |
+
image_encoder=image_encoder,
|
| 109 |
+
variant="fp16",
|
| 110 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
self.pipe.load_ip_adapter(
|
| 113 |
ip_adapter_model,
|
|
|
|
| 190 |
output_type="pil",
|
| 191 |
)
|
| 192 |
|
| 193 |
+
return results.images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/pipelines/IPcompositionHyperSDXL.py
CHANGED
|
@@ -106,23 +106,14 @@ class Pipeline:
|
|
| 106 |
torch_dtype=torch.float16,
|
| 107 |
).to(device)
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
else:
|
| 118 |
-
self.pipe = StableDiffusionXLPipeline.from_pretrained(
|
| 119 |
-
model_id,
|
| 120 |
-
safety_checker=None,
|
| 121 |
-
torch_dtype=torch_dtype,
|
| 122 |
-
vae=vae,
|
| 123 |
-
image_encoder=image_encoder,
|
| 124 |
-
variant="fp16",
|
| 125 |
-
)
|
| 126 |
self.pipe.load_ip_adapter(
|
| 127 |
ip_adapter_model,
|
| 128 |
subfolder="",
|
|
@@ -214,14 +205,4 @@ class Pipeline:
|
|
| 214 |
ip_adapter_image=[params.image],
|
| 215 |
output_type="pil",
|
| 216 |
)
|
| 217 |
-
|
| 218 |
-
nsfw_content_detected = (
|
| 219 |
-
results.nsfw_content_detected[0]
|
| 220 |
-
if "nsfw_content_detected" in results
|
| 221 |
-
else False
|
| 222 |
-
)
|
| 223 |
-
if nsfw_content_detected:
|
| 224 |
-
return None
|
| 225 |
-
result_image = results.images[0]
|
| 226 |
-
|
| 227 |
-
return result_image
|
|
|
|
| 106 |
torch_dtype=torch.float16,
|
| 107 |
).to(device)
|
| 108 |
|
| 109 |
+
self.pipe = StableDiffusionXLPipeline.from_pretrained(
|
| 110 |
+
model_id,
|
| 111 |
+
safety_checker=None,
|
| 112 |
+
torch_dtype=torch_dtype,
|
| 113 |
+
vae=vae,
|
| 114 |
+
image_encoder=image_encoder,
|
| 115 |
+
variant="fp16",
|
| 116 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
self.pipe.load_ip_adapter(
|
| 118 |
ip_adapter_model,
|
| 119 |
subfolder="",
|
|
|
|
| 205 |
ip_adapter_image=[params.image],
|
| 206 |
output_type="pil",
|
| 207 |
)
|
| 208 |
+
return results.images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/pipelines/controlnet.py
CHANGED
|
@@ -159,16 +159,12 @@ class Pipeline:
|
|
| 159 |
controlnet_canny = ControlNetModel.from_pretrained(
|
| 160 |
controlnet_model, torch_dtype=torch_dtype
|
| 161 |
).to(device)
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
base_model,
|
| 169 |
-
safety_checker=None,
|
| 170 |
-
controlnet=controlnet_canny,
|
| 171 |
-
)
|
| 172 |
if args.taesd:
|
| 173 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
| 174 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
@@ -254,14 +250,6 @@ class Pipeline:
|
|
| 254 |
control_guidance_start=params.controlnet_start,
|
| 255 |
control_guidance_end=params.controlnet_end,
|
| 256 |
)
|
| 257 |
-
|
| 258 |
-
nsfw_content_detected = (
|
| 259 |
-
results.nsfw_content_detected[0]
|
| 260 |
-
if "nsfw_content_detected" in results
|
| 261 |
-
else False
|
| 262 |
-
)
|
| 263 |
-
if nsfw_content_detected:
|
| 264 |
-
return None
|
| 265 |
result_image = results.images[0]
|
| 266 |
if params.debug_canny:
|
| 267 |
# paste control_image on top of result_image
|
|
|
|
| 159 |
controlnet_canny = ControlNetModel.from_pretrained(
|
| 160 |
controlnet_model, torch_dtype=torch_dtype
|
| 161 |
).to(device)
|
| 162 |
+
|
| 163 |
+
self.pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
| 164 |
+
base_model,
|
| 165 |
+
safety_checker=None,
|
| 166 |
+
controlnet=controlnet_canny,
|
| 167 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
if args.taesd:
|
| 169 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
| 170 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
|
|
| 250 |
control_guidance_start=params.controlnet_start,
|
| 251 |
control_guidance_end=params.controlnet_end,
|
| 252 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
result_image = results.images[0]
|
| 254 |
if params.debug_canny:
|
| 255 |
# paste control_image on top of result_image
|
server/pipelines/controlnetDepthFlashSD.py
CHANGED
|
@@ -146,17 +146,12 @@ class Pipeline:
|
|
| 146 |
device=device,
|
| 147 |
)
|
| 148 |
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
model_id,
|
| 156 |
-
safety_checker=None,
|
| 157 |
-
controlnet=controlnet_depth,
|
| 158 |
-
torch_dtype=torch_dtype,
|
| 159 |
-
)
|
| 160 |
|
| 161 |
if args.taesd:
|
| 162 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
|
@@ -258,14 +253,6 @@ class Pipeline:
|
|
| 258 |
control_guidance_start=params.controlnet_start,
|
| 259 |
control_guidance_end=params.controlnet_end,
|
| 260 |
)
|
| 261 |
-
|
| 262 |
-
nsfw_content_detected = (
|
| 263 |
-
results.nsfw_content_detected[0]
|
| 264 |
-
if "nsfw_content_detected" in results
|
| 265 |
-
else False
|
| 266 |
-
)
|
| 267 |
-
if nsfw_content_detected:
|
| 268 |
-
return None
|
| 269 |
result_image = results.images[0]
|
| 270 |
if params.debug_depth:
|
| 271 |
# paste control_image on top of result_image
|
|
|
|
| 146 |
device=device,
|
| 147 |
)
|
| 148 |
|
| 149 |
+
self.pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
| 150 |
+
model_id,
|
| 151 |
+
safety_checker=None,
|
| 152 |
+
controlnet=controlnet_depth,
|
| 153 |
+
torch_dtype=torch_dtype,
|
| 154 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
if args.taesd:
|
| 157 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
|
|
|
| 253 |
control_guidance_start=params.controlnet_start,
|
| 254 |
control_guidance_end=params.controlnet_end,
|
| 255 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
result_image = results.images[0]
|
| 257 |
if params.debug_depth:
|
| 258 |
# paste control_image on top of result_image
|
server/pipelines/controlnetDepthHyperSD.py
CHANGED
|
@@ -148,17 +148,12 @@ class Pipeline:
|
|
| 148 |
device=device,
|
| 149 |
)
|
| 150 |
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
model_id,
|
| 158 |
-
safety_checker=None,
|
| 159 |
-
controlnet=controlnet_depth,
|
| 160 |
-
torch_dtype=torch_dtype,
|
| 161 |
-
)
|
| 162 |
|
| 163 |
if args.taesd:
|
| 164 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
|
@@ -259,13 +254,6 @@ class Pipeline:
|
|
| 259 |
control_guidance_end=params.controlnet_end,
|
| 260 |
)
|
| 261 |
|
| 262 |
-
nsfw_content_detected = (
|
| 263 |
-
results.nsfw_content_detected[0]
|
| 264 |
-
if "nsfw_content_detected" in results
|
| 265 |
-
else False
|
| 266 |
-
)
|
| 267 |
-
if nsfw_content_detected:
|
| 268 |
-
return None
|
| 269 |
result_image = results.images[0]
|
| 270 |
if params.debug_depth:
|
| 271 |
# paste control_image on top of result_image
|
|
|
|
| 148 |
device=device,
|
| 149 |
)
|
| 150 |
|
| 151 |
+
self.pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
| 152 |
+
model_id,
|
| 153 |
+
safety_checker=None,
|
| 154 |
+
controlnet=controlnet_depth,
|
| 155 |
+
torch_dtype=torch_dtype,
|
| 156 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
|
| 158 |
if args.taesd:
|
| 159 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
|
|
|
| 254 |
control_guidance_end=params.controlnet_end,
|
| 255 |
)
|
| 256 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
result_image = results.images[0]
|
| 258 |
if params.debug_depth:
|
| 259 |
# paste control_image on top of result_image
|
server/pipelines/controlnetDepthHyperSDXL.py
CHANGED
|
@@ -151,18 +151,13 @@ class Pipeline:
|
|
| 151 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch_dtype
|
| 152 |
)
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
safety_checker=None,
|
| 162 |
-
controlnet=controlnet_depth,
|
| 163 |
-
vae=vae,
|
| 164 |
-
torch_dtype=torch_dtype,
|
| 165 |
-
)
|
| 166 |
|
| 167 |
self.pipe.load_lora_weights(
|
| 168 |
hf_hub_download("ByteDance/Hyper-SD", "Hyper-SDXL-1step-lora.safetensors")
|
|
@@ -258,13 +253,6 @@ class Pipeline:
|
|
| 258 |
control_guidance_end=params.controlnet_end,
|
| 259 |
)
|
| 260 |
|
| 261 |
-
nsfw_content_detected = (
|
| 262 |
-
results.nsfw_content_detected[0]
|
| 263 |
-
if "nsfw_content_detected" in results
|
| 264 |
-
else False
|
| 265 |
-
)
|
| 266 |
-
if nsfw_content_detected:
|
| 267 |
-
return None
|
| 268 |
result_image = results.images[0]
|
| 269 |
if params.debug_depth:
|
| 270 |
# paste control_image on top of result_image
|
|
|
|
| 151 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch_dtype
|
| 152 |
)
|
| 153 |
|
| 154 |
+
self.pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
|
| 155 |
+
model_id,
|
| 156 |
+
safety_checker=None,
|
| 157 |
+
controlnet=controlnet_depth,
|
| 158 |
+
vae=vae,
|
| 159 |
+
torch_dtype=torch_dtype,
|
| 160 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
self.pipe.load_lora_weights(
|
| 163 |
hf_hub_download("ByteDance/Hyper-SD", "Hyper-SDXL-1step-lora.safetensors")
|
|
|
|
| 253 |
control_guidance_end=params.controlnet_end,
|
| 254 |
)
|
| 255 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
result_image = results.images[0]
|
| 257 |
if params.debug_depth:
|
| 258 |
# paste control_image on top of result_image
|
server/pipelines/controlnetFlashSD.py
CHANGED
|
@@ -138,17 +138,12 @@ class Pipeline:
|
|
| 138 |
controlnet_model, torch_dtype=torch_dtype
|
| 139 |
)
|
| 140 |
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
model_id,
|
| 148 |
-
safety_checker=None,
|
| 149 |
-
controlnet=controlnet_canny,
|
| 150 |
-
torch_dtype=torch_dtype,
|
| 151 |
-
)
|
| 152 |
|
| 153 |
self.pipe.scheduler = LCMScheduler.from_pretrained(
|
| 154 |
model_id,
|
|
@@ -252,13 +247,6 @@ class Pipeline:
|
|
| 252 |
control_guidance_end=params.controlnet_end,
|
| 253 |
)
|
| 254 |
|
| 255 |
-
nsfw_content_detected = (
|
| 256 |
-
results.nsfw_content_detected[0]
|
| 257 |
-
if "nsfw_content_detected" in results
|
| 258 |
-
else False
|
| 259 |
-
)
|
| 260 |
-
if nsfw_content_detected:
|
| 261 |
-
return None
|
| 262 |
result_image = results.images[0]
|
| 263 |
if params.debug_canny:
|
| 264 |
# paste control_image on top of result_image
|
|
|
|
| 138 |
controlnet_model, torch_dtype=torch_dtype
|
| 139 |
)
|
| 140 |
|
| 141 |
+
self.pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
| 142 |
+
model_id,
|
| 143 |
+
safety_checker=None,
|
| 144 |
+
controlnet=controlnet_canny,
|
| 145 |
+
torch_dtype=torch_dtype,
|
| 146 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
|
| 148 |
self.pipe.scheduler = LCMScheduler.from_pretrained(
|
| 149 |
model_id,
|
|
|
|
| 247 |
control_guidance_end=params.controlnet_end,
|
| 248 |
)
|
| 249 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
result_image = results.images[0]
|
| 251 |
if params.debug_canny:
|
| 252 |
# paste control_image on top of result_image
|
server/pipelines/controlnetFlashSDXL.py
CHANGED
|
@@ -143,18 +143,13 @@ class Pipeline:
|
|
| 143 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch_dtype
|
| 144 |
)
|
| 145 |
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
safety_checker=None,
|
| 154 |
-
controlnet=controlnet_canny,
|
| 155 |
-
vae=vae,
|
| 156 |
-
torch_dtype=torch_dtype,
|
| 157 |
-
)
|
| 158 |
|
| 159 |
self.pipe.scheduler = LCMScheduler.from_pretrained(
|
| 160 |
model_id,
|
|
@@ -253,13 +248,6 @@ class Pipeline:
|
|
| 253 |
control_guidance_end=params.controlnet_end,
|
| 254 |
)
|
| 255 |
|
| 256 |
-
nsfw_content_detected = (
|
| 257 |
-
results.nsfw_content_detected[0]
|
| 258 |
-
if "nsfw_content_detected" in results
|
| 259 |
-
else False
|
| 260 |
-
)
|
| 261 |
-
if nsfw_content_detected:
|
| 262 |
-
return None
|
| 263 |
result_image = results.images[0]
|
| 264 |
if params.debug_canny:
|
| 265 |
# paste control_image on top of result_image
|
|
|
|
| 143 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch_dtype
|
| 144 |
)
|
| 145 |
|
| 146 |
+
self.pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
|
| 147 |
+
model_id,
|
| 148 |
+
safety_checker=None,
|
| 149 |
+
controlnet=controlnet_canny,
|
| 150 |
+
vae=vae,
|
| 151 |
+
torch_dtype=torch_dtype,
|
| 152 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
self.pipe.scheduler = LCMScheduler.from_pretrained(
|
| 155 |
model_id,
|
|
|
|
| 248 |
control_guidance_end=params.controlnet_end,
|
| 249 |
)
|
| 250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
result_image = results.images[0]
|
| 252 |
if params.debug_canny:
|
| 253 |
# paste control_image on top of result_image
|
server/pipelines/controlnetHyperSD.py
CHANGED
|
@@ -160,17 +160,12 @@ class Pipeline:
|
|
| 160 |
controlnet_model, torch_dtype=torch_dtype
|
| 161 |
)
|
| 162 |
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
model_id,
|
| 170 |
-
safety_checker=None,
|
| 171 |
-
controlnet=controlnet_canny,
|
| 172 |
-
torch_dtype=torch_dtype,
|
| 173 |
-
)
|
| 174 |
|
| 175 |
self.pipe.load_lora_weights(
|
| 176 |
hf_hub_download("ByteDance/Hyper-SD", "Hyper-SD15-1step-lora.safetensors")
|
|
@@ -269,13 +264,6 @@ class Pipeline:
|
|
| 269 |
control_guidance_end=params.controlnet_end,
|
| 270 |
)
|
| 271 |
|
| 272 |
-
nsfw_content_detected = (
|
| 273 |
-
results.nsfw_content_detected[0]
|
| 274 |
-
if "nsfw_content_detected" in results
|
| 275 |
-
else False
|
| 276 |
-
)
|
| 277 |
-
if nsfw_content_detected:
|
| 278 |
-
return None
|
| 279 |
result_image = results.images[0]
|
| 280 |
if params.debug_canny:
|
| 281 |
# paste control_image on top of result_image
|
|
|
|
| 160 |
controlnet_model, torch_dtype=torch_dtype
|
| 161 |
)
|
| 162 |
|
| 163 |
+
self.pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
| 164 |
+
model_id,
|
| 165 |
+
safety_checker=None,
|
| 166 |
+
controlnet=controlnet_canny,
|
| 167 |
+
torch_dtype=torch_dtype,
|
| 168 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
|
| 170 |
self.pipe.load_lora_weights(
|
| 171 |
hf_hub_download("ByteDance/Hyper-SD", "Hyper-SD15-1step-lora.safetensors")
|
|
|
|
| 264 |
control_guidance_end=params.controlnet_end,
|
| 265 |
)
|
| 266 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 267 |
result_image = results.images[0]
|
| 268 |
if params.debug_canny:
|
| 269 |
# paste control_image on top of result_image
|
server/pipelines/controlnetHyperSDXL.py
CHANGED
|
@@ -164,18 +164,13 @@ class Pipeline:
|
|
| 164 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch_dtype
|
| 165 |
)
|
| 166 |
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
safety_checker=None,
|
| 175 |
-
controlnet=controlnet_canny,
|
| 176 |
-
vae=vae,
|
| 177 |
-
torch_dtype=torch_dtype,
|
| 178 |
-
)
|
| 179 |
|
| 180 |
self.pipe.load_lora_weights(
|
| 181 |
hf_hub_download("ByteDance/Hyper-SD", "Hyper-SDXL-1step-lora.safetensors")
|
|
@@ -274,13 +269,6 @@ class Pipeline:
|
|
| 274 |
control_guidance_end=params.controlnet_end,
|
| 275 |
)
|
| 276 |
|
| 277 |
-
nsfw_content_detected = (
|
| 278 |
-
results.nsfw_content_detected[0]
|
| 279 |
-
if "nsfw_content_detected" in results
|
| 280 |
-
else False
|
| 281 |
-
)
|
| 282 |
-
if nsfw_content_detected:
|
| 283 |
-
return None
|
| 284 |
result_image = results.images[0]
|
| 285 |
if params.debug_canny:
|
| 286 |
# paste control_image on top of result_image
|
|
|
|
| 164 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch_dtype
|
| 165 |
)
|
| 166 |
|
| 167 |
+
self.pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
|
| 168 |
+
model_id,
|
| 169 |
+
safety_checker=None,
|
| 170 |
+
controlnet=controlnet_canny,
|
| 171 |
+
vae=vae,
|
| 172 |
+
torch_dtype=torch_dtype,
|
| 173 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
self.pipe.load_lora_weights(
|
| 176 |
hf_hub_download("ByteDance/Hyper-SD", "Hyper-SDXL-1step-lora.safetensors")
|
|
|
|
| 269 |
control_guidance_end=params.controlnet_end,
|
| 270 |
)
|
| 271 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
result_image = results.images[0]
|
| 273 |
if params.debug_canny:
|
| 274 |
# paste control_image on top of result_image
|
server/pipelines/controlnetLoraSD15.py
CHANGED
|
@@ -174,21 +174,13 @@ class Pipeline:
|
|
| 174 |
|
| 175 |
self.pipes = {}
|
| 176 |
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
else:
|
| 185 |
-
for base_model_id in base_models.keys():
|
| 186 |
-
pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
| 187 |
-
base_model_id,
|
| 188 |
-
safety_checker=None,
|
| 189 |
-
controlnet=controlnet_canny,
|
| 190 |
-
)
|
| 191 |
-
self.pipes[base_model_id] = pipe
|
| 192 |
|
| 193 |
self.canny_torch = SobelOperator(device=device)
|
| 194 |
|
|
@@ -262,13 +254,6 @@ class Pipeline:
|
|
| 262 |
control_guidance_end=params.controlnet_end,
|
| 263 |
)
|
| 264 |
|
| 265 |
-
nsfw_content_detected = (
|
| 266 |
-
results.nsfw_content_detected[0]
|
| 267 |
-
if "nsfw_content_detected" in results
|
| 268 |
-
else False
|
| 269 |
-
)
|
| 270 |
-
if nsfw_content_detected:
|
| 271 |
-
return None
|
| 272 |
result_image = results.images[0]
|
| 273 |
if params.debug_canny:
|
| 274 |
# paste control_image on top of result_image
|
|
|
|
| 174 |
|
| 175 |
self.pipes = {}
|
| 176 |
|
| 177 |
+
for base_model_id in base_models.keys():
|
| 178 |
+
pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
| 179 |
+
base_model_id,
|
| 180 |
+
safety_checker=None,
|
| 181 |
+
controlnet=controlnet_canny,
|
| 182 |
+
)
|
| 183 |
+
self.pipes[base_model_id] = pipe
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
self.canny_torch = SobelOperator(device=device)
|
| 186 |
|
|
|
|
| 254 |
control_guidance_end=params.controlnet_end,
|
| 255 |
)
|
| 256 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
result_image = results.images[0]
|
| 258 |
if params.debug_canny:
|
| 259 |
# paste control_image on top of result_image
|
server/pipelines/controlnetLoraSD15QRCode.py
CHANGED
|
@@ -154,11 +154,9 @@ class Pipeline:
|
|
| 154 |
controlnet=controlnet_qrcode,
|
| 155 |
)
|
| 156 |
|
| 157 |
-
self.control_image = Image.open(
|
| 158 |
-
"qr-code.png").convert("RGB").resize((512, 512))
|
| 159 |
|
| 160 |
-
self.pipe.scheduler = LCMScheduler.from_config(
|
| 161 |
-
self.pipe.scheduler.config)
|
| 162 |
self.pipe.set_progress_bar_config(disable=True)
|
| 163 |
if device.type != "mps":
|
| 164 |
self.pipe.unet.to(memory_format=torch.channels_last)
|
|
@@ -206,9 +204,7 @@ class Pipeline:
|
|
| 206 |
steps = math.ceil(1 / max(0.10, strength))
|
| 207 |
|
| 208 |
blend_qr_image = Image.blend(
|
| 209 |
-
params.image,
|
| 210 |
-
self.control_image,
|
| 211 |
-
alpha=params.blend
|
| 212 |
)
|
| 213 |
results = self.pipe(
|
| 214 |
image=blend_qr_image,
|
|
@@ -227,13 +223,4 @@ class Pipeline:
|
|
| 227 |
control_guidance_end=params.controlnet_end,
|
| 228 |
)
|
| 229 |
|
| 230 |
-
|
| 231 |
-
results.nsfw_content_detected[0]
|
| 232 |
-
if "nsfw_content_detected" in results
|
| 233 |
-
else False
|
| 234 |
-
)
|
| 235 |
-
if nsfw_content_detected:
|
| 236 |
-
return None
|
| 237 |
-
result_image = results.images[0]
|
| 238 |
-
|
| 239 |
-
return result_image
|
|
|
|
| 154 |
controlnet=controlnet_qrcode,
|
| 155 |
)
|
| 156 |
|
| 157 |
+
self.control_image = Image.open("qr-code.png").convert("RGB").resize((512, 512))
|
|
|
|
| 158 |
|
| 159 |
+
self.pipe.scheduler = LCMScheduler.from_config(self.pipe.scheduler.config)
|
|
|
|
| 160 |
self.pipe.set_progress_bar_config(disable=True)
|
| 161 |
if device.type != "mps":
|
| 162 |
self.pipe.unet.to(memory_format=torch.channels_last)
|
|
|
|
| 204 |
steps = math.ceil(1 / max(0.10, strength))
|
| 205 |
|
| 206 |
blend_qr_image = Image.blend(
|
| 207 |
+
params.image, self.control_image, alpha=params.blend
|
|
|
|
|
|
|
| 208 |
)
|
| 209 |
results = self.pipe(
|
| 210 |
image=blend_qr_image,
|
|
|
|
| 223 |
control_guidance_end=params.controlnet_end,
|
| 224 |
)
|
| 225 |
|
| 226 |
+
return results.images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/pipelines/controlnetLoraSDXL-Lightning.py
CHANGED
|
@@ -9,7 +9,6 @@ from diffusers import (
|
|
| 9 |
from compel import Compel, ReturnedEmbeddingsType
|
| 10 |
import torch
|
| 11 |
from pipelines.utils.canny_gpu import SobelOperator
|
| 12 |
-
from pipelines.utils.safety_checker import SafetyChecker
|
| 13 |
from huggingface_hub import hf_hub_download
|
| 14 |
from safetensors.torch import load_file
|
| 15 |
|
|
@@ -169,10 +168,6 @@ class Pipeline:
|
|
| 169 |
)
|
| 170 |
|
| 171 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
| 172 |
-
self.safety_checker = None
|
| 173 |
-
if args.safety_checker:
|
| 174 |
-
self.safety_checker = SafetyChecker(device=device.type)
|
| 175 |
-
|
| 176 |
if args.taesd:
|
| 177 |
vae = AutoencoderTiny.from_pretrained(
|
| 178 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
@@ -290,13 +285,7 @@ class Pipeline:
|
|
| 290 |
control_guidance_start=params.controlnet_start,
|
| 291 |
control_guidance_end=params.controlnet_end,
|
| 292 |
)
|
| 293 |
-
|
| 294 |
-
if self.safety_checker:
|
| 295 |
-
images, has_nsfw_concepts = self.safety_checker(images)
|
| 296 |
-
if any(has_nsfw_concepts):
|
| 297 |
-
return None
|
| 298 |
-
|
| 299 |
-
result_image = images[0]
|
| 300 |
if params.debug_canny:
|
| 301 |
# paste control_image on top of result_image
|
| 302 |
w0, h0 = (200, 200)
|
|
|
|
| 9 |
from compel import Compel, ReturnedEmbeddingsType
|
| 10 |
import torch
|
| 11 |
from pipelines.utils.canny_gpu import SobelOperator
|
|
|
|
| 12 |
from huggingface_hub import hf_hub_download
|
| 13 |
from safetensors.torch import load_file
|
| 14 |
|
|
|
|
| 168 |
)
|
| 169 |
|
| 170 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
if args.taesd:
|
| 172 |
vae = AutoencoderTiny.from_pretrained(
|
| 173 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
|
|
| 285 |
control_guidance_start=params.controlnet_start,
|
| 286 |
control_guidance_end=params.controlnet_end,
|
| 287 |
)
|
| 288 |
+
result_image = results.images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 289 |
if params.debug_canny:
|
| 290 |
# paste control_image on top of result_image
|
| 291 |
w0, h0 = (200, 200)
|
server/pipelines/controlnetLoraSDXL.py
CHANGED
|
@@ -173,19 +173,12 @@ class Pipeline:
|
|
| 173 |
vae = AutoencoderKL.from_pretrained(
|
| 174 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch_dtype
|
| 175 |
)
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
else:
|
| 183 |
-
self.pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
|
| 184 |
-
model_id,
|
| 185 |
-
safety_checker=None,
|
| 186 |
-
controlnet=controlnet_canny,
|
| 187 |
-
vae=vae,
|
| 188 |
-
)
|
| 189 |
self.canny_torch = SobelOperator(device=device)
|
| 190 |
# Load LCM LoRA
|
| 191 |
self.pipe.load_lora_weights(lcm_lora_id, adapter_name="lcm")
|
|
@@ -196,8 +189,7 @@ class Pipeline:
|
|
| 196 |
)
|
| 197 |
self.pipe.set_adapters(["lcm", "toy"], adapter_weights=[1.0, 0.8])
|
| 198 |
|
| 199 |
-
self.pipe.scheduler = LCMScheduler.from_config(
|
| 200 |
-
self.pipe.scheduler.config)
|
| 201 |
self.pipe.set_progress_bar_config(disable=True)
|
| 202 |
self.pipe.to(device=device, dtype=torch_dtype).to(device)
|
| 203 |
|
|
@@ -219,8 +211,7 @@ class Pipeline:
|
|
| 219 |
if args.compel:
|
| 220 |
self.pipe.compel_proc = Compel(
|
| 221 |
tokenizer=[self.pipe.tokenizer, self.pipe.tokenizer_2],
|
| 222 |
-
text_encoder=[self.pipe.text_encoder,
|
| 223 |
-
self.pipe.text_encoder_2],
|
| 224 |
returned_embeddings_type=ReturnedEmbeddingsType.PENULTIMATE_HIDDEN_STATES_NON_NORMALIZED,
|
| 225 |
requires_pooled=[False, True],
|
| 226 |
)
|
|
@@ -292,13 +283,6 @@ class Pipeline:
|
|
| 292 |
control_guidance_end=params.controlnet_end,
|
| 293 |
)
|
| 294 |
|
| 295 |
-
nsfw_content_detected = (
|
| 296 |
-
results.nsfw_content_detected[0]
|
| 297 |
-
if "nsfw_content_detected" in results
|
| 298 |
-
else False
|
| 299 |
-
)
|
| 300 |
-
if nsfw_content_detected:
|
| 301 |
-
return None
|
| 302 |
result_image = results.images[0]
|
| 303 |
if params.debug_canny:
|
| 304 |
# paste control_image on top of result_image
|
|
|
|
| 173 |
vae = AutoencoderKL.from_pretrained(
|
| 174 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch_dtype
|
| 175 |
)
|
| 176 |
+
self.pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
|
| 177 |
+
model_id,
|
| 178 |
+
safety_checker=None,
|
| 179 |
+
controlnet=controlnet_canny,
|
| 180 |
+
vae=vae,
|
| 181 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
self.canny_torch = SobelOperator(device=device)
|
| 183 |
# Load LCM LoRA
|
| 184 |
self.pipe.load_lora_weights(lcm_lora_id, adapter_name="lcm")
|
|
|
|
| 189 |
)
|
| 190 |
self.pipe.set_adapters(["lcm", "toy"], adapter_weights=[1.0, 0.8])
|
| 191 |
|
| 192 |
+
self.pipe.scheduler = LCMScheduler.from_config(self.pipe.scheduler.config)
|
|
|
|
| 193 |
self.pipe.set_progress_bar_config(disable=True)
|
| 194 |
self.pipe.to(device=device, dtype=torch_dtype).to(device)
|
| 195 |
|
|
|
|
| 211 |
if args.compel:
|
| 212 |
self.pipe.compel_proc = Compel(
|
| 213 |
tokenizer=[self.pipe.tokenizer, self.pipe.tokenizer_2],
|
| 214 |
+
text_encoder=[self.pipe.text_encoder, self.pipe.text_encoder_2],
|
|
|
|
| 215 |
returned_embeddings_type=ReturnedEmbeddingsType.PENULTIMATE_HIDDEN_STATES_NON_NORMALIZED,
|
| 216 |
requires_pooled=[False, True],
|
| 217 |
)
|
|
|
|
| 283 |
control_guidance_end=params.controlnet_end,
|
| 284 |
)
|
| 285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
result_image = results.images[0]
|
| 287 |
if params.debug_canny:
|
| 288 |
# paste control_image on top of result_image
|
server/pipelines/controlnetMistoLineHyperSDXL.py
CHANGED
|
@@ -166,18 +166,13 @@ class Pipeline:
|
|
| 166 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch_dtype
|
| 167 |
)
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
safety_checker=None,
|
| 177 |
-
controlnet=controlnet_canny,
|
| 178 |
-
vae=vae,
|
| 179 |
-
torch_dtype=torch_dtype,
|
| 180 |
-
)
|
| 181 |
|
| 182 |
self.pipe.load_lora_weights(
|
| 183 |
hf_hub_download("ByteDance/Hyper-SD", "Hyper-SDXL-1step-lora.safetensors")
|
|
@@ -282,13 +277,6 @@ class Pipeline:
|
|
| 282 |
control_guidance_end=params.controlnet_end,
|
| 283 |
)
|
| 284 |
|
| 285 |
-
nsfw_content_detected = (
|
| 286 |
-
results.nsfw_content_detected[0]
|
| 287 |
-
if "nsfw_content_detected" in results
|
| 288 |
-
else False
|
| 289 |
-
)
|
| 290 |
-
if nsfw_content_detected:
|
| 291 |
-
return None
|
| 292 |
result_image = results.images[0]
|
| 293 |
if params.debug_canny:
|
| 294 |
# paste control_image on top of result_image
|
|
|
|
| 166 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch_dtype
|
| 167 |
)
|
| 168 |
|
| 169 |
+
self.pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
|
| 170 |
+
model_id,
|
| 171 |
+
safety_checker=None,
|
| 172 |
+
controlnet=controlnet_canny,
|
| 173 |
+
vae=vae,
|
| 174 |
+
torch_dtype=torch_dtype,
|
| 175 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
|
| 177 |
self.pipe.load_lora_weights(
|
| 178 |
hf_hub_download("ByteDance/Hyper-SD", "Hyper-SDXL-1step-lora.safetensors")
|
|
|
|
| 277 |
control_guidance_end=params.controlnet_end,
|
| 278 |
)
|
| 279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
result_image = results.images[0]
|
| 281 |
if params.debug_canny:
|
| 282 |
# paste control_image on top of result_image
|
server/pipelines/controlnetPCMSD15.py
CHANGED
|
@@ -140,17 +140,11 @@ class Pipeline:
|
|
| 140 |
controlnet_model, torch_dtype=torch_dtype
|
| 141 |
).to(device)
|
| 142 |
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
else:
|
| 149 |
-
self.pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
| 150 |
-
base_model_id,
|
| 151 |
-
safety_checker=None,
|
| 152 |
-
controlnet=controlnet_canny,
|
| 153 |
-
)
|
| 154 |
|
| 155 |
self.canny_torch = SobelOperator(device=device)
|
| 156 |
|
|
@@ -238,13 +232,6 @@ class Pipeline:
|
|
| 238 |
control_guidance_end=params.controlnet_end,
|
| 239 |
)
|
| 240 |
|
| 241 |
-
nsfw_content_detected = (
|
| 242 |
-
results.nsfw_content_detected[0]
|
| 243 |
-
if "nsfw_content_detected" in results
|
| 244 |
-
else False
|
| 245 |
-
)
|
| 246 |
-
if nsfw_content_detected:
|
| 247 |
-
return None
|
| 248 |
result_image = results.images[0]
|
| 249 |
if params.debug_canny:
|
| 250 |
# paste control_image on top of result_image
|
|
|
|
| 140 |
controlnet_model, torch_dtype=torch_dtype
|
| 141 |
).to(device)
|
| 142 |
|
| 143 |
+
self.pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
| 144 |
+
base_model_id,
|
| 145 |
+
safety_checker=None,
|
| 146 |
+
controlnet=controlnet_canny,
|
| 147 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
self.canny_torch = SobelOperator(device=device)
|
| 150 |
|
|
|
|
| 232 |
control_guidance_end=params.controlnet_end,
|
| 233 |
)
|
| 234 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
result_image = results.images[0]
|
| 236 |
if params.debug_canny:
|
| 237 |
# paste control_image on top of result_image
|
server/pipelines/controlnetSDTurbo.py
CHANGED
|
@@ -7,7 +7,6 @@ from diffusers import (
|
|
| 7 |
from compel import Compel
|
| 8 |
import torch
|
| 9 |
from pipelines.utils.canny_gpu import SobelOperator
|
| 10 |
-
from pipelines.utils.safety_checker import SafetyChecker
|
| 11 |
|
| 12 |
try:
|
| 13 |
import intel_extension_for_pytorch as ipex # type: ignore
|
|
@@ -162,10 +161,6 @@ class Pipeline:
|
|
| 162 |
)
|
| 163 |
self.pipes = {}
|
| 164 |
|
| 165 |
-
self.safety_checker = None
|
| 166 |
-
if args.safety_checker:
|
| 167 |
-
self.safety_checker = SafetyChecker(device=device.type)
|
| 168 |
-
|
| 169 |
self.pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
| 170 |
base_model,
|
| 171 |
controlnet=controlnet_canny,
|
|
@@ -267,13 +262,7 @@ class Pipeline:
|
|
| 267 |
control_guidance_start=params.controlnet_start,
|
| 268 |
control_guidance_end=params.controlnet_end,
|
| 269 |
)
|
| 270 |
-
|
| 271 |
-
if self.safety_checker:
|
| 272 |
-
images, has_nsfw_concepts = self.safety_checker(images)
|
| 273 |
-
if any(has_nsfw_concepts):
|
| 274 |
-
return None
|
| 275 |
-
|
| 276 |
-
result_image = images[0]
|
| 277 |
if params.debug_canny:
|
| 278 |
# paste control_image on top of result_image
|
| 279 |
w0, h0 = (200, 200)
|
|
|
|
| 7 |
from compel import Compel
|
| 8 |
import torch
|
| 9 |
from pipelines.utils.canny_gpu import SobelOperator
|
|
|
|
| 10 |
|
| 11 |
try:
|
| 12 |
import intel_extension_for_pytorch as ipex # type: ignore
|
|
|
|
| 161 |
)
|
| 162 |
self.pipes = {}
|
| 163 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
self.pipe = StableDiffusionControlNetImg2ImgPipeline.from_pretrained(
|
| 165 |
base_model,
|
| 166 |
controlnet=controlnet_canny,
|
|
|
|
| 262 |
control_guidance_start=params.controlnet_start,
|
| 263 |
control_guidance_end=params.controlnet_end,
|
| 264 |
)
|
| 265 |
+
result_image = results.images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
if params.debug_canny:
|
| 267 |
# paste control_image on top of result_image
|
| 268 |
w0, h0 = (200, 200)
|
server/pipelines/controlnetSDXLTurbo.py
CHANGED
|
@@ -7,7 +7,6 @@ from diffusers import (
|
|
| 7 |
from compel import Compel, ReturnedEmbeddingsType
|
| 8 |
import torch
|
| 9 |
from pipelines.utils.canny_gpu import SobelOperator
|
| 10 |
-
from pipelines.utils.safety_checker import SafetyChecker
|
| 11 |
|
| 12 |
try:
|
| 13 |
import intel_extension_for_pytorch as ipex # type: ignore
|
|
@@ -171,9 +170,6 @@ class Pipeline:
|
|
| 171 |
vae = AutoencoderKL.from_pretrained(
|
| 172 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch_dtype
|
| 173 |
)
|
| 174 |
-
self.safety_checker = None
|
| 175 |
-
if args.safety_checker:
|
| 176 |
-
self.safety_checker = SafetyChecker(device=device.type)
|
| 177 |
|
| 178 |
self.pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
|
| 179 |
model_id,
|
|
@@ -274,14 +270,7 @@ class Pipeline:
|
|
| 274 |
control_guidance_start=params.controlnet_start,
|
| 275 |
control_guidance_end=params.controlnet_end,
|
| 276 |
)
|
| 277 |
-
|
| 278 |
-
images = results.images
|
| 279 |
-
if self.safety_checker:
|
| 280 |
-
images, has_nsfw_concepts = self.safety_checker(images)
|
| 281 |
-
if any(has_nsfw_concepts):
|
| 282 |
-
return None
|
| 283 |
-
|
| 284 |
-
result_image = images[0]
|
| 285 |
if params.debug_canny:
|
| 286 |
# paste control_image on top of result_image
|
| 287 |
w0, h0 = (200, 200)
|
|
|
|
| 7 |
from compel import Compel, ReturnedEmbeddingsType
|
| 8 |
import torch
|
| 9 |
from pipelines.utils.canny_gpu import SobelOperator
|
|
|
|
| 10 |
|
| 11 |
try:
|
| 12 |
import intel_extension_for_pytorch as ipex # type: ignore
|
|
|
|
| 170 |
vae = AutoencoderKL.from_pretrained(
|
| 171 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch_dtype
|
| 172 |
)
|
|
|
|
|
|
|
|
|
|
| 173 |
|
| 174 |
self.pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
|
| 175 |
model_id,
|
|
|
|
| 270 |
control_guidance_start=params.controlnet_start,
|
| 271 |
control_guidance_end=params.controlnet_end,
|
| 272 |
)
|
| 273 |
+
result_image = results.images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 274 |
if params.debug_canny:
|
| 275 |
# paste control_image on top of result_image
|
| 276 |
w0, h0 = (200, 200)
|
server/pipelines/controlnetSegmindVegaRT.py
CHANGED
|
@@ -173,19 +173,12 @@ class Pipeline:
|
|
| 173 |
vae = AutoencoderKL.from_pretrained(
|
| 174 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch_dtype
|
| 175 |
)
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
else:
|
| 183 |
-
self.pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
|
| 184 |
-
base_model,
|
| 185 |
-
safety_checker=None,
|
| 186 |
-
controlnet=controlnet_canny,
|
| 187 |
-
vae=vae,
|
| 188 |
-
)
|
| 189 |
self.canny_torch = SobelOperator(device=device)
|
| 190 |
|
| 191 |
self.pipe.load_lora_weights(lora_model)
|
|
@@ -285,13 +278,6 @@ class Pipeline:
|
|
| 285 |
control_guidance_end=params.controlnet_end,
|
| 286 |
)
|
| 287 |
|
| 288 |
-
nsfw_content_detected = (
|
| 289 |
-
results.nsfw_content_detected[0]
|
| 290 |
-
if "nsfw_content_detected" in results
|
| 291 |
-
else False
|
| 292 |
-
)
|
| 293 |
-
if nsfw_content_detected:
|
| 294 |
-
return None
|
| 295 |
result_image = results.images[0]
|
| 296 |
if params.debug_canny:
|
| 297 |
# paste control_image on top of result_image
|
|
|
|
| 173 |
vae = AutoencoderKL.from_pretrained(
|
| 174 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch_dtype
|
| 175 |
)
|
| 176 |
+
self.pipe = StableDiffusionXLControlNetImg2ImgPipeline.from_pretrained(
|
| 177 |
+
base_model,
|
| 178 |
+
safety_checker=None,
|
| 179 |
+
controlnet=controlnet_canny,
|
| 180 |
+
vae=vae,
|
| 181 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
self.canny_torch = SobelOperator(device=device)
|
| 183 |
|
| 184 |
self.pipe.load_lora_weights(lora_model)
|
|
|
|
| 278 |
control_guidance_end=params.controlnet_end,
|
| 279 |
)
|
| 280 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
result_image = results.images[0]
|
| 282 |
if params.debug_canny:
|
| 283 |
# paste control_image on top of result_image
|
server/pipelines/img2img.py
CHANGED
|
@@ -95,13 +95,10 @@ class Pipeline:
|
|
| 95 |
)
|
| 96 |
|
| 97 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
base_model,
|
| 103 |
-
safety_checker=None,
|
| 104 |
-
)
|
| 105 |
if args.taesd:
|
| 106 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
| 107 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
@@ -171,13 +168,4 @@ class Pipeline:
|
|
| 171 |
output_type="pil",
|
| 172 |
)
|
| 173 |
|
| 174 |
-
|
| 175 |
-
results.nsfw_content_detected[0]
|
| 176 |
-
if "nsfw_content_detected" in results
|
| 177 |
-
else False
|
| 178 |
-
)
|
| 179 |
-
if nsfw_content_detected:
|
| 180 |
-
return None
|
| 181 |
-
result_image = results.images[0]
|
| 182 |
-
|
| 183 |
-
return result_image
|
|
|
|
| 95 |
)
|
| 96 |
|
| 97 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
| 98 |
+
self.pipe = AutoPipelineForImage2Image.from_pretrained(
|
| 99 |
+
base_model,
|
| 100 |
+
safety_checker=None,
|
| 101 |
+
)
|
|
|
|
|
|
|
|
|
|
| 102 |
if args.taesd:
|
| 103 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
| 104 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
|
|
| 168 |
output_type="pil",
|
| 169 |
)
|
| 170 |
|
| 171 |
+
return results.images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/pipelines/img2imgSDTurbo.py
CHANGED
|
@@ -93,13 +93,10 @@ class Pipeline:
|
|
| 93 |
)
|
| 94 |
|
| 95 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
base_model,
|
| 101 |
-
safety_checker=None,
|
| 102 |
-
)
|
| 103 |
if args.taesd:
|
| 104 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
| 105 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
@@ -187,13 +184,4 @@ class Pipeline:
|
|
| 187 |
output_type="pil",
|
| 188 |
)
|
| 189 |
|
| 190 |
-
|
| 191 |
-
results.nsfw_content_detected[0]
|
| 192 |
-
if "nsfw_content_detected" in results
|
| 193 |
-
else False
|
| 194 |
-
)
|
| 195 |
-
if nsfw_content_detected:
|
| 196 |
-
return None
|
| 197 |
-
result_image = results.images[0]
|
| 198 |
-
|
| 199 |
-
return result_image
|
|
|
|
| 93 |
)
|
| 94 |
|
| 95 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
| 96 |
+
self.pipe = AutoPipelineForImage2Image.from_pretrained(
|
| 97 |
+
base_model,
|
| 98 |
+
safety_checker=None,
|
| 99 |
+
)
|
|
|
|
|
|
|
|
|
|
| 100 |
if args.taesd:
|
| 101 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
| 102 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
|
|
| 184 |
output_type="pil",
|
| 185 |
)
|
| 186 |
|
| 187 |
+
return results.images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/pipelines/img2imgSDXL-Lightning.py
CHANGED
|
@@ -110,7 +110,6 @@ class Pipeline:
|
|
| 110 |
)
|
| 111 |
|
| 112 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
| 113 |
-
|
| 114 |
if args.taesd:
|
| 115 |
vae = AutoencoderTiny.from_pretrained(
|
| 116 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
@@ -214,13 +213,4 @@ class Pipeline:
|
|
| 214 |
output_type="pil",
|
| 215 |
)
|
| 216 |
|
| 217 |
-
|
| 218 |
-
results.nsfw_content_detected[0]
|
| 219 |
-
if "nsfw_content_detected" in results
|
| 220 |
-
else False
|
| 221 |
-
)
|
| 222 |
-
if nsfw_content_detected:
|
| 223 |
-
return None
|
| 224 |
-
result_image = results.images[0]
|
| 225 |
-
|
| 226 |
-
return result_image
|
|
|
|
| 110 |
)
|
| 111 |
|
| 112 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
|
|
|
| 113 |
if args.taesd:
|
| 114 |
vae = AutoencoderTiny.from_pretrained(
|
| 115 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
|
|
| 213 |
output_type="pil",
|
| 214 |
)
|
| 215 |
|
| 216 |
+
return results.images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/pipelines/img2imgSDXLTurbo.py
CHANGED
|
@@ -103,13 +103,10 @@ class Pipeline:
|
|
| 103 |
)
|
| 104 |
|
| 105 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
base_model,
|
| 111 |
-
safety_checker=None,
|
| 112 |
-
)
|
| 113 |
if args.taesd:
|
| 114 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
| 115 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
@@ -194,13 +191,4 @@ class Pipeline:
|
|
| 194 |
output_type="pil",
|
| 195 |
)
|
| 196 |
|
| 197 |
-
|
| 198 |
-
results.nsfw_content_detected[0]
|
| 199 |
-
if "nsfw_content_detected" in results
|
| 200 |
-
else False
|
| 201 |
-
)
|
| 202 |
-
if nsfw_content_detected:
|
| 203 |
-
return None
|
| 204 |
-
result_image = results.images[0]
|
| 205 |
-
|
| 206 |
-
return result_image
|
|
|
|
| 103 |
)
|
| 104 |
|
| 105 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
| 106 |
+
self.pipe = AutoPipelineForImage2Image.from_pretrained(
|
| 107 |
+
base_model,
|
| 108 |
+
safety_checker=None,
|
| 109 |
+
)
|
|
|
|
|
|
|
|
|
|
| 110 |
if args.taesd:
|
| 111 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
| 112 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
|
|
| 191 |
output_type="pil",
|
| 192 |
)
|
| 193 |
|
| 194 |
+
return results.images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/pipelines/img2imgSDXS512.py
CHANGED
|
@@ -92,13 +92,10 @@ class Pipeline:
|
|
| 92 |
)
|
| 93 |
|
| 94 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
base_model,
|
| 100 |
-
safety_checker=None,
|
| 101 |
-
)
|
| 102 |
if args.taesd:
|
| 103 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
| 104 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
@@ -162,14 +159,4 @@ class Pipeline:
|
|
| 162 |
height=params.height,
|
| 163 |
output_type="pil",
|
| 164 |
)
|
| 165 |
-
|
| 166 |
-
nsfw_content_detected = (
|
| 167 |
-
results.nsfw_content_detected[0]
|
| 168 |
-
if "nsfw_content_detected" in results
|
| 169 |
-
else False
|
| 170 |
-
)
|
| 171 |
-
if nsfw_content_detected:
|
| 172 |
-
return None
|
| 173 |
-
result_image = results.images[0]
|
| 174 |
-
|
| 175 |
-
return result_image
|
|
|
|
| 92 |
)
|
| 93 |
|
| 94 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
| 95 |
+
self.pipe = AutoPipelineForImage2Image.from_pretrained(
|
| 96 |
+
base_model,
|
| 97 |
+
safety_checker=None,
|
| 98 |
+
)
|
|
|
|
|
|
|
|
|
|
| 99 |
if args.taesd:
|
| 100 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
| 101 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
|
|
| 159 |
height=params.height,
|
| 160 |
output_type="pil",
|
| 161 |
)
|
| 162 |
+
return results.images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/pipelines/img2imgSegmindVegaRT.py
CHANGED
|
@@ -105,17 +105,11 @@ class Pipeline:
|
|
| 105 |
)
|
| 106 |
|
| 107 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
else:
|
| 114 |
-
self.pipe = AutoPipelineForImage2Image.from_pretrained(
|
| 115 |
-
base_model,
|
| 116 |
-
safety_checker=None,
|
| 117 |
-
variant="fp16",
|
| 118 |
-
)
|
| 119 |
if args.taesd:
|
| 120 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
| 121 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
@@ -205,13 +199,4 @@ class Pipeline:
|
|
| 205 |
output_type="pil",
|
| 206 |
)
|
| 207 |
|
| 208 |
-
|
| 209 |
-
results.nsfw_content_detected[0]
|
| 210 |
-
if "nsfw_content_detected" in results
|
| 211 |
-
else False
|
| 212 |
-
)
|
| 213 |
-
if nsfw_content_detected:
|
| 214 |
-
return None
|
| 215 |
-
result_image = results.images[0]
|
| 216 |
-
|
| 217 |
-
return result_image
|
|
|
|
| 105 |
)
|
| 106 |
|
| 107 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
| 108 |
+
self.pipe = AutoPipelineForImage2Image.from_pretrained(
|
| 109 |
+
base_model,
|
| 110 |
+
safety_checker=None,
|
| 111 |
+
variant="fp16",
|
| 112 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
if args.taesd:
|
| 114 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
| 115 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
|
|
| 199 |
output_type="pil",
|
| 200 |
)
|
| 201 |
|
| 202 |
+
return results.images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/pipelines/txt2img.py
CHANGED
|
@@ -79,12 +79,7 @@ class Pipeline:
|
|
| 79 |
)
|
| 80 |
|
| 81 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
| 82 |
-
|
| 83 |
-
self.pipe = DiffusionPipeline.from_pretrained(base_model)
|
| 84 |
-
else:
|
| 85 |
-
self.pipe = DiffusionPipeline.from_pretrained(
|
| 86 |
-
base_model, safety_checker=None
|
| 87 |
-
)
|
| 88 |
if args.taesd:
|
| 89 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
| 90 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
@@ -142,11 +137,5 @@ class Pipeline:
|
|
| 142 |
height=params.height,
|
| 143 |
output_type="pil",
|
| 144 |
)
|
| 145 |
-
|
| 146 |
-
results.nsfw_content_detected[0]
|
| 147 |
-
if "nsfw_content_detected" in results
|
| 148 |
-
else False
|
| 149 |
-
)
|
| 150 |
-
if nsfw_content_detected:
|
| 151 |
-
return None
|
| 152 |
return results.images[0]
|
|
|
|
| 79 |
)
|
| 80 |
|
| 81 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
| 82 |
+
self.pipe = DiffusionPipeline.from_pretrained(base_model, safety_checker=None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
if args.taesd:
|
| 84 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
| 85 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
|
|
| 137 |
height=params.height,
|
| 138 |
output_type="pil",
|
| 139 |
)
|
| 140 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
return results.images[0]
|
server/pipelines/txt2imgLora.py
CHANGED
|
@@ -86,12 +86,7 @@ class Pipeline:
|
|
| 86 |
)
|
| 87 |
|
| 88 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
| 89 |
-
|
| 90 |
-
self.pipe = DiffusionPipeline.from_pretrained(base_model)
|
| 91 |
-
else:
|
| 92 |
-
self.pipe = DiffusionPipeline.from_pretrained(
|
| 93 |
-
base_model, safety_checker=None
|
| 94 |
-
)
|
| 95 |
if args.taesd:
|
| 96 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
| 97 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
@@ -152,11 +147,5 @@ class Pipeline:
|
|
| 152 |
height=params.height,
|
| 153 |
output_type="pil",
|
| 154 |
)
|
| 155 |
-
|
| 156 |
-
results.nsfw_content_detected[0]
|
| 157 |
-
if "nsfw_content_detected" in results
|
| 158 |
-
else False
|
| 159 |
-
)
|
| 160 |
-
if nsfw_content_detected:
|
| 161 |
-
return None
|
| 162 |
return results.images[0]
|
|
|
|
| 86 |
)
|
| 87 |
|
| 88 |
def __init__(self, args: Args, device: torch.device, torch_dtype: torch.dtype):
|
| 89 |
+
self.pipe = DiffusionPipeline.from_pretrained(base_model, safety_checker=None)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
if args.taesd:
|
| 91 |
self.pipe.vae = AutoencoderTiny.from_pretrained(
|
| 92 |
taesd_model, torch_dtype=torch_dtype, use_safetensors=True
|
|
|
|
| 147 |
height=params.height,
|
| 148 |
output_type="pil",
|
| 149 |
)
|
| 150 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
return results.images[0]
|
server/pipelines/txt2imgLoraSDXL.py
CHANGED
|
@@ -95,17 +95,12 @@ class Pipeline:
|
|
| 95 |
vae = AutoencoderKL.from_pretrained(
|
| 96 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch_dtype
|
| 97 |
)
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
self.pipe = DiffusionPipeline.from_pretrained(
|
| 105 |
-
model_id,
|
| 106 |
-
safety_checker=None,
|
| 107 |
-
vae=vae,
|
| 108 |
-
)
|
| 109 |
# Load LCM LoRA
|
| 110 |
self.pipe.load_lora_weights(lcm_lora_id, adapter_name="lcm")
|
| 111 |
self.pipe.scheduler = LCMScheduler.from_config(self.pipe.scheduler.config)
|
|
@@ -184,13 +179,4 @@ class Pipeline:
|
|
| 184 |
output_type="pil",
|
| 185 |
)
|
| 186 |
|
| 187 |
-
|
| 188 |
-
results.nsfw_content_detected[0]
|
| 189 |
-
if "nsfw_content_detected" in results
|
| 190 |
-
else False
|
| 191 |
-
)
|
| 192 |
-
if nsfw_content_detected:
|
| 193 |
-
return None
|
| 194 |
-
result_image = results.images[0]
|
| 195 |
-
|
| 196 |
-
return result_image
|
|
|
|
| 95 |
vae = AutoencoderKL.from_pretrained(
|
| 96 |
"madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch_dtype
|
| 97 |
)
|
| 98 |
+
|
| 99 |
+
self.pipe = DiffusionPipeline.from_pretrained(
|
| 100 |
+
model_id,
|
| 101 |
+
safety_checker=None,
|
| 102 |
+
vae=vae,
|
| 103 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
# Load LCM LoRA
|
| 105 |
self.pipe.load_lora_weights(lcm_lora_id, adapter_name="lcm")
|
| 106 |
self.pipe.scheduler = LCMScheduler.from_config(self.pipe.scheduler.config)
|
|
|
|
| 179 |
output_type="pil",
|
| 180 |
)
|
| 181 |
|
| 182 |
+
return results.images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server/pipelines/utils/safety_checker.py
CHANGED
|
@@ -150,14 +150,20 @@ class SafetyChecker:
|
|
| 150 |
)
|
| 151 |
|
| 152 |
def __call__(
|
| 153 |
-
self, images: list[Image.Image]
|
| 154 |
-
) -> tuple[list[Image.Image], list[bool]]:
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
|
|
|
|
|
|
|
|
|
| 158 |
has_nsfw_concepts = self.safety_checker(
|
| 159 |
-
images=[
|
| 160 |
clip_input=safety_checker_input.pixel_values.to(self.device),
|
| 161 |
)
|
| 162 |
|
|
|
|
|
|
|
|
|
|
| 163 |
return images, has_nsfw_concepts
|
|
|
|
| 150 |
)
|
| 151 |
|
| 152 |
def __call__(
|
| 153 |
+
self, images: list[Image.Image] | Image.Image
|
| 154 |
+
) -> tuple[list[Image.Image], list[bool]] | tuple[Image.Image, bool]:
|
| 155 |
+
images_list = [images] if isinstance(images, Image.Image) else images
|
| 156 |
+
|
| 157 |
+
safety_checker_input = self.feature_extractor(
|
| 158 |
+
images_list, return_tensors="pt"
|
| 159 |
+
).to(self.device)
|
| 160 |
+
|
| 161 |
has_nsfw_concepts = self.safety_checker(
|
| 162 |
+
images=[images_list],
|
| 163 |
clip_input=safety_checker_input.pixel_values.to(self.device),
|
| 164 |
)
|
| 165 |
|
| 166 |
+
if isinstance(images, Image.Image):
|
| 167 |
+
return images, has_nsfw_concepts[0]
|
| 168 |
+
|
| 169 |
return images, has_nsfw_concepts
|