[Image lab] Send to lab button (#444)

* added image lab

* first release

model loading/unloading and save procedure added, commented out unused code from frontend

* bug fixes

Changed the image output to a gallery to display multiple items

Fixed results not showing up in output

Fixed RealESRGAN 2x mode not working and hard coded the default value for the reload.

* added GoBig model check

* added LDSR load check

* removed global statements, added model loader/unloader function

* fixed optimized mode

* update

* update

Added send to lab button
Added a print out if latent-diffusion folder isn't found

* brought back the fix faces and upscale in generation tab

Co-authored-by: dr3amer <91037083+dr3am37@users.noreply.github.com>
Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
This commit is contained in:
devilismyfriend 2022-09-01 10:48:51 -07:00 committed by GitHub
parent e1d08e7a87
commit 678578c99d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 6 deletions

View File

@ -47,8 +47,7 @@ def draw_gradio_ui(opt, img2img=lambda x: x, txt2img=lambda x: x,imgproc=lambda
#_js=js_copy_to_clipboard( 'txt2img_gallery_output')
)
output_txt2img_copy_to_input_btn = gr.Button("Push to img2img")
if RealESRGAN is not None:
output_txt2img_to_upscale_esrgan = gr.Button("Upscale w/ ESRGAN")
output_txt2img_to_imglab = gr.Button("Send to Lab",visible=True)
output_txt2img_params = gr.Highlightedtext(label="Generation parameters", interactive=False, elem_id='highlight')
with gr.Group():
@ -325,7 +324,7 @@ def draw_gradio_ui(opt, img2img=lambda x: x, txt2img=lambda x: x,imgproc=lambda
with gr.Column():
with gr.Tabs():
with gr.TabItem('Single Image'):
imgproc_source = gr.Image(label="Source", source="upload", interactive=True, type="pil")
imgproc_source = gr.Image(label="Source", source="upload", interactive=True, type="pil",elem_id="imglab_input")
#gfpgan_strength = gr.Slider(minimum=0.0, maximum=1.0, step=0.001, label="Effect strength",
# value=gfpgan_defaults['strength'])
@ -423,6 +422,14 @@ def draw_gradio_ui(opt, img2img=lambda x: x, txt2img=lambda x: x,imgproc=lambda
[imgproc_source, imgproc_folder,imgproc_prompt,imgproc_toggles,
imgproc_upscale_toggles,imgproc_realesrgan_model_name,imgproc_sampling, imgproc_steps, imgproc_height, imgproc_width, imgproc_cfg, imgproc_denoising, imgproc_seed,imgproc_gfpgan_strength],
[imgproc_output])
output_txt2img_to_imglab.click(
uifn.copy_img_to_lab,
[output_txt2img_gallery],
[imgproc_source, tabs],
_js=call_JS("moveImageFromGallery",
fromId="txt2img_gallery_output",
toId="imglab_input")
)
if RealESRGAN is None:
with gr.Row():
with gr.Column():

View File

@ -15,6 +15,16 @@ def update_image_mask(cropped_image, resize_mode, width, height):
resized_cropped_image = resize_image(resize_mode, cropped_image, width, height) if cropped_image else None
return gr.update(value=resized_cropped_image)
def copy_img_to_lab(img):
try:
image_data = re.sub('^data:image/.+;base64,', '', img)
processed_image = Image.open(BytesIO(base64.b64decode(image_data)))
tab_update = gr.update(selected='imgproc_tab')
img_update = gr.update(value=processed_image)
return processed_image, tab_update
except IndexError:
return [None, None]
def copy_img_to_input(img):
try:
image_data = re.sub('^data:image/.+;base64,', '', img)

View File

@ -362,6 +362,8 @@ def try_loading_LDSR(model_name: str):
import traceback
print("Error loading LDSR:", file=sys.stderr)
print(traceback.format_exc(), file=sys.stderr)
else:
print("LDSR not found at path, please make sure you have cloned the LDSR repo to ./src/latent-diffusion/")
try_loading_LDSR('model')
def load_SD_model():
@ -1851,13 +1853,11 @@ txt2img_toggles = [
'jpg samples',
]
"""
# removed for now becuase of Image Lab implementation
if GFPGAN is not None:
txt2img_toggles.append('Fix faces using GFPGAN')
if RealESRGAN is not None:
txt2img_toggles.append('Upscale images using RealESRGAN')
"""
txt2img_defaults = {
'prompt': '',
'ddim_steps': 50,