stable-diffusion-webui
stable-diffusion-webui copied to clipboard
Regional outpainting prototype.
Process outlined and demonstrated in #3507 . Uses gradio's selection tool to get the region from img2img, it is a bit clunky but gets the job done. The additional components required were hastily thrown onto the tab, not sure where exactly they should be (leaning towards a separate tab but haven't really looked into it). Note that I tested it on a slightly modified local version (all requirements and repo version checks disabled, installed and cloned the latest versions manually), so YMMV.
Might be a good idea to make the image component on the separate tab larger, or even screen width fitting; preferably with the source zoomed out. I find that the biggest annoyances though are having to wipe the image to get "send to img2img" to work in selection state (might be possible to automate), and then manually reentering the selection state (with the cropbox reset).
Seems that it doesn't work with jpgs (or likely any non-png images), I'm getting the PIL.UnidentifiedImageError for any such outpainting attempts. Looks like the srcimg decoding segment in img2img needs to handle more formats.
if srcimg.startswith("data:image/png;base64,"):
srcimg = srcimg[len("data:image/png;base64,"):]
srcimg_b = base64.decodebytes(srcimg.encode('utf-8'))
srcimg_pil = Image.open(io.BytesIO(srcimg_b))
Alright, fixed it. Might be preferable to tweak the code in a similar manner for the instances in ui.py and api.py:
srcimg_b = base64.b64decode(srcimg.split(",")[-1])
srcimg_pil = Image.open(io.BytesIO(srcimg_b))
Added a tab for outpainting. Has some small issues: Haven't delved into the parameter separation (visit?), so other than the renamed label "outpaint content" values default to the same as img2img, whereas it's better to have steps = 80 and denoising = 0.8. Gradio can't update an image in edit mode, opened an issue for that - Gradio issue And I'm rather out of sync with the master branch from the past week - guess mostly that the js gallery selection has been merged, the rest seems irrelevant or minor reformatting.

Edit: Updated to latest master version in new PR.