Extras Tab Clears Infotext
Version: f2.0.1v1.10.1-previous-527-g720b80da
Description If there is a setting for this I am missing please let me know, I tried searching the settings for infotext and couldn't find anything. In previous versions, the extras tab would keep the infotext from txt2img or img2img and just add onto it, but with the current version it seems like the extras tab just clears the infotext because after passing a txt2img image with infotext through, even when disabling all upscaling/modifications, it just says none under parameters.
I did some digging and I think the issue might be with the use of ForgeCanvas in modules/ui_postprocessing.py:
extras_image = ForgeCanvas(elem_id="extras_image", height=512, no_scribbles=True).background
This line is different from AUTO1111 and the previous tag in which it is
extras_image = gr.Image(label="Source", source="upload", interactive=True, type="pil", elem_id="extras_image")
It expects to get some data down the pipeline in image.info from a PIL image and if you check the images output from txt2img and img2img in PIL they do have some image.info data, but the dict is empty if you follow the postprocessing pipeline. I think that by switching to using ForgeCanvas it might be throwing away that data but I'm not 100% sure. The img2img and inpaint tabs also use the new canvas but they are able to retain the metadata and I'm not sure what they do differently.
Just in case anyone has the same issue as me and finds this issue, and since this is still broken for me in main and I can't make a pull request, here is what I did to fix it.
The problem occurs because when the image is added to the canvas it is added to a custom gradio textbox object called LogicalImage that stores the base64 encoded version of the image. When the image is converted to base64 it loses the information contained in the image's metadata so that when it is converted back from base64 to an image again the generation information is lost. This doesn't occur in inpaint and img2img because the infotext is actually recreated from the information available on the img2img tab, but when passing it through the postprocessing pipeline it doesn't regenerate the infotext and expects it to be forwarded with the image data.
The solution is to store the infotext before converting it to base64 and and restore it after converting it back to an image. to do that, navigate to modules_forge/forge_canvas/canvas.py and change the class definition for LogicalImage to:
class LogicalImage(gr.Textbox):
@wraps(gr.Textbox.__init__)
def __init__(self, *args, numpy=True, **kwargs):
self.numpy = numpy
self.infotext = dict() # Create an empty dict here
if 'value' in kwargs:
initial_value = kwargs['value']
if initial_value is not None:
kwargs['value'] = self.image_to_base64(initial_value)
else:
del kwargs['value']
super().__init__(*args, **kwargs)
def preprocess(self, payload):
if not isinstance(payload, str):
return None
if not payload.startswith("data:image/png;base64,"):
return None
image = base64_to_image(payload, numpy=self.numpy)
image.info = self.infotext # Restore the infotext after converting back to an image
return image
def postprocess(self, value):
if value is None:
return None
self.infotext = value.info # Save the infotext before converting to base64
return image_to_base64(value, numpy=self.numpy)
def get_block_name(self):
return "textbox"
This fixes the infotext after saving from the extras tab. I haven't fully tested this and from my review of the code it may not work when using controlnet since that converts the image from a PIL image to a numpy array which would also discard the infotext.
Thanks for this!