stable-diffusion-webui/frontend/frontend.py

876 lines
58 KiB
Python
Raw Normal View History

2022-09-26 16:02:48 +03:00
# This file is part of stable-diffusion-webui (https://github.com/sd-webui/stable-diffusion-webui/).
# Copyright 2022 sd-webui team.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import gradio as gr
from frontend.css_and_js import css, js, call_JS
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
from frontend.job_manager import JobManager
import frontend.ui_functions as uifn
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
import uuid
import torch
Scene-to-Image Prompt Layering System (#1179) # Summary of the change - new Scene-to-Image tab - new scn2img function - functions for loading and running monocular_depth_estimation with tensorflow # Description (relevant motivation, which issue is fixed) Related to discussion #925 > Would it be possible to have a layers system where we could do have foreground, mid, and background objects which relate to one another and share the style? So we could say generate a landscape, one another layer generate a castle, and on another layer generate a crowd of people. To make this work I made a prompt-based layering system in a new "Scene-to-Image" tab. You write a a multi-line prompt that looks like markdown, where each section declares one layer. It is hierarchical, so each layer can have their own child layers. Examples: https://imgur.com/a/eUxd5qn ![](https://i.imgur.com/L61w00Q.png) In the frontend you can find a brief documentation for the syntax, examples and reference for the various arguments. Here a short summary: Sections with "prompt" and child layers are img2img, without child layers they are txt2img. Without "prompt" they are just images, useful for mask selection, image composition, etc. Images can be initialized with "color", resized with "resize" and their position specified with "pos". Rotation and rotation center are "rotation" and "center". Mask can automatically be selected by color or by estimated depth based on https://huggingface.co/spaces/atsantiago/Monocular_Depth_Filter. ![](https://i.imgur.com/8rMHWmZ.png) # Additional dependencies that are required for this change For mask selection by monocular depth estimation tensorflow is required and the model must be cloned to ./src/monocular_depth_estimation/ Changes in environment.yaml: - einops>=0.3.0 - tensorflow>=2.10.0 Einops must be allowed to be newer for tensorflow to work. # Checklist: - [x] I have changed the base branch to `dev` - [x] I have performed a self-review of my own code - [x] I have commented my code in hard-to-understand areas - [x] I have made corresponding changes to the documentation Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-10-02 20:23:37 +03:00
import os
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
Scene-to-Image Prompt Layering System (#1179) # Summary of the change - new Scene-to-Image tab - new scn2img function - functions for loading and running monocular_depth_estimation with tensorflow # Description (relevant motivation, which issue is fixed) Related to discussion #925 > Would it be possible to have a layers system where we could do have foreground, mid, and background objects which relate to one another and share the style? So we could say generate a landscape, one another layer generate a castle, and on another layer generate a crowd of people. To make this work I made a prompt-based layering system in a new "Scene-to-Image" tab. You write a a multi-line prompt that looks like markdown, where each section declares one layer. It is hierarchical, so each layer can have their own child layers. Examples: https://imgur.com/a/eUxd5qn ![](https://i.imgur.com/L61w00Q.png) In the frontend you can find a brief documentation for the syntax, examples and reference for the various arguments. Here a short summary: Sections with "prompt" and child layers are img2img, without child layers they are txt2img. Without "prompt" they are just images, useful for mask selection, image composition, etc. Images can be initialized with "color", resized with "resize" and their position specified with "pos". Rotation and rotation center are "rotation" and "center". Mask can automatically be selected by color or by estimated depth based on https://huggingface.co/spaces/atsantiago/Monocular_Depth_Filter. ![](https://i.imgur.com/8rMHWmZ.png) # Additional dependencies that are required for this change For mask selection by monocular depth estimation tensorflow is required and the model must be cloned to ./src/monocular_depth_estimation/ Changes in environment.yaml: - einops>=0.3.0 - tensorflow>=2.10.0 Einops must be allowed to be newer for tensorflow to work. # Checklist: - [x] I have changed the base branch to `dev` - [x] I have performed a self-review of my own code - [x] I have commented my code in hard-to-understand areas - [x] I have made corresponding changes to the documentation Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-10-02 20:23:37 +03:00
def draw_gradio_ui(opt, img2img=lambda x: x, txt2img=lambda x: x, imgproc=lambda x: x, scn2img=lambda x: x,
txt2img_defaults={}, RealESRGAN=True, GFPGAN=True, LDSR=True,
txt2img_toggles={}, txt2img_toggle_defaults='k_euler', show_embeddings=False, img2img_defaults={},
img2img_toggles={}, img2img_toggle_defaults={}, sample_img2img=None, img2img_mask_modes=None,
Scene-to-Image Prompt Layering System (#1179) # Summary of the change - new Scene-to-Image tab - new scn2img function - functions for loading and running monocular_depth_estimation with tensorflow # Description (relevant motivation, which issue is fixed) Related to discussion #925 > Would it be possible to have a layers system where we could do have foreground, mid, and background objects which relate to one another and share the style? So we could say generate a landscape, one another layer generate a castle, and on another layer generate a crowd of people. To make this work I made a prompt-based layering system in a new "Scene-to-Image" tab. You write a a multi-line prompt that looks like markdown, where each section declares one layer. It is hierarchical, so each layer can have their own child layers. Examples: https://imgur.com/a/eUxd5qn ![](https://i.imgur.com/L61w00Q.png) In the frontend you can find a brief documentation for the syntax, examples and reference for the various arguments. Here a short summary: Sections with "prompt" and child layers are img2img, without child layers they are txt2img. Without "prompt" they are just images, useful for mask selection, image composition, etc. Images can be initialized with "color", resized with "resize" and their position specified with "pos". Rotation and rotation center are "rotation" and "center". Mask can automatically be selected by color or by estimated depth based on https://huggingface.co/spaces/atsantiago/Monocular_Depth_Filter. ![](https://i.imgur.com/8rMHWmZ.png) # Additional dependencies that are required for this change For mask selection by monocular depth estimation tensorflow is required and the model must be cloned to ./src/monocular_depth_estimation/ Changes in environment.yaml: - einops>=0.3.0 - tensorflow>=2.10.0 Einops must be allowed to be newer for tensorflow to work. # Checklist: - [x] I have changed the base branch to `dev` - [x] I have performed a self-review of my own code - [x] I have commented my code in hard-to-understand areas - [x] I have made corresponding changes to the documentation Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-10-02 20:23:37 +03:00
img2img_resize_modes=None, imgproc_defaults={}, imgproc_mode_toggles={},
scn2img_defaults={}, scn2img_toggles={}, scn2img_toggle_defaults={}, scn2img_define_args=lambda: ({},{},{}),
user_defaults={}, run_GFPGAN=lambda x: x, run_RealESRGAN=lambda x: x,
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
job_manager: JobManager = None) -> gr.Blocks:
with gr.Blocks(css=css(opt), analytics_enabled=False, title="Stable Diffusion WebUI") as demo:
with gr.Tabs(elem_id='tabss') as tabs:
with gr.TabItem("Text-to-Image", id='txt2img_tab'):
with gr.Row(elem_id="prompt_row"):
txt2img_prompt = gr.Textbox(label="Prompt",
elem_id='prompt_input',
placeholder="A corgi wearing a top hat as an oil painting.",
lines=1,
max_lines=1 if txt2img_defaults['submit_on_enter'] == 'Yes' else 25,
value=txt2img_defaults['prompt'],
show_label=False)
txt2img_btn = gr.Button("Generate", elem_id="generate", variant="primary")
2022-09-04 03:46:17 +03:00
with gr.Row(elem_id='body').style(equal_height=False):
with gr.Column():
txt2img_width = gr.Slider(minimum=64, maximum=1024, step=64, label="Width",
value=txt2img_defaults["width"])
txt2img_height = gr.Slider(minimum=64, maximum=1024, step=64, label="Height",
2022-08-31 05:25:32 +03:00
value=txt2img_defaults["height"])
txt2img_cfg = gr.Slider(minimum=-40.0, maximum=30.0, step=0.5,
label='Classifier Free Guidance Scale (how strongly the image should follow the prompt)',
2022-08-31 16:17:57 +03:00
value=txt2img_defaults['cfg_scale'], elem_id='cfg_slider')
txt2img_seed = gr.Textbox(label="Seed (blank to randomize)", lines=1, max_lines=1,
value=txt2img_defaults["seed"])
txt2img_batch_size = gr.Slider(minimum=1, maximum=50, step=1,
label='Images per batch',
value=txt2img_defaults['batch_size'])
txt2img_batch_count = gr.Slider(minimum=1, maximum=50, step=1,
label='Number of batches to generate',
value=txt2img_defaults['n_iter'])
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
txt2img_job_ui = job_manager.draw_gradio_ui() if job_manager else None
txt2img_dimensions_info_text_box = gr.Textbox(
label="Aspect ratio (4:3 = 1.333 | 16:9 = 1.777 | 21:9 = 2.333)")
with gr.Column():
with gr.Box():
output_txt2img_gallery = gr.Gallery(label="Images", elem_id="txt2img_gallery_output").style(
grid=[4, 4])
gr.Markdown(
"Select an image from the gallery, then click one of the buttons below to perform an action.")
with gr.Row(elem_id='txt2img_actions_row'):
2022-09-18 15:08:47 +03:00
gr.Button("Copy to clipboard").click(
fn=None,
inputs=output_txt2img_gallery,
outputs=[],
_js=call_JS(
"copyImageFromGalleryToClipboard",
fromId="txt2img_gallery_output"
)
)
output_txt2img_copy_to_input_btn = gr.Button("Push to img2img")
output_txt2img_to_imglab = gr.Button("Send to Lab", visible=True)
output_txt2img_params = gr.Highlightedtext(label="Generation parameters", interactive=False,
elem_id='txt2img_highlight')
with gr.Group():
with gr.Row(elem_id='txt2img_output_row'):
2022-09-04 03:46:17 +03:00
output_txt2img_copy_params = gr.Button("Copy full parameters").click(
inputs=[output_txt2img_params],
outputs=[],
_js=call_JS(
'copyFullOutput',
fromId='txt2img_highlight'
),
fn=None, show_progress=False
)
output_txt2img_seed = gr.Number(label='Seed', interactive=False, visible=False)
2022-09-04 03:46:17 +03:00
output_txt2img_copy_seed = gr.Button("Copy only seed").click(
inputs=[output_txt2img_seed],
outputs=[],
_js=call_JS('gradioInputToClipboard'),
fn=None,
show_progress=False
)
output_txt2img_stats = gr.HTML(label='Stats')
with gr.Column():
2022-09-04 03:46:17 +03:00
txt2img_steps = gr.Slider(minimum=1, maximum=250, step=1, label="Sampling Steps",
value=txt2img_defaults['ddim_steps'])
txt2img_sampling = gr.Dropdown(label='Sampling method (k_lms is default k-diffusion sampler)',
choices=["DDIM", "PLMS", 'k_dpm_2_a', 'k_dpm_2', 'k_euler_a',
'k_euler', 'k_heun', 'k_lms'],
value=txt2img_defaults['sampler_name'])
with gr.Tabs():
with gr.TabItem('Simple'):
txt2img_submit_on_enter = gr.Radio(['Yes', 'No'],
label="Submit on enter? (no means multiline)",
value=txt2img_defaults['submit_on_enter'],
interactive=True, elem_id='submit_on_enter')
txt2img_submit_on_enter.change(
2022-08-30 11:32:06 +03:00
lambda x: gr.update(max_lines=1 if x == 'Yes' else 25), txt2img_submit_on_enter,
txt2img_prompt)
with gr.TabItem('Advanced'):
txt2img_toggles = gr.CheckboxGroup(label='', choices=txt2img_toggles,
value=txt2img_toggle_defaults, type="index")
txt2img_realesrgan_model_name = gr.Dropdown(label='RealESRGAN model',
choices=['RealESRGAN_x4plus',
'RealESRGAN_x4plus_anime_6B'],
Scene-to-Image Prompt Layering System (#1179) # Summary of the change - new Scene-to-Image tab - new scn2img function - functions for loading and running monocular_depth_estimation with tensorflow # Description (relevant motivation, which issue is fixed) Related to discussion #925 > Would it be possible to have a layers system where we could do have foreground, mid, and background objects which relate to one another and share the style? So we could say generate a landscape, one another layer generate a castle, and on another layer generate a crowd of people. To make this work I made a prompt-based layering system in a new "Scene-to-Image" tab. You write a a multi-line prompt that looks like markdown, where each section declares one layer. It is hierarchical, so each layer can have their own child layers. Examples: https://imgur.com/a/eUxd5qn ![](https://i.imgur.com/L61w00Q.png) In the frontend you can find a brief documentation for the syntax, examples and reference for the various arguments. Here a short summary: Sections with "prompt" and child layers are img2img, without child layers they are txt2img. Without "prompt" they are just images, useful for mask selection, image composition, etc. Images can be initialized with "color", resized with "resize" and their position specified with "pos". Rotation and rotation center are "rotation" and "center". Mask can automatically be selected by color or by estimated depth based on https://huggingface.co/spaces/atsantiago/Monocular_Depth_Filter. ![](https://i.imgur.com/8rMHWmZ.png) # Additional dependencies that are required for this change For mask selection by monocular depth estimation tensorflow is required and the model must be cloned to ./src/monocular_depth_estimation/ Changes in environment.yaml: - einops>=0.3.0 - tensorflow>=2.10.0 Einops must be allowed to be newer for tensorflow to work. # Checklist: - [x] I have changed the base branch to `dev` - [x] I have performed a self-review of my own code - [x] I have commented my code in hard-to-understand areas - [x] I have made corresponding changes to the documentation Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-10-02 20:23:37 +03:00
value=txt2img_defaults['realesrgan_model_name'],
Dev merge (#819) * #715 #699 #698 #663 #625 #617 #611 #604 (#716) * Update README.md * Add sampler name to metadata (#695) Co-authored-by: EliEron <example@example.com> * old-dev-merge Co-authored-by: EliEron <subanimehd@gmail.com> Co-authored-by: EliEron <example@example.com> * img2img-fix (#717) * Revert "img2img-fix (#717)" This reverts commit 70d4b1ca2a27ff6e67aada0a47cb02670adfe056. * img2img fixes * Revert "img2img fixes" This reverts commit e66eddc6217d37deaa5e3086366a6f208a688969. * Revert "Revert "img2img-fix (#717)"" This reverts commit bf08b617d4fc97551cd9f264556b2e875e54b831. * img2img fixed * - Removed duplicated calls to save_sample. - Change variables and arguments to be more self-explanatory and easier to understand what they do. * Moved streamlit files to their proper location, before they were incorrectly added to the repository root folder. * Added retry dependency for the streamlit version. * Added .cmd file for easy running and updating the streamlit version of the UI. * Removed duplicated entry for streamlit on the environment.yaml file. * Removed some unnecessary lines from the the webui_streamlit.cmd file. * add gfpgan folder to gitignore, auto gen by imglab * added placeholder text similar to gradio * added auto conversion for 4 channel PNG to RGB * fix: regex escape characters * Update Readme links to sd-webui when appropriate (#781) * Update link to sd-webui when appropriate * added LDSR instruction per devilismyfriend guide * fix: stack overflow during recursion call (#784) * Added option to set default sampler name from config file, will be useful for those wanting to change the default sampler and have it persist even when closing the UI and opening it again. * Added try and except block to handle basic errors like StopException which is raised by streamlit when you hit the stop button and KeyError which happens also when stopping the generation because it tries to check the model at the end which is not loaded at that time, this can be ignored and so thats the reason for the exception. * separate css to external file * Added "git pull" and "git stash" to the commands run by the cmd scripts when launching the UI, this should make it so people who use it can automatically update the code from the repo and be up to date without manually using those commands everytime. * resolve conflict with master Co-authored-by: EliEron <subanimehd@gmail.com> Co-authored-by: EliEron <example@example.com> Co-authored-by: ZeroCool <ZeroCool940711@users.noreply.github.com> Co-authored-by: ZeroCool940711 <alejandrogilelias940711@gmail.com> Co-authored-by: Hafiidz <3688500+Hafiidz@users.noreply.github.com> Co-authored-by: Thomas Mello <work.mello@gmail.com>
2022-09-08 13:41:04 +03:00
visible=False) # RealESRGAN is not None # invisible until removed) # TODO: Feels like I shouldnt slot it in here.
txt2img_ddim_eta = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label="DDIM ETA",
value=txt2img_defaults['ddim_eta'], visible=False)
txt2img_variant_amount = gr.Slider(minimum=0.0, maximum=1.0, label='Variation Amount',
value=txt2img_defaults['variant_amount'])
txt2img_variant_seed = gr.Textbox(label="Variant Seed (blank to randomize)", lines=1,
max_lines=1, value=txt2img_defaults["variant_seed"])
txt2img_embeddings = gr.File(label="Embeddings file for textual inversion",
visible=show_embeddings)
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
txt2img_func = txt2img
txt2img_inputs = [txt2img_prompt, txt2img_steps, txt2img_sampling, txt2img_toggles,
txt2img_realesrgan_model_name, txt2img_ddim_eta, txt2img_batch_count,
txt2img_batch_size, txt2img_cfg, txt2img_seed, txt2img_height, txt2img_width,
txt2img_embeddings, txt2img_variant_amount, txt2img_variant_seed]
txt2img_outputs = [output_txt2img_gallery, output_txt2img_seed,
output_txt2img_params, output_txt2img_stats]
# If a JobManager was passed in then wrap the Generate functions
if txt2img_job_ui:
txt2img_func, txt2img_inputs, txt2img_outputs = txt2img_job_ui.wrap_func(
func=txt2img_func,
inputs=txt2img_inputs,
outputs=txt2img_outputs
)
use_queue = False
else:
use_queue = True
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
txt2img_btn.click(
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
txt2img_func,
txt2img_inputs,
txt2img_outputs,
api_name='txt2img',
queue=use_queue
)
txt2img_prompt.submit(
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
txt2img_func,
txt2img_inputs,
txt2img_outputs,
queue=use_queue
)
[Various Changes] GoBig fixes, model loading unloading and more (#553) * 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 * uncommenting img lab flag * added LDSR instructions * default imgProcessorTask set to false * exposed LDSR settings to lab users need to reclone the LDSR repo to use them. * Update frontend.py moving some stuff around to make them more coherent * restored upscale and fix faces to img2img * added notice section * fixed gfpgan/upscaled pictures not showing in 2img interfaces * send to lab button now sends info as well * uncommented dimension info update * added increment buttons to sampler for that k_euler_a action * image lab settings toggle on and off with selection * removed wip settings panel * better model loading handling and removed increment buttons * explaining * disabled SD unloading in image lab upscaling with realesgan and face fix * fixed a conflict with image lab Co-authored-by: dr3amer <91037083+dr3am37@users.noreply.github.com> Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 11:07:17 +03:00
txt2img_width.change(fn=uifn.update_dimensions_info, inputs=[txt2img_width, txt2img_height], outputs=txt2img_dimensions_info_text_box)
txt2img_height.change(fn=uifn.update_dimensions_info, inputs=[txt2img_width, txt2img_height], outputs=txt2img_dimensions_info_text_box)
txt2img_dimensions_info_text_box.value = uifn.update_dimensions_info(txt2img_width.value, txt2img_height.value)
[Various Changes] GoBig fixes, model loading unloading and more (#553) * 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 * uncommenting img lab flag * added LDSR instructions * default imgProcessorTask set to false * exposed LDSR settings to lab users need to reclone the LDSR repo to use them. * Update frontend.py moving some stuff around to make them more coherent * restored upscale and fix faces to img2img * added notice section * fixed gfpgan/upscaled pictures not showing in 2img interfaces * send to lab button now sends info as well * uncommented dimension info update * added increment buttons to sampler for that k_euler_a action * image lab settings toggle on and off with selection * removed wip settings panel * better model loading handling and removed increment buttons * explaining * disabled SD unloading in image lab upscaling with realesgan and face fix * fixed a conflict with image lab Co-authored-by: dr3amer <91037083+dr3am37@users.noreply.github.com> Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 11:07:17 +03:00
# Temporarily disable prompt parsing until memory issues could be solved
# See #676
# live_prompt_params = [txt2img_prompt, txt2img_width, txt2img_height, txt2img_steps, txt2img_seed,
# txt2img_batch_count, txt2img_cfg]
# txt2img_prompt.change(
# fn=None,
# inputs=live_prompt_params,
# outputs=live_prompt_params,
# _js=js_parse_prompt
# )
with gr.TabItem("Image-to-Image Unified", id="img2img_tab"):
with gr.Row(elem_id="prompt_row"):
img2img_prompt = gr.Textbox(label="Prompt",
elem_id='img2img_prompt_input',
placeholder="A fantasy landscape, trending on artstation.",
lines=1,
max_lines=1 if txt2img_defaults['submit_on_enter'] == 'Yes' else 25,
value=img2img_defaults['prompt'],
show_label=False).style()
img2img_btn_mask = gr.Button("Generate", variant="primary", visible=False,
elem_id="img2img_mask_btn")
img2img_btn_editor = gr.Button("Generate", variant="primary", elem_id="img2img_edit_btn")
with gr.Row().style(equal_height=False):
with gr.Column():
gr.Markdown('#### Img2Img Input')
img2img_image_mask = gr.Image(
value=sample_img2img,
source="upload",
interactive=True,
type="pil", tool="sketch",
elem_id="img2img_mask",
image_mode="RGBA"
)
img2img_image_editor = gr.Image(
value=sample_img2img,
source="upload",
interactive=True,
type="pil",
tool="select",
visible=False,
image_mode="RGBA",
elem_id="img2img_editor"
)
with gr.Tabs():
with gr.TabItem("Editor Options"):
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
with gr.Row():
# disable Uncrop for now
choices=["Mask", "Crop", "Uncrop"]
#choices=["Mask", "Crop"]
img2img_image_editor_mode = gr.Radio(choices=choices,
label="Image Editor Mode",
value="Mask", elem_id='edit_mode_select',
visible=True)
img2img_mask = gr.Radio(choices=["Keep masked area", "Regenerate only masked area"],
label="Mask Mode", type="index",
value=img2img_mask_modes[img2img_defaults['mask_mode']],
visible=True)
img2img_mask_restore = gr.Checkbox(label="Only modify regenerated parts of image",
Add mask_restore to restore images based on mask, fixing #665 (#898) * Add mask_restore option to give users the option to restore images based on mask, fixing #665. Before commit c73fdd78 (Implement masking during sampling to improve blending, #308) image mask was applied after sampling, resulting in masked parts that are not regenerated to actually stay the same. Since c73fdd78 the masked img2img will change the whole image, even in masked areas. It gives better looking results at first glance, but will result in image degredation when applied a few times. See issue #665. In the workflow of using repeated masked img2img, users may want to use this options to keep the parts of image they actually want to keep without image degradation. A final masked img2img or whole image img2img with mask_restore disabled will give the better blending of "Implement masking during sampling". * revert changes of a7be43ba in change_image_editor_mode * fix ui_functions.change_image_editor_mode by adding gr.update to the end of the list it returns * revert inserted newlines and whitespaces to match format of previous code * improve caption of new option mask_restore "Only modify regenerated parts of image" * fix ui_functions.change_image_editor_mode by adding gr.update to the end of the list it returns an old copy of the function exists in webui.py, this superflous function mistakenly was changed by the earlier commit b6a9e16b * remove unused functions that are near duplicates of functions in ui_functions.py
2022-09-10 00:07:14 +03:00
value=img2img_defaults['mask_restore'],
visible=True)
img2img_mask_blur_strength = gr.Slider(minimum=1, maximum=100, step=1,
label="How much blurry should the mask be? (to avoid hard edges)",
Scene-to-Image Prompt Layering System (#1179) # Summary of the change - new Scene-to-Image tab - new scn2img function - functions for loading and running monocular_depth_estimation with tensorflow # Description (relevant motivation, which issue is fixed) Related to discussion #925 > Would it be possible to have a layers system where we could do have foreground, mid, and background objects which relate to one another and share the style? So we could say generate a landscape, one another layer generate a castle, and on another layer generate a crowd of people. To make this work I made a prompt-based layering system in a new "Scene-to-Image" tab. You write a a multi-line prompt that looks like markdown, where each section declares one layer. It is hierarchical, so each layer can have their own child layers. Examples: https://imgur.com/a/eUxd5qn ![](https://i.imgur.com/L61w00Q.png) In the frontend you can find a brief documentation for the syntax, examples and reference for the various arguments. Here a short summary: Sections with "prompt" and child layers are img2img, without child layers they are txt2img. Without "prompt" they are just images, useful for mask selection, image composition, etc. Images can be initialized with "color", resized with "resize" and their position specified with "pos". Rotation and rotation center are "rotation" and "center". Mask can automatically be selected by color or by estimated depth based on https://huggingface.co/spaces/atsantiago/Monocular_Depth_Filter. ![](https://i.imgur.com/8rMHWmZ.png) # Additional dependencies that are required for this change For mask selection by monocular depth estimation tensorflow is required and the model must be cloned to ./src/monocular_depth_estimation/ Changes in environment.yaml: - einops>=0.3.0 - tensorflow>=2.10.0 Einops must be allowed to be newer for tensorflow to work. # Checklist: - [x] I have changed the base branch to `dev` - [x] I have performed a self-review of my own code - [x] I have commented my code in hard-to-understand areas - [x] I have made corresponding changes to the documentation Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-10-02 20:23:37 +03:00
value=img2img_defaults['mask_blur_strength'], visible=True)
img2img_resize = gr.Radio(label="Resize mode",
choices=["Just resize", "Crop and resize",
"Resize and fill"],
type="index",
value=img2img_resize_modes[
img2img_defaults['resize_mode']], visible=False)
img2img_painterro_btn = gr.Button("Advanced Editor")
with gr.TabItem("Hints"):
img2img_help = gr.Markdown(visible=False, value=uifn.help_text)
with gr.Column():
gr.Markdown('#### Img2Img Results')
output_img2img_gallery = gr.Gallery(label="Images", elem_id="img2img_gallery_output").style(
grid=[4, 4, 4])
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
img2img_job_ui = job_manager.draw_gradio_ui() if job_manager else None
with gr.Tabs():
with gr.TabItem("Generated image actions", id="img2img_actions_tab"):
gr.Markdown("Select an image, then press one of the buttons below")
with gr.Row():
output_img2img_copy_to_clipboard_btn = gr.Button("Copy to clipboard")
output_img2img_copy_to_input_btn = gr.Button("Push to img2img input")
output_img2img_copy_to_mask_btn = gr.Button("Push to img2img input mask")
gr.Markdown("Warning: This will clear your current image and mask settings!")
with gr.TabItem("Output info", id="img2img_output_info_tab"):
output_img2img_params = gr.Highlightedtext(
label="Generation parameters", interactive=False,
elem_id='img2img_highlight')
with gr.Row():
output_img2img_copy_params = gr.Button("Copy full parameters").click(
inputs=output_img2img_params,
outputs=[],
_js=call_JS(
'copyFullOutput',
fromId='img2img_highlight'
),
fn=None,
show_progress=False)
output_img2img_seed = gr.Number(label='Seed', interactive=False, visible=False)
output_img2img_copy_seed = gr.Button("Copy only seed").click(
inputs=output_img2img_seed,
outputs=[],
_js=call_JS("gradioInputToClipboard"),
fn=None,
show_progress=False
)
output_img2img_stats = gr.HTML(label='Stats')
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
gr.Markdown('# img2img settings')
with gr.Row():
with gr.Column():
img2img_width = gr.Slider(minimum=64, maximum=2048, step=64, label="Width",
value=img2img_defaults["width"])
img2img_height = gr.Slider(minimum=64, maximum=2048, step=64, label="Height",
value=img2img_defaults["height"])
img2img_cfg = gr.Slider(minimum=-40.0, maximum=30.0, step=0.5,
label='Classifier Free Guidance Scale (how strongly the image should follow the prompt)',
2022-08-31 16:17:57 +03:00
value=img2img_defaults['cfg_scale'], elem_id='cfg_slider')
img2img_seed = gr.Textbox(label="Seed (blank to randomize)", lines=1, max_lines=1,
value=img2img_defaults["seed"])
img2img_batch_count = gr.Slider(minimum=1, maximum=50, step=1,
label='Batch count (how many batches of images to generate)',
value=img2img_defaults['n_iter'])
img2img_dimensions_info_text_box = gr.Textbox(
label="Aspect ratio (4:3 = 1.333 | 16:9 = 1.777 | 21:9 = 2.333)")
with gr.Column():
img2img_steps = gr.Slider(minimum=1, maximum=250, step=1, label="Sampling Steps",
value=img2img_defaults['ddim_steps'])
img2img_sampling = gr.Dropdown(label='Sampling method (k_lms is default k-diffusion sampler)',
choices=["DDIM", 'k_dpm_2_a', 'k_dpm_2', 'k_euler_a', 'k_euler',
'k_heun', 'k_lms'],
value=img2img_defaults['sampler_name'])
img2img_denoising = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label='Denoising Strength',
value=img2img_defaults['denoising_strength'])
img2img_toggles = gr.CheckboxGroup(label='', choices=img2img_toggles,
value=img2img_toggle_defaults, type="index")
img2img_realesrgan_model_name = gr.Dropdown(label='RealESRGAN model',
choices=['RealESRGAN_x4plus',
'RealESRGAN_x4plus_anime_6B'],
Scene-to-Image Prompt Layering System (#1179) # Summary of the change - new Scene-to-Image tab - new scn2img function - functions for loading and running monocular_depth_estimation with tensorflow # Description (relevant motivation, which issue is fixed) Related to discussion #925 > Would it be possible to have a layers system where we could do have foreground, mid, and background objects which relate to one another and share the style? So we could say generate a landscape, one another layer generate a castle, and on another layer generate a crowd of people. To make this work I made a prompt-based layering system in a new "Scene-to-Image" tab. You write a a multi-line prompt that looks like markdown, where each section declares one layer. It is hierarchical, so each layer can have their own child layers. Examples: https://imgur.com/a/eUxd5qn ![](https://i.imgur.com/L61w00Q.png) In the frontend you can find a brief documentation for the syntax, examples and reference for the various arguments. Here a short summary: Sections with "prompt" and child layers are img2img, without child layers they are txt2img. Without "prompt" they are just images, useful for mask selection, image composition, etc. Images can be initialized with "color", resized with "resize" and their position specified with "pos". Rotation and rotation center are "rotation" and "center". Mask can automatically be selected by color or by estimated depth based on https://huggingface.co/spaces/atsantiago/Monocular_Depth_Filter. ![](https://i.imgur.com/8rMHWmZ.png) # Additional dependencies that are required for this change For mask selection by monocular depth estimation tensorflow is required and the model must be cloned to ./src/monocular_depth_estimation/ Changes in environment.yaml: - einops>=0.3.0 - tensorflow>=2.10.0 Einops must be allowed to be newer for tensorflow to work. # Checklist: - [x] I have changed the base branch to `dev` - [x] I have performed a self-review of my own code - [x] I have commented my code in hard-to-understand areas - [x] I have made corresponding changes to the documentation Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-10-02 20:23:37 +03:00
value=img2img_defaults['realesrgan_model_name'],
visible=RealESRGAN is not None) # TODO: Feels like I shouldnt slot it in here.
img2img_embeddings = gr.File(label="Embeddings file for textual inversion",
visible=show_embeddings)
img2img_image_editor_mode.change(
uifn.change_image_editor_mode,
[img2img_image_editor_mode,
img2img_image_editor,
img2img_image_mask,
img2img_resize,
img2img_width,
img2img_height
],
[img2img_image_editor, img2img_image_mask, img2img_btn_editor, img2img_btn_mask,
Add mask_restore to restore images based on mask, fixing #665 (#898) * Add mask_restore option to give users the option to restore images based on mask, fixing #665. Before commit c73fdd78 (Implement masking during sampling to improve blending, #308) image mask was applied after sampling, resulting in masked parts that are not regenerated to actually stay the same. Since c73fdd78 the masked img2img will change the whole image, even in masked areas. It gives better looking results at first glance, but will result in image degredation when applied a few times. See issue #665. In the workflow of using repeated masked img2img, users may want to use this options to keep the parts of image they actually want to keep without image degradation. A final masked img2img or whole image img2img with mask_restore disabled will give the better blending of "Implement masking during sampling". * revert changes of a7be43ba in change_image_editor_mode * fix ui_functions.change_image_editor_mode by adding gr.update to the end of the list it returns * revert inserted newlines and whitespaces to match format of previous code * improve caption of new option mask_restore "Only modify regenerated parts of image" * fix ui_functions.change_image_editor_mode by adding gr.update to the end of the list it returns an old copy of the function exists in webui.py, this superflous function mistakenly was changed by the earlier commit b6a9e16b * remove unused functions that are near duplicates of functions in ui_functions.py
2022-09-10 00:07:14 +03:00
img2img_painterro_btn, img2img_mask, img2img_mask_blur_strength, img2img_mask_restore]
)
# img2img_image_editor_mode.change(
# uifn.update_image_mask,
# [img2img_image_editor, img2img_resize, img2img_width, img2img_height],
# img2img_image_mask
# )
output_txt2img_copy_to_input_btn.click(
uifn.copy_img_to_input,
[output_txt2img_gallery],
[img2img_image_editor, img2img_image_mask, tabs],
_js=call_JS("moveImageFromGallery",
fromId="txt2img_gallery_output",
toId="img2img_editor")
)
output_img2img_copy_to_input_btn.click(
uifn.copy_img_to_edit,
[output_img2img_gallery],
[img2img_image_editor, tabs, img2img_image_editor_mode],
_js=call_JS("moveImageFromGallery",
fromId="img2img_gallery_output",
toId="img2img_editor")
)
output_img2img_copy_to_mask_btn.click(
uifn.copy_img_to_mask,
[output_img2img_gallery],
[img2img_image_mask, tabs, img2img_image_editor_mode],
_js=call_JS("moveImageFromGallery",
fromId="img2img_gallery_output",
toId="img2img_editor")
)
output_img2img_copy_to_clipboard_btn.click(fn=None, inputs=output_img2img_gallery, outputs=[],
_js=call_JS("copyImageFromGalleryToClipboard",
fromId="img2img_gallery_output")
)
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
img2img_func = img2img
Add mask_restore to restore images based on mask, fixing #665 (#898) * Add mask_restore option to give users the option to restore images based on mask, fixing #665. Before commit c73fdd78 (Implement masking during sampling to improve blending, #308) image mask was applied after sampling, resulting in masked parts that are not regenerated to actually stay the same. Since c73fdd78 the masked img2img will change the whole image, even in masked areas. It gives better looking results at first glance, but will result in image degredation when applied a few times. See issue #665. In the workflow of using repeated masked img2img, users may want to use this options to keep the parts of image they actually want to keep without image degradation. A final masked img2img or whole image img2img with mask_restore disabled will give the better blending of "Implement masking during sampling". * revert changes of a7be43ba in change_image_editor_mode * fix ui_functions.change_image_editor_mode by adding gr.update to the end of the list it returns * revert inserted newlines and whitespaces to match format of previous code * improve caption of new option mask_restore "Only modify regenerated parts of image" * fix ui_functions.change_image_editor_mode by adding gr.update to the end of the list it returns an old copy of the function exists in webui.py, this superflous function mistakenly was changed by the earlier commit b6a9e16b * remove unused functions that are near duplicates of functions in ui_functions.py
2022-09-10 00:07:14 +03:00
img2img_inputs = [img2img_prompt, img2img_image_editor_mode, img2img_mask, img2img_mask_blur_strength,
img2img_mask_restore, img2img_steps, img2img_sampling, img2img_toggles,
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
img2img_realesrgan_model_name, img2img_batch_count, img2img_cfg,
img2img_denoising, img2img_seed, img2img_height, img2img_width, img2img_resize,
img2img_image_editor, img2img_image_mask, img2img_embeddings]
img2img_outputs = [output_img2img_gallery, output_img2img_seed, output_img2img_params,
output_img2img_stats]
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
# If a JobManager was passed in then wrap the Generate functions
if img2img_job_ui:
img2img_func, img2img_inputs, img2img_outputs = img2img_job_ui.wrap_func(
func=img2img_func,
inputs=img2img_inputs,
outputs=img2img_outputs,
)
use_queue = False
else:
use_queue = True
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
img2img_btn_mask.click(
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
img2img_func,
img2img_inputs,
img2img_outputs,
api_name="img2img",
queue=use_queue
)
def img2img_submit_params():
# print([img2img_prompt, img2img_image_editor_mode, img2img_mask,
# img2img_mask_blur_strength, img2img_steps, img2img_sampling, img2img_toggles,
# img2img_realesrgan_model_name, img2img_batch_count, img2img_cfg,
# img2img_denoising, img2img_seed, img2img_height, img2img_width, img2img_resize,
# img2img_image_editor, img2img_image_mask, img2img_embeddings])
Job Manager feature - view images before all are complete, cancel ongoing generations (#460) * Add max-jobs command line argument Adds a new command line argument, max-jobs, which will set the number of concurrent jobs the gradio queue will allow. When set to more than the default of 1 the gradio UI will be able to process additional UI commands at the same time. * JobManager: initial txt2img implementation Initial implementation of JobManager, applied to txt2img. Adds 'refresh' and 'cancel' buttons to the UI. These are useful when generating images with large batch counts. The 'refresh' button will update the gallery with the currently-generated images, and the cancel button will cause the generation to stop after the current iteration. The new job manager can be disabled with the parameter --no-job-manager * JobManager: Add status update text * JobManager: Replace wrapped inputs as well * JobManager: Per-session unique keys * JobManager: Pre and Post call funcs, UI updates Added pre- and post- function call 'dummy objects' to allow updating the UI before and after a generate run. Update the visuals of the buttons and status text in these new functions. * JobManager: enforce maximum jobs * JobManager: Move 'call' func code block It just makes more sense between _pre and _post. * JobManager: Add session management Adds support for multiple browser sessions. A single session cannot run the same job twice. If there are no available jobs when Generate is clicked, the generation aborts. It does *not* queue. * JobManager: add session maintenance Addded the ability for one session to stop all concurrent sessions, and to free memory from any 'finished' sessions for which the browser has been closed (as the images will be stored until the browser does a final 'refresh' after the job finishes, which will never happen if the browser closed) * JobManager: Add img2img support This *should* add JobManager to img2img, but it is untested since img2img is broken for me even without my changes. * Fixed img2img functionality on this pr * Revert "Fixed img2img functionality on this pr" This reverts commit 649b1e8e655601aa7fcdbfaaa2ee321b03e61ab4. * Img2Img: Fix 'image editor' options not visible * Fix Img2Img Job Manager integration * Img2Img UI: Move JobManager above Image Actions It is helpful if it is on the screen when you hit generate, so you can notice the button light up when generation starts. * Improve job status text * JobManager: Free available job on exception * JobManager: Add queueing Adds a simple queueing system to JobManager. If max-jobs concurrent jobs are already active then any subsequent jobs will block until a slot frees up. Note: The UI does not give great feedback to this. The JobManager status box will say "Loading..." * JobManager: Fix queue accidentally LIFO Queues should really be first in, first out. * JobManager: add draw_gradio_ui function Reduces a lot of boilerplate code in frontend.py Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 10:30:07 +03:00
return (img2img_func,
img2img_inputs,
img2img_outputs)
img2img_btn_editor.click(*img2img_submit_params())
2022-08-30 22:18:29 +03:00
# GENERATE ON ENTER
img2img_prompt.submit(None, None, None,
_js=call_JS("clickFirstVisibleButton",
rowId="prompt_row"))
img2img_painterro_btn.click(None,
[img2img_image_editor, img2img_image_mask, img2img_image_editor_mode],
[img2img_image_editor, img2img_image_mask],
_js=call_JS("Painterro.init", toId="img2img_editor")
)
img2img_width.change(fn=uifn.update_dimensions_info, inputs=[img2img_width, img2img_height],
outputs=img2img_dimensions_info_text_box)
img2img_height.change(fn=uifn.update_dimensions_info, inputs=[img2img_width, img2img_height],
outputs=img2img_dimensions_info_text_box)
img2img_dimensions_info_text_box.value = uifn.update_dimensions_info(img2img_width.value, img2img_height.value)
with gr.TabItem("Image Lab", id='imgproc_tab'):
gr.Markdown("Post-process results")
with gr.Row():
with gr.Column():
with gr.Tabs():
with gr.TabItem('Single Image'):
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'])
# select folder with images to process
with gr.TabItem('Batch Process'):
2022-09-11 04:21:32 +03:00
imgproc_folder = gr.File(label="Batch Process", file_count="multiple", interactive=True, type="file")
imgproc_pngnfo = gr.Textbox(label="PNG Metadata", placeholder="PngNfo", visible=False,
max_lines=5)
with gr.Row():
imgproc_btn = gr.Button("Process", variant="primary")
gr.HTML("""
<div id="90" style="max-width: 100%; font-size: 14px; text-align: center;" class="output-markdown gr-prose border-solid border border-gray-200 rounded gr-panel">
<p><b>Upscale Modes Guide</b></p>
<p></p>
<p><b>RealESRGAN</b></p>
<p>A 4X/2X fast upscaler that works well for stylized content, will smooth more detailed compositions.</p>
<p><b>GoBIG</b></p>
<p>A 2X upscaler that uses RealESRGAN to upscale the image and then slice it into small parts, each part gets diffused further by SD to create more details, great for adding and increasing details but will change the composition, might also fix issues like eyes etc, use the settings like img2img etc</p>
<p><b>Latent Diffusion Super Resolution</b></p>
<p>A 4X upscaler with high VRAM usage that uses a Latent Diffusion model to upscale the image, this will accentuate the details but won't change the composition, might introduce sharpening, great for textures or compositions with plenty of details, is slower.</p>
<p><b>GoLatent</b></p>
<p>A 8X upscaler with high VRAM usage, uses GoBig to add details and then uses a Latent Diffusion model to upscale the image, this will result in less artifacting/sharpeninng, use the settings to feed GoBig settings that will contribute to the result, this mode is considerbly slower</p>
</div>
""")
with gr.Column():
with gr.Tabs():
with gr.TabItem('Output'):
imgproc_output = gr.Gallery(label="Output", elem_id="imgproc_gallery_output")
with gr.Row(elem_id="proc_options_row"):
with gr.Box():
with gr.Column():
gr.Markdown("<b>Processor Selection</b>")
imgproc_toggles = gr.CheckboxGroup(label='', choices=imgproc_mode_toggles,
type="index")
# .change toggles to show options
# imgproc_toggles.change()
with gr.Box(visible=False) as gfpgan_group:
gfpgan_defaults = {
'strength': 100,
}
if 'gfpgan' in user_defaults:
gfpgan_defaults.update(user_defaults['gfpgan'])
if GFPGAN is None:
gr.HTML("""
[Various Changes] GoBig fixes, model loading unloading and more (#553) * 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 * uncommenting img lab flag * added LDSR instructions * default imgProcessorTask set to false * exposed LDSR settings to lab users need to reclone the LDSR repo to use them. * Update frontend.py moving some stuff around to make them more coherent * restored upscale and fix faces to img2img * added notice section * fixed gfpgan/upscaled pictures not showing in 2img interfaces * send to lab button now sends info as well * uncommented dimension info update * added increment buttons to sampler for that k_euler_a action * image lab settings toggle on and off with selection * removed wip settings panel * better model loading handling and removed increment buttons * explaining * disabled SD unloading in image lab upscaling with realesgan and face fix * fixed a conflict with image lab Co-authored-by: dr3amer <91037083+dr3am37@users.noreply.github.com> Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 11:07:17 +03:00
<div id="90" style="max-width: 100%; font-size: 14px; text-align: center;" class="output-markdown gr-prose border-solid border border-gray-200 rounded gr-panel">
<p><b> Please download GFPGAN to activate face fixing features</b>, instructions are available at the <a href='https://github.com/hlky/stable-diffusion-webui'>Github</a></p>
</div>
""")
# gr.Markdown("")
# gr.Markdown("<b> Please download GFPGAN to activate face fixing features</b>, instructions are available at the <a href='https://github.com/hlky/stable-diffusion-webui'>Github</a>")
with gr.Column():
gr.Markdown("<b>GFPGAN Settings</b>")
imgproc_gfpgan_strength = gr.Slider(minimum=0.0, maximum=1.0, step=0.001,
label="Effect strength",
value=gfpgan_defaults['strength'],
visible=GFPGAN is not None)
with gr.Box(visible=False) as upscale_group:
if LDSR:
upscaleModes = ['RealESRGAN', 'GoBig', 'Latent Diffusion SR', 'GoLatent ']
else:
gr.HTML("""
[Various Changes] GoBig fixes, model loading unloading and more (#553) * 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 * uncommenting img lab flag * added LDSR instructions * default imgProcessorTask set to false * exposed LDSR settings to lab users need to reclone the LDSR repo to use them. * Update frontend.py moving some stuff around to make them more coherent * restored upscale and fix faces to img2img * added notice section * fixed gfpgan/upscaled pictures not showing in 2img interfaces * send to lab button now sends info as well * uncommented dimension info update * added increment buttons to sampler for that k_euler_a action * image lab settings toggle on and off with selection * removed wip settings panel * better model loading handling and removed increment buttons * explaining * disabled SD unloading in image lab upscaling with realesgan and face fix * fixed a conflict with image lab Co-authored-by: dr3amer <91037083+dr3am37@users.noreply.github.com> Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 11:07:17 +03:00
<div id="90" style="max-width: 100%; font-size: 14px; text-align: center;" class="output-markdown gr-prose border-solid border border-gray-200 rounded gr-panel">
<p><b> Please download LDSR to activate more upscale features</b>, instructions are available at the <a href='https://github.com/hlky/stable-diffusion-webui'>Github</a></p>
</div>
""")
upscaleModes = ['RealESRGAN', 'GoBig']
with gr.Column():
gr.Markdown("<b>Upscaler Selection</b>")
imgproc_upscale_toggles = gr.Radio(label='', choices=upscaleModes, type="index",
visible=RealESRGAN is not None, value='RealESRGAN')
with gr.Box(visible=False) as upscalerSettings_group:
with gr.Box(visible=True) as realesrgan_group:
[Various Changes] GoBig fixes, model loading unloading and more (#553) * 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 * uncommenting img lab flag * added LDSR instructions * default imgProcessorTask set to false * exposed LDSR settings to lab users need to reclone the LDSR repo to use them. * Update frontend.py moving some stuff around to make them more coherent * restored upscale and fix faces to img2img * added notice section * fixed gfpgan/upscaled pictures not showing in 2img interfaces * send to lab button now sends info as well * uncommented dimension info update * added increment buttons to sampler for that k_euler_a action * image lab settings toggle on and off with selection * removed wip settings panel * better model loading handling and removed increment buttons * explaining * disabled SD unloading in image lab upscaling with realesgan and face fix * fixed a conflict with image lab Co-authored-by: dr3amer <91037083+dr3am37@users.noreply.github.com> Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 11:07:17 +03:00
with gr.Column():
gr.Markdown("<b>RealESRGAN Settings</b>")
imgproc_realesrgan_model_name = gr.Dropdown(label='RealESRGAN model',
interactive=RealESRGAN is not None,
choices=['RealESRGAN_x4plus',
'RealESRGAN_x4plus_anime_6B',
'RealESRGAN_x2plus',
'RealESRGAN_x2plus_anime_6B'],
value='RealESRGAN_x4plus',
visible=RealESRGAN is not None) # TODO: Feels like I shouldnt slot it in here.
with gr.Box(visible=False) as ldsr_group:
with gr.Row(elem_id="ldsr_settings_row"):
[Various Changes] GoBig fixes, model loading unloading and more (#553) * 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 * uncommenting img lab flag * added LDSR instructions * default imgProcessorTask set to false * exposed LDSR settings to lab users need to reclone the LDSR repo to use them. * Update frontend.py moving some stuff around to make them more coherent * restored upscale and fix faces to img2img * added notice section * fixed gfpgan/upscaled pictures not showing in 2img interfaces * send to lab button now sends info as well * uncommented dimension info update * added increment buttons to sampler for that k_euler_a action * image lab settings toggle on and off with selection * removed wip settings panel * better model loading handling and removed increment buttons * explaining * disabled SD unloading in image lab upscaling with realesgan and face fix * fixed a conflict with image lab Co-authored-by: dr3amer <91037083+dr3am37@users.noreply.github.com> Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 11:07:17 +03:00
with gr.Column():
gr.Markdown("<b>Latent Diffusion Super Sampling Settings</b>")
imgproc_ldsr_steps = gr.Slider(minimum=0, maximum=500, step=10,
label="LDSR Sampling Steps",
value=100, visible=LDSR is not None)
imgproc_ldsr_pre_downSample = gr.Dropdown(
label='LDSR Pre Downsample mode (Lower resolution before processing for speed)',
choices=["None", '1/2', '1/4'], value="None", visible=LDSR is not None)
imgproc_ldsr_post_downSample = gr.Dropdown(
label='LDSR Post Downsample mode (aka SuperSampling)',
choices=["None", "Original Size", '1/2', '1/4'], value="None",
visible=LDSR is not None)
with gr.Box(visible=False) as gobig_group:
with gr.Row(elem_id="proc_prompt_row"):
with gr.Column():
gr.Markdown("<b>GoBig Settings</b>")
imgproc_prompt = gr.Textbox(label="",
elem_id='prompt_input',
placeholder="A corgi wearing a top hat as an oil painting.",
lines=1,
max_lines=1,
value=imgproc_defaults['prompt'],
show_label=True,
visible=RealESRGAN is not None)
imgproc_sampling = gr.Dropdown(
label='Sampling method (k_lms is default k-diffusion sampler)',
choices=["DDIM", 'k_dpm_2_a', 'k_dpm_2', 'k_euler_a', 'k_euler',
'k_heun', 'k_lms'],
value=imgproc_defaults['sampler_name'], visible=RealESRGAN is not None)
imgproc_steps = gr.Slider(minimum=1, maximum=250, step=1,
label="Sampling Steps",
value=imgproc_defaults['ddim_steps'],
visible=RealESRGAN is not None)
imgproc_cfg = gr.Slider(minimum=1.0, maximum=30.0, step=0.5,
label='Classifier Free Guidance Scale (how strongly the image should follow the prompt)',
value=imgproc_defaults['cfg_scale'],
visible=RealESRGAN is not None)
imgproc_denoising = gr.Slider(minimum=0.0, maximum=1.0, step=0.01,
label='Denoising Strength',
value=imgproc_defaults['denoising_strength'],
visible=RealESRGAN is not None)
imgproc_height = gr.Slider(minimum=64, maximum=2048, step=64, label="Height",
value=imgproc_defaults["height"],
visible=False) # not currently implemented
imgproc_width = gr.Slider(minimum=64, maximum=2048, step=64, label="Width",
value=imgproc_defaults["width"],
visible=False) # not currently implemented
imgproc_seed = gr.Textbox(label="Seed (blank to randomize)", lines=1,
max_lines=1,
value=imgproc_defaults["seed"],
visible=RealESRGAN is not None)
imgproc_btn.click(
imgproc,
[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_ldsr_steps, imgproc_ldsr_pre_downSample,
imgproc_ldsr_post_downSample],
[imgproc_output], api_name="imgproc")
imgproc_source.change(
uifn.get_png_nfo,
[imgproc_source],
[imgproc_pngnfo])
output_txt2img_to_imglab.click(
fn=uifn.copy_img_params_to_lab,
inputs=[output_txt2img_params],
outputs=[imgproc_prompt, imgproc_seed, imgproc_steps, imgproc_cfg,
imgproc_sampling],
)
output_txt2img_to_imglab.click(
fn=uifn.copy_img_to_lab,
inputs=[output_txt2img_gallery],
outputs=[imgproc_source, tabs],
_js=call_JS("moveImageFromGallery",
fromId="txt2img_gallery_output",
toId="imglab_input")
)
if RealESRGAN is None:
with gr.Row():
with gr.Column():
# seperator
gr.HTML("""
<div id="90" style="max-width: 100%; font-size: 14px; text-align: center;" class="output-markdown gr-prose border-solid border border-gray-200 rounded gr-panel">
<p><b> Please download RealESRGAN to activate upscale features</b>, instructions are available at the <a href='https://github.com/hlky/stable-diffusion-webui'>Github</a></p>
</div>
""")
[Various Changes] GoBig fixes, model loading unloading and more (#553) * 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 * uncommenting img lab flag * added LDSR instructions * default imgProcessorTask set to false * exposed LDSR settings to lab users need to reclone the LDSR repo to use them. * Update frontend.py moving some stuff around to make them more coherent * restored upscale and fix faces to img2img * added notice section * fixed gfpgan/upscaled pictures not showing in 2img interfaces * send to lab button now sends info as well * uncommented dimension info update * added increment buttons to sampler for that k_euler_a action * image lab settings toggle on and off with selection * removed wip settings panel * better model loading handling and removed increment buttons * explaining * disabled SD unloading in image lab upscaling with realesgan and face fix * fixed a conflict with image lab Co-authored-by: dr3amer <91037083+dr3am37@users.noreply.github.com> Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 11:07:17 +03:00
imgproc_toggles.change(fn=uifn.toggle_options_gfpgan, inputs=[imgproc_toggles], outputs=[gfpgan_group])
imgproc_toggles.change(fn=uifn.toggle_options_upscalers, inputs=[imgproc_toggles], outputs=[upscale_group])
imgproc_toggles.change(fn=uifn.toggle_options_upscalers, inputs=[imgproc_toggles],
outputs=[upscalerSettings_group])
imgproc_upscale_toggles.change(fn=uifn.toggle_options_realesrgan, inputs=[imgproc_upscale_toggles],
outputs=[realesrgan_group])
imgproc_upscale_toggles.change(fn=uifn.toggle_options_ldsr, inputs=[imgproc_upscale_toggles],
outputs=[ldsr_group])
imgproc_upscale_toggles.change(fn=uifn.toggle_options_gobig, inputs=[imgproc_upscale_toggles],
outputs=[gobig_group])
[Various Changes] GoBig fixes, model loading unloading and more (#553) * 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 * uncommenting img lab flag * added LDSR instructions * default imgProcessorTask set to false * exposed LDSR settings to lab users need to reclone the LDSR repo to use them. * Update frontend.py moving some stuff around to make them more coherent * restored upscale and fix faces to img2img * added notice section * fixed gfpgan/upscaled pictures not showing in 2img interfaces * send to lab button now sends info as well * uncommented dimension info update * added increment buttons to sampler for that k_euler_a action * image lab settings toggle on and off with selection * removed wip settings panel * better model loading handling and removed increment buttons * explaining * disabled SD unloading in image lab upscaling with realesgan and face fix * fixed a conflict with image lab Co-authored-by: dr3amer <91037083+dr3am37@users.noreply.github.com> Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-09-03 11:07:17 +03:00
Scene-to-Image Prompt Layering System (#1179) # Summary of the change - new Scene-to-Image tab - new scn2img function - functions for loading and running monocular_depth_estimation with tensorflow # Description (relevant motivation, which issue is fixed) Related to discussion #925 > Would it be possible to have a layers system where we could do have foreground, mid, and background objects which relate to one another and share the style? So we could say generate a landscape, one another layer generate a castle, and on another layer generate a crowd of people. To make this work I made a prompt-based layering system in a new "Scene-to-Image" tab. You write a a multi-line prompt that looks like markdown, where each section declares one layer. It is hierarchical, so each layer can have their own child layers. Examples: https://imgur.com/a/eUxd5qn ![](https://i.imgur.com/L61w00Q.png) In the frontend you can find a brief documentation for the syntax, examples and reference for the various arguments. Here a short summary: Sections with "prompt" and child layers are img2img, without child layers they are txt2img. Without "prompt" they are just images, useful for mask selection, image composition, etc. Images can be initialized with "color", resized with "resize" and their position specified with "pos". Rotation and rotation center are "rotation" and "center". Mask can automatically be selected by color or by estimated depth based on https://huggingface.co/spaces/atsantiago/Monocular_Depth_Filter. ![](https://i.imgur.com/8rMHWmZ.png) # Additional dependencies that are required for this change For mask selection by monocular depth estimation tensorflow is required and the model must be cloned to ./src/monocular_depth_estimation/ Changes in environment.yaml: - einops>=0.3.0 - tensorflow>=2.10.0 Einops must be allowed to be newer for tensorflow to work. # Checklist: - [x] I have changed the base branch to `dev` - [x] I have performed a self-review of my own code - [x] I have commented my code in hard-to-understand areas - [x] I have made corresponding changes to the documentation Co-authored-by: hlky <106811348+hlky@users.noreply.github.com>
2022-10-02 20:23:37 +03:00
with gr.TabItem("Scene-to-Image", id='scn2img_tab'):
example_path = os.path.join("data","scn2img_examples")
files = os.listdir(example_path)
examples = {}
for fn in files:
filepath = os.path.join(example_path, str(fn))
with open(filepath, "r") as file:
examples[fn] = file.read()
with gr.Row(elem_id="tools_row"):
scn2img_btn = gr.Button("Generate", elem_id="generate", variant="primary")
with gr.Row().style(equal_height=False):
with gr.Column():
scn2img_seed = gr.Textbox(
label="Seed (blank to randomize, specify to use cache)", lines=1, max_lines=1,
value=scn2img_defaults["seed"]
)
scn2img_prompt = gr.Textbox(
label="Prompt Scene",
elem_id='scn2_img_input',
placeholder=examples[list(examples.keys())[0]],
lines=50,
max_lines=50,
value=scn2img_defaults['prompt'],
show_label=False
)
with gr.Column():
with gr.Tabs():
with gr.TabItem("Results", id="scn2img_results_tab"):
# gr.Markdown('#### Scn2Img Results')
output_scn2img_gallery = gr.Gallery(
label="Images",
elem_id="scn2img_gallery_output"
).style(grid=[3, 3, 3], height=80)
scn2img_job_ui = job_manager.draw_gradio_ui() if job_manager else None
with gr.Tabs():
with gr.TabItem("Generated image actions", id="scn2img_actions_tab"):
gr.Markdown("Select an image, then press one of the buttons below")
with gr.Row():
output_scn2img_copy_to_clipboard_btn = gr.Button("Copy to clipboard")
output_scn2img_copy_to_img2img_input_btn = gr.Button("Push to img2img input")
output_scn2img_copy_to_img2img_mask_btn = gr.Button("Push to img2img input mask")
gr.Markdown("Warning: This will clear your current img2img image and mask settings!")
with gr.TabItem("Output info", id="scn2img_output_info_tab"):
output_scn2img_params = gr.Highlightedtext(label="Generation parameters", interactive=False,
elem_id='scn2img_highlight')
with gr.Row():
output_scn2img_copy_params = gr.Button("Copy full parameters").click(
inputs=[output_scn2img_params],
outputs=[],
_js=call_JS(
'copyFullOutput',
fromId='scn2img_highlight'
),
fn=None, show_progress=False
)
output_scn2img_seed = gr.Number(label='Seed', interactive=False, visible=False)
output_scn2img_copy_seed = gr.Button("Copy only initial seed").click(
inputs=output_scn2img_seed, outputs=[],
_js=call_JS("gradioInputToClipboard"), fn=None, show_progress=False)
output_scn2img_stats = gr.HTML(label='Stats')
with gr.TabItem("SceneCode", id="scn2img_scncode_tab"):
output_scn2img_scncode = gr.HTML(label="SceneCode")
scn2img_toggles = gr.CheckboxGroup(label='', choices=scn2img_toggles,
value=scn2img_toggle_defaults, type="index")
scn2img_embeddings = gr.File(label="Embeddings file for textual inversion",
visible=show_embeddings)
with gr.TabItem("Docs", id="scn2img_docs_tab"):
parse_arg, function_args, function_args_ext = scn2img_define_args()
with gr.Tabs():
with gr.TabItem("syntax", id=f"scn2img_docs_syntax_tab"):
lines = [
"Scene-to-Image defines layers of images in markdown-like syntax.",
"",
"Markdown headings, e.g. '# layer0', define layers.",
"Layers are hierarchical, i.e. each layer can contain more layers.",
"Child layers are blended together by their image masks, like layers in image editors.",
"",
"The content of sections define the arguments for image generation.",
"Arguments are defined by lines of the form 'arg:value' or 'arg=value'.",
"",
"To invoke txt2img or img2img, they layer must contain the 'prompt' argument.",
"For img2img the layer must have child layers, the result of blending them will be the input image for img2img.",
"When no prompt is specified the layer can still be used for image composition and mask selection.",
]
gr.Markdown("\n".join(lines))
for func, ext in function_args_ext.items():
with gr.TabItem(func, id=f"scn2img_docs_{func}_tab"):
lines = []
for e in ext:
lines.append(f"#### Arguments for {e}")
if e not in function_args: continue
for argname,argtype in function_args[e].items():
lines.append(f" - {argname}: {argtype}")
gr.Markdown("\n".join(lines))
with gr.TabItem("Examples", id="scn2img_examples_tab"):
scn2img_examples = {}
with gr.Tabs():
for k, (example, content) in enumerate(examples.items()):
with gr.TabItem(example, id=f"scn2img_example_{k}_tab"):
scn2img_examples[example] = gr.Textbox(
label="Prompt Scene",
elem_id=f"scn2img_example_{k}",
value=content,
lines=50,
max_lines=50,
show_label=False,
interactive=True
)
output_scn2img_copy_to_img2img_input_btn.click(
uifn.copy_img_to_edit,
[output_scn2img_gallery],
[img2img_image_editor, tabs, img2img_image_editor_mode],
_js=call_JS("moveImageFromGallery",
fromId="scn2img_gallery_output",
toId="img2img_editor")
)
output_scn2img_copy_to_img2img_mask_btn.click(
uifn.copy_img_to_mask,
[output_scn2img_gallery],
[img2img_image_mask, tabs, img2img_image_editor_mode],
_js=call_JS("moveImageFromGallery",
fromId="scn2img_gallery_output",
toId="img2img_editor")
)
output_scn2img_copy_to_clipboard_btn.click(
fn=None,
inputs=output_scn2img_gallery,
outputs=[],
_js=call_JS("copyImageFromGalleryToClipboard",
fromId="scn2img_gallery_output")
)
scn2img_func = scn2img
scn2img_inputs = [
scn2img_prompt,
scn2img_toggles,
scn2img_seed,
scn2img_embeddings
]
scn2img_outputs = [
output_scn2img_gallery,
output_scn2img_seed,
output_scn2img_params,
output_scn2img_stats,
output_scn2img_scncode
]
# If a JobManager was passed in then wrap the Generate functions
if scn2img_job_ui:
scn2img_func, scn2img_inputs, scn2img_outputs = scn2img_job_ui.wrap_func(
func=scn2img_func,
inputs=scn2img_inputs,
outputs=scn2img_outputs,
)
scn2img_btn.click(
scn2img_func,
scn2img_inputs,
scn2img_outputs
)
"""
if GFPGAN is not None:
gfpgan_defaults = {
'strength': 100,
}
if 'gfpgan' in user_defaults:
gfpgan_defaults.update(user_defaults['gfpgan'])
with gr.TabItem("GFPGAN", id='cfpgan_tab'):
gr.Markdown("Fix faces on images")
with gr.Row():
with gr.Column():
gfpgan_source = gr.Image(label="Source", source="upload", interactive=True, type="pil")
gfpgan_strength = gr.Slider(minimum=0.0, maximum=1.0, step=0.001, label="Effect strength",
value=gfpgan_defaults['strength'])
gfpgan_btn = gr.Button("Generate", variant="primary")
with gr.Column():
2022-08-31 16:34:50 +03:00
gfpgan_output = gr.Image(label="Output", elem_id='gan_image')
gfpgan_btn.click(
run_GFPGAN,
[gfpgan_source, gfpgan_strength],
[gfpgan_output]
)
if RealESRGAN is not None:
with gr.TabItem("RealESRGAN", id='realesrgan_tab'):
gr.Markdown("Upscale images")
with gr.Row():
with gr.Column():
realesrgan_source = gr.Image(label="Source", source="upload", interactive=True, type="pil")
realesrgan_model_name = gr.Dropdown(label='RealESRGAN model', choices=['RealESRGAN_x4plus',
'RealESRGAN_x4plus_anime_6B'],
value='RealESRGAN_x4plus')
realesrgan_btn = gr.Button("Generate")
with gr.Column():
2022-08-31 16:34:50 +03:00
realesrgan_output = gr.Image(label="Output", elem_id='gan_image')
realesrgan_btn.click(
run_RealESRGAN,
[realesrgan_source, realesrgan_model_name],
[realesrgan_output]
)
output_txt2img_to_upscale_esrgan.click(
uifn.copy_img_to_upscale_esrgan,
output_txt2img_gallery,
[realesrgan_source, tabs],
_js=js_move_image('txt2img_gallery_output', 'img2img_editor'))
"""
gr.HTML("""
<div id="90" style="max-width: 100%; font-size: 14px; text-align: center;" class="output-markdown gr-prose border-solid border border-gray-200 rounded gr-panel">
<p>For help and advanced usage guides, visit the <a href="https://github.com/hlky/stable-diffusion-webui/wiki" target="_blank">Project Wiki</a></p>
<p>Stable Diffusion WebUI is an open-source project. You can find the latest stable builds on the <a href="https://github.com/hlky/stable-diffusion" target="_blank">main repository</a>.
If you would like to contribute to development or test bleeding edge builds, you can visit the <a href="https://github.com/hlky/stable-diffusion-webui" target="_blank">developement repository</a>.</p>
<p>Device ID {current_device_index}: {current_device_name}<br/>{total_device_count} total devices</p>
</div>
""".format(current_device_name=torch.cuda.get_device_name(), current_device_index=torch.cuda.current_device(), total_device_count=torch.cuda.device_count()))
# Hack: Detect the load event on the frontend
# Won't be needed in the next version of gradio
# See the relevant PR: https://github.com/gradio-app/gradio/pull/2108
load_detector = gr.Number(value=0, label="Load Detector", visible=False)
load_detector.change(None, None, None, _js=js(opt))
demo.load(lambda x: 42, inputs=load_detector, outputs=load_detector)
2022-08-29 08:38:34 +03:00
return demo