diff --git a/modules/history.py b/modules/history.py index 7caa0251e..62166b895 100644 --- a/modules/history.py +++ b/modules/history.py @@ -48,6 +48,9 @@ class History: self.index = -1 self.latents = deque(maxlen=1024) + def __str__(self): + return f'History(count={self.count} size={self.size})' + @property def count(self): return len(self.latents) @@ -71,8 +74,13 @@ class History: self.index = -1 else: current_index = 0 - item = self.latents[current_index] + while abs(current_index) <= self.count: + item = self.latents[current_index] + if item.latent is not None: + break + current_index -= 1 if item.latent is None: + print('HERE') return None, -1 log.debug(f'History get: index={current_index} time={item.ts} shape={list(item.latent.shape)} dtype={item.latent.dtype} count={self.count}') return item.latent.to(devices.device), current_index diff --git a/modules/processing_args.py b/modules/processing_args.py index 0da3c01ea..6f3305e62 100644 --- a/modules/processing_args.py +++ b/modules/processing_args.py @@ -323,12 +323,12 @@ def set_pipeline_args(p, model, prompts:list, negative_prompts:list, prompts_2:l elif 'callback' in possible: args['callback'] = diffusers_callback_legacy - if 'image' in kwargs: - if isinstance(kwargs['image'], list) and isinstance(kwargs['image'][0], Image.Image): + if 'image' in kwargs and kwargs['image'] is not None: + if isinstance(kwargs['image'], list) and len(kwargs['image']) > 0 and isinstance(kwargs['image'][0], Image.Image): p.init_images = kwargs['image'] - if isinstance(kwargs['image'], Image.Image): + elif isinstance(kwargs['image'], Image.Image): p.init_images = [kwargs['image']] - if isinstance(kwargs['image'], torch.Tensor): + elif isinstance(kwargs['image'], torch.Tensor): p.init_images = kwargs['image'] # handle remaining args diff --git a/modules/processing_diffusers.py b/modules/processing_diffusers.py index 3db699aff..b7b1030ef 100644 --- a/modules/processing_diffusers.py +++ b/modules/processing_diffusers.py @@ -599,8 +599,9 @@ def process_diffusers(p: processing.StableDiffusionProcessing): if 'base' not in p.skip: output = process_base(p) else: - images, _index=shared.history.selected - output = SimpleNamespace(images=images) + # images, _index = shared.history.selected + images = shared.history.last_latent + output = SimpleNamespace(images=images) if images is not None else None if (output is None or (hasattr(output, 'images') and len(output.images) == 0)) and has_images: if output is not None: