mirror of
https://github.com/vladmandic/sdnext.git
synced 2026-01-27 15:02:48 +03:00
ipadapter masks api support
This commit is contained in:
@@ -95,7 +95,7 @@ class APIControl():
|
||||
|
||||
def prepare_ip_adapter(self, request):
|
||||
if hasattr(request, "ip_adapter") and request.ip_adapter:
|
||||
args = { 'ip_adapter_names': [], 'ip_adapter_scales': [], 'ip_adapter_starts': [], 'ip_adapter_ends': [], 'ip_adapter_images': [] }
|
||||
args = { 'ip_adapter_names': [], 'ip_adapter_scales': [], 'ip_adapter_starts': [], 'ip_adapter_ends': [], 'ip_adapter_images': [], 'ip_adapter_masks': [] }
|
||||
for ipadapter in request.ip_adapter:
|
||||
if not ipadapter.images or len(ipadapter.images) == 0:
|
||||
continue
|
||||
@@ -104,6 +104,9 @@ class APIControl():
|
||||
args['ip_adapter_starts'].append(ipadapter.start)
|
||||
args['ip_adapter_ends'].append(ipadapter.end)
|
||||
args['ip_adapter_images'].append([helpers.decode_base64_to_image(x) for x in ipadapter.images])
|
||||
if ipadapter.masks:
|
||||
args['ip_adapter_masks'].append([helpers.decode_base64_to_image(x) for x in ipadapter.masks])
|
||||
|
||||
del request.ip_adapter
|
||||
return args
|
||||
else:
|
||||
|
||||
@@ -67,7 +67,6 @@ class APIGenerate():
|
||||
p.ip_adapter_starts = []
|
||||
p.ip_adapter_ends = []
|
||||
p.ip_adapter_images = []
|
||||
p.ip_adapter_masks = []
|
||||
for ipadapter in request.ip_adapter:
|
||||
if not ipadapter.images or len(ipadapter.images) == 0:
|
||||
continue
|
||||
@@ -76,7 +75,9 @@ class APIGenerate():
|
||||
p.ip_adapter_starts.append(ipadapter.start)
|
||||
p.ip_adapter_ends.append(ipadapter.end)
|
||||
p.ip_adapter_images.append([helpers.decode_base64_to_image(x) for x in ipadapter.images])
|
||||
p.ip_adapter_masks.append([helpers.decode_base64_to_image(x) for x in ipadapter.masks])
|
||||
p.ip_adapter_masks = []
|
||||
if ipadapter.masks:
|
||||
p.ip_adapter_masks.append([helpers.decode_base64_to_image(x) for x in ipadapter.masks])
|
||||
del request.ip_adapter
|
||||
|
||||
def post_text2img(self, txt2imgreq: models.ReqTxt2Img):
|
||||
|
||||
@@ -45,7 +45,9 @@ def get_images(input_images):
|
||||
if not isinstance(input_images, list):
|
||||
input_images = [input_images]
|
||||
for image in input_images:
|
||||
if isinstance(image, list):
|
||||
if image is None:
|
||||
continue
|
||||
elif isinstance(image, list):
|
||||
output_images.append(get_images(image)) # recursive
|
||||
elif isinstance(image, Image.Image):
|
||||
output_images.append(image)
|
||||
@@ -108,9 +110,11 @@ def apply(pipe, p: processing.StableDiffusionProcessing, adapter_names=[], adapt
|
||||
if hasattr(p, 'ip_adapter_images'):
|
||||
adapter_images = p.ip_adapter_images
|
||||
adapter_images = get_images(adapter_images)
|
||||
if hasattr(p, 'ip_adapter_masks'):
|
||||
if hasattr(p, 'ip_adapter_masks') and len(p.ip_adapter_masks) > 0:
|
||||
adapter_masks = p.ip_adapter_masks
|
||||
adapter_masks = get_images(adapter_masks)
|
||||
adapter_masks = get_images(adapter_masks)
|
||||
else:
|
||||
adapter_masks = []
|
||||
if len(adapter_masks) > 0:
|
||||
from diffusers.image_processor import IPAdapterMaskProcessor
|
||||
mask_processor = IPAdapterMaskProcessor()
|
||||
|
||||
@@ -22,9 +22,7 @@ psutil
|
||||
pyyaml
|
||||
resize-right
|
||||
rich
|
||||
safetensors
|
||||
scipy
|
||||
tensordict==0.1.2
|
||||
toml
|
||||
torchdiffeq
|
||||
voluptuous
|
||||
@@ -33,8 +31,10 @@ scikit-image
|
||||
fasteners
|
||||
dctorch
|
||||
pymatting
|
||||
peft
|
||||
orjson
|
||||
safetensors==0.4.3
|
||||
tensordict==0.1.2
|
||||
peft==0.10.0
|
||||
httpx==0.24.1
|
||||
compel==2.0.2
|
||||
torchsde==0.2.6
|
||||
@@ -42,7 +42,7 @@ clip-interrogator==0.6.0
|
||||
antlr4-python3-runtime==4.9.3
|
||||
requests==2.31.0
|
||||
tqdm==4.66.2
|
||||
accelerate==0.29.1
|
||||
accelerate==0.29.3
|
||||
opencv-contrib-python-headless==4.9.0.80
|
||||
diffusers==0.27.2
|
||||
einops==0.4.1
|
||||
@@ -54,11 +54,11 @@ numba==0.59.1
|
||||
pandas
|
||||
protobuf==3.20.3
|
||||
pytorch_lightning==1.9.4
|
||||
tokenizers==0.15.2
|
||||
transformers==4.39.3
|
||||
tokenizers==0.19.1
|
||||
transformers==4.40.0
|
||||
tomesd==0.1.3
|
||||
urllib3==1.26.18
|
||||
Pillow==10.3.0
|
||||
timm==0.9.16
|
||||
pydantic==1.10.13
|
||||
pydantic==1.10.15
|
||||
typing-extensions==4.11.0
|
||||
@@ -93,4 +93,5 @@ class Script(scripts.Script):
|
||||
p.ip_adapter_ends = args[MAX_ADAPTERS*4:MAX_ADAPTERS*5][:units]
|
||||
if getattr(p, 'ip_adapter_masks', []) == []:
|
||||
p.ip_adapter_masks = args[MAX_ADAPTERS*5:MAX_ADAPTERS*6][:units]
|
||||
p.ip_adapter_masks = [x for x in p.ip_adapter_masks if x]
|
||||
# ipadapter.apply(shared.sd_model, p, p.ip_adapter_names, p.ip_adapter_scales, p.ip_adapter_starts, p.ip_adapter_ends, p.ip_adapter_images) # called directly from processing.process_images_inner
|
||||
|
||||
Reference in New Issue
Block a user