Commit
·
5e07795
1
Parent(s):
b44b2d7
fix handler
Browse files- handler.py +9 -31
handler.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
#
|
| 2 |
import io, base64
|
| 3 |
from PIL import Image
|
| 4 |
import torch
|
|
@@ -6,30 +6,17 @@ from diffusers import StableDiffusionXLInpaintPipeline
|
|
| 6 |
|
| 7 |
class EndpointHandler:
|
| 8 |
def __init__(self, path="."):
|
| 9 |
-
print("
|
| 10 |
model_id = "andro-flock/LUSTIFY-SDXL-NSFW-checkpoint-v2-0-INPAINTING"
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
model_id, torch_dtype=torch.float16, use_safetensors=True
|
| 16 |
-
).to("cuda")
|
| 17 |
-
except Exception as e:
|
| 18 |
-
print("fp16 failed -> trying bf16:", e)
|
| 19 |
-
try:
|
| 20 |
-
self.pipe = StableDiffusionXLInpaintPipeline.from_pretrained(
|
| 21 |
-
model_id, torch_dtype=torch.bfloat16, use_safetensors=True
|
| 22 |
-
).to("cuda")
|
| 23 |
-
except Exception as e2:
|
| 24 |
-
print("bf16 failed -> using fp32:", e2)
|
| 25 |
-
self.pipe = StableDiffusionXLInpaintPipeline.from_pretrained(
|
| 26 |
-
model_id, torch_dtype=torch.float32, use_safetensors=True
|
| 27 |
-
).to("cuda")
|
| 28 |
-
|
| 29 |
self.pipe.enable_attention_slicing()
|
| 30 |
|
| 31 |
def _to_pil(self, data, mode):
|
| 32 |
if isinstance(data, str):
|
|
|
|
| 33 |
data = base64.b64decode(data)
|
| 34 |
return Image.open(io.BytesIO(data)).convert(mode)
|
| 35 |
|
|
@@ -37,19 +24,10 @@ class EndpointHandler:
|
|
| 37 |
prompt = data.get("prompt", "")
|
| 38 |
init_img = self._to_pil(data["image"], "RGB")
|
| 39 |
mask_img = self._to_pil(data["mask"], "L") # white=repaint, black=keep
|
| 40 |
-
|
| 41 |
steps = int(data.get("num_inference_steps", 30))
|
| 42 |
guidance = float(data.get("guidance_scale", 7.0))
|
| 43 |
strength = float(data.get("strength", 0.85))
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
prompt=prompt,
|
| 47 |
-
image=init_img,
|
| 48 |
-
mask_image=mask_img,
|
| 49 |
-
num_inference_steps=steps,
|
| 50 |
-
guidance_scale=guidance,
|
| 51 |
-
strength=strength
|
| 52 |
-
).images[0]
|
| 53 |
-
|
| 54 |
buf = io.BytesIO(); out.save(buf, format="PNG")
|
| 55 |
return {"image_base64": base64.b64encode(buf.getvalue()).decode()}
|
|
|
|
| 1 |
+
# HANDLER_MARKER_2025-08-29
|
| 2 |
import io, base64
|
| 3 |
from PIL import Image
|
| 4 |
import torch
|
|
|
|
| 6 |
|
| 7 |
class EndpointHandler:
|
| 8 |
def __init__(self, path="."):
|
| 9 |
+
print("HANDLER_MARKER_2025-08-29: loading WITHOUT variant arg")
|
| 10 |
model_id = "andro-flock/LUSTIFY-SDXL-NSFW-checkpoint-v2-0-INPAINTING"
|
| 11 |
+
# NO variant= here
|
| 12 |
+
self.pipe = StableDiffusionXLInpaintPipeline.from_pretrained(
|
| 13 |
+
model_id, torch_dtype=torch.float16, use_safetensors=True
|
| 14 |
+
).to("cuda")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
self.pipe.enable_attention_slicing()
|
| 16 |
|
| 17 |
def _to_pil(self, data, mode):
|
| 18 |
if isinstance(data, str):
|
| 19 |
+
import base64, io
|
| 20 |
data = base64.b64decode(data)
|
| 21 |
return Image.open(io.BytesIO(data)).convert(mode)
|
| 22 |
|
|
|
|
| 24 |
prompt = data.get("prompt", "")
|
| 25 |
init_img = self._to_pil(data["image"], "RGB")
|
| 26 |
mask_img = self._to_pil(data["mask"], "L") # white=repaint, black=keep
|
|
|
|
| 27 |
steps = int(data.get("num_inference_steps", 30))
|
| 28 |
guidance = float(data.get("guidance_scale", 7.0))
|
| 29 |
strength = float(data.get("strength", 0.85))
|
| 30 |
+
out = self.pipe(prompt=prompt, image=init_img, mask_image=mask_img,
|
| 31 |
+
num_inference_steps=steps, guidance_scale=guidance, strength=strength).images[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
buf = io.BytesIO(); out.save(buf, format="PNG")
|
| 33 |
return {"image_base64": base64.b64encode(buf.getvalue()).decode()}
|