Skip to content

Commit

Permalink
fix image processing with controlnet
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyongliang committed Mar 5, 2023
1 parent 5078ae9 commit c9bf1d3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
22 changes: 20 additions & 2 deletions modules/call_queue.py
Expand Up @@ -81,7 +81,16 @@ def sagemaker_inference(task, infer, username, sagemaker_endpoint, *args, **kwar
if task == 'text-to-image':
script_args = []
for i in range(23, len(args)):
script_args.append(args[i])
if(isinstance(args[i], dict)):
script_arg = {}
for key in args[i]:
if key == 'image' or key == 'mask':
script_arg[key] = encode_image_to_base64(Image.fromarray(args[i][key]))
else:
script_arg[key] = args[i][key]
script_args.append(script_arg)
else:
script_args.append(args[i])

prompt = args[0]
negative_prompt = args[1]
Expand Down Expand Up @@ -180,7 +189,16 @@ def sagemaker_inference(task, infer, username, sagemaker_endpoint, *args, **kwar

script_args = []
for i in range(36, len(args)):
script_args.append(args[i])
if(isinstance(args[i], dict)):
script_arg = {}
for key in args[i]:
if key == 'image' or key == 'mask':
script_arg[key] = encode_image_to_base64(Image.fromarray(args[i][key]))
else:
script_arg[key] = args[i][key]
script_args.append(script_arg)
else:
script_args.append(args[i])

if mode == 1:
# Drawn mask
Expand Down
9 changes: 7 additions & 2 deletions modules/processing.py
Expand Up @@ -21,7 +21,8 @@
import modules.images as images
import modules.styles
import logging

import base64
import io

# some of those options should not be changed at all because they would break the model, so I removed them from options.
opt_C = 4
Expand Down Expand Up @@ -117,14 +118,18 @@ def __init__(self, sd_model=None, outpath_samples=None, outpath_grids=None, prom

self.script_args = json.loads(script_args) if script_args != None else None

if self.script_args:
for key in self.script_args:
if key == 'image' or key == 'mask':
self.script_arg[key] = Image.open(io.BytesIO(base64.b64decode(self.script_args[key])))

if not seed_enable_extras:
self.subseed = -1
self.subseed_strength = 0
self.seed_resize_from_h = 0
self.seed_resize_from_w = 0

self.scripts = None
self.script_args = None
self.all_prompts = None
self.all_negative_prompts = None
self.all_seeds = None
Expand Down

0 comments on commit c9bf1d3

Please sign in to comment.