upgrade to gradio==3.4b3 t fixthe inpain bugs

rework progressbar/preview to work with new gradio
remove unnecessary create style button
added link to alternative colab
This commit is contained in:
AUTOMATIC 2022-09-23 20:46:02 +03:00
parent 1a0353675d
commit 0065327726
6 changed files with 68 additions and 81 deletions

View File

@ -51,7 +51,10 @@ A browser interface based on Gradio library for Stable Diffusion.
## Installation and Running ## Installation and Running
Make sure the required [dependencies](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Dependencies) are met and follow the instructions available for both [NVidia](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Install-and-Run-on-NVidia-GPUs) (recommended) and [AMD](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Install-and-Run-on-AMD-GPUs) GPUs. Make sure the required [dependencies](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Dependencies) are met and follow the instructions available for both [NVidia](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Install-and-Run-on-NVidia-GPUs) (recommended) and [AMD](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Install-and-Run-on-AMD-GPUs) GPUs.
Alternatively, use [Google Colab](https://colab.research.google.com/drive/1Iy-xW9t1-OQWhb0hNxueGij8phCyluOh). Alternatively, use Google Colab:
- [Colab, maintained by Akaibu#9379](https://colab.research.google.com/drive/1kw3egmSn-KgWsikYvOMjJkVDsPLjEMzl)
- [Colab, original by me, outdated](https://colab.research.google.com/drive/1Iy-xW9t1-OQWhb0hNxueGij8phCyluOh).
### Automatic Installation on Windows ### Automatic Installation on Windows
1. Install [Python 3.10.6](https://www.python.org/downloads/windows/), checking "Add Python to PATH" 1. Install [Python 3.10.6](https://www.python.org/downloads/windows/), checking "Add Python to PATH"

View File

@ -1,53 +1,52 @@
// code related to showing and updating progressbar shown as the image is being made // code related to showing and updating progressbar shown as the image is being made
global_progressbar = null global_progressbars = {}
onUiUpdate(function(){ function check_progressbar(id_part, id_progressbar, id_progressbar_span, id_interrupt, id_preview, id_gallery){
progressbar = gradioApp().getElementById('progressbar') var progressbar = gradioApp().getElementById(id_progressbar)
progressDiv = gradioApp().querySelectorAll('#progressSpan').length > 0; var interrupt = gradioApp().getElementById(id_interrupt)
interrupt = gradioApp().getElementById('interrupt') if(progressbar!= null && progressbar != global_progressbars[id_progressbar]){
if(progressbar!= null && progressbar != global_progressbar){ global_progressbars[id_progressbar] = progressbar
global_progressbar = progressbar
var mutationObserver = new MutationObserver(function(m){ var mutationObserver = new MutationObserver(function(m){
txt2img_preview = gradioApp().getElementById('txt2img_preview') preview = gradioApp().getElementById(id_preview)
txt2img_gallery = gradioApp().getElementById('txt2img_gallery') gallery = gradioApp().getElementById(id_gallery)
img2img_preview = gradioApp().getElementById('img2img_preview')
img2img_gallery = gradioApp().getElementById('img2img_gallery')
if(txt2img_preview != null && txt2img_gallery != null){ if(preview != null && gallery != null){
txt2img_preview.style.width = txt2img_gallery.clientWidth + "px" preview.style.width = gallery.clientWidth + "px"
txt2img_preview.style.height = txt2img_gallery.clientHeight + "px" preview.style.height = gallery.clientHeight + "px"
var progressDiv = gradioApp().querySelectorAll('#' + id_progressbar_span).length > 0;
if(!progressDiv){ if(!progressDiv){
interrupt.style.display = "none" interrupt.style.display = "none"
} }
} }
if(img2img_preview != null && img2img_gallery != null){ window.setTimeout(function(){ requestMoreProgress(id_part, id_progressbar_span, id_interrupt) }, 500)
img2img_preview.style.width = img2img_gallery.clientWidth + "px"
img2img_preview.style.height = img2img_gallery.clientHeight + "px"
if(!progressDiv){
interrupt.style.display = "none"
}
}
window.setTimeout(requestMoreProgress, 500)
}); });
mutationObserver.observe( progressbar, { childList:true, subtree:true }) mutationObserver.observe( progressbar, { childList:true, subtree:true })
} }
}
onUiUpdate(function(){
check_progressbar('txt2img', 'txt2img_progressbar', 'txt2img_progress_span', 'txt2img_interrupt', 'txt2img_preview', 'txt2img_gallery')
check_progressbar('img2img', 'img2img_progressbar', 'img2img_progress_span', 'img2img_interrupt', 'img2img_preview', 'img2img_gallery')
}) })
function requestMoreProgress(){
btn = gradioApp().getElementById("check_progress"); function requestMoreProgress(id_part, id_progressbar_span, id_interrupt){
btn = gradioApp().getElementById(id_part+"_check_progress");
if(btn==null) return; if(btn==null) return;
btn.click(); btn.click();
progressDiv = gradioApp().querySelectorAll('#progressSpan').length > 0; var progressDiv = gradioApp().querySelectorAll('#' + id_progressbar_span).length > 0;
if(progressDiv){ var interrupt = gradioApp().getElementById(id_interrupt)
console.log(progressDiv, interrupt)
if(progressDiv && interrupt){
interrupt.style.display = "block" interrupt.style.display = "block"
} }
} }
function requestProgress(){ function requestProgress(id_part){
btn = gradioApp().getElementById("check_progress_initial"); btn = gradioApp().getElementById(id_part+"_check_progress_initial");
if(btn==null) return; if(btn==null) return;
btn.click(); btn.click();

View File

@ -79,13 +79,13 @@ function create_submit_args(args){
} }
function submit(){ function submit(){
requestProgress() requestProgress('txt2img')
return create_submit_args(arguments) return create_submit_args(arguments)
} }
function submit_img2img(){ function submit_img2img(){
requestProgress() requestProgress('img2img')
res = create_submit_args(arguments) res = create_submit_args(arguments)

View File

@ -166,7 +166,7 @@ def wrap_gradio_call(func):
return f return f
def check_progress_call(): def check_progress_call(id_part):
if shared.state.job_count == 0: if shared.state.job_count == 0:
return "", gr_show(False), gr_show(False) return "", gr_show(False), gr_show(False)
@ -200,15 +200,15 @@ def check_progress_call():
else: else:
preview_visibility = gr_show(True) preview_visibility = gr_show(True)
return f"<span id='progressSpan' style='display: none'>{time.time()}</span><p>{progressbar}</p>", preview_visibility, image return f"<span id='{id_part}_progress_span' style='display: none'>{time.time()}</span><p>{progressbar}</p>", preview_visibility, image
def check_progress_call_initial(): def check_progress_call_initial(id_part):
shared.state.job_count = -1 shared.state.job_count = -1
shared.state.current_latent = None shared.state.current_latent = None
shared.state.current_image = None shared.state.current_image = None
return check_progress_call() return check_progress_call(id_part)
def roll_artist(prompt): def roll_artist(prompt):
@ -236,8 +236,7 @@ def add_style(name: str, prompt: str, negative_prompt: str):
# reserialize all styles every time we save them # reserialize all styles every time we save them
shared.prompt_styles.save_styles(shared.styles_filename) shared.prompt_styles.save_styles(shared.styles_filename)
update = {"visible": True, "choices": list(shared.prompt_styles.styles), "__type__": "update"} return [gr.Dropdown.update(visible=True, choices=list(shared.prompt_styles.styles)) for _ in range(4)]
return [update, update, update, update]
def apply_styles(prompt, prompt_neg, style1_name, style2_name): def apply_styles(prompt, prompt_neg, style1_name, style2_name):
@ -329,6 +328,8 @@ def connect_reuse_seed(seed: gr.Number, reuse_seed: gr.Button, generation_info:
def create_toprow(is_img2img): def create_toprow(is_img2img):
id_part = "img2img" if is_img2img else "txt2img"
with gr.Row(elem_id="toprow"): with gr.Row(elem_id="toprow"):
with gr.Column(scale=4): with gr.Column(scale=4):
with gr.Row(): with gr.Row():
@ -337,19 +338,20 @@ def create_toprow(is_img2img):
prompt = gr.Textbox(label="Prompt", elem_id="prompt", show_label=False, placeholder="Prompt", lines=2) prompt = gr.Textbox(label="Prompt", elem_id="prompt", show_label=False, placeholder="Prompt", lines=2)
roll = gr.Button('Roll', elem_id="roll", visible=len(shared.artist_db.artists) > 0) roll = gr.Button('Roll', elem_id="roll", visible=len(shared.artist_db.artists) > 0)
with gr.Column(scale=1, elem_id="style_pos_col"):
prompt_style = gr.Dropdown(label="Style 1", elem_id="style_index", choices=[k for k, v in shared.prompt_styles.styles.items()], value=next(iter(shared.prompt_styles.styles.keys())), visible=len(shared.prompt_styles.styles) > 1) with gr.Column(scale=10, elem_id="style_pos_col"):
prompt_style = gr.Dropdown(label="Style 1", elem_id=f"{id_part}_style_index", choices=[k for k, v in shared.prompt_styles.styles.items()], value=next(iter(shared.prompt_styles.styles.keys())), visible=len(shared.prompt_styles.styles) > 1)
with gr.Row(): with gr.Row():
with gr.Column(scale=8): with gr.Column(scale=8):
negative_prompt = gr.Textbox(label="Negative prompt", elem_id="negative_prompt", show_label=False, placeholder="Negative prompt", lines=2) negative_prompt = gr.Textbox(label="Negative prompt", elem_id="negative_prompt", show_label=False, placeholder="Negative prompt", lines=2)
with gr.Column(scale=1, elem_id="style_neg_col"): with gr.Column(scale=1, elem_id="style_neg_col"):
prompt_style2 = gr.Dropdown(label="Style 2", elem_id="style2_index", choices=[k for k, v in shared.prompt_styles.styles.items()], value=next(iter(shared.prompt_styles.styles.keys())), visible=len(shared.prompt_styles.styles) > 1) prompt_style2 = gr.Dropdown(label="Style 2", elem_id=f"{id_part}_style2_index", choices=[k for k, v in shared.prompt_styles.styles.items()], value=next(iter(shared.prompt_styles.styles.keys())), visible=len(shared.prompt_styles.styles) > 1)
with gr.Column(scale=1): with gr.Column(scale=1):
with gr.Row(): with gr.Row():
interrupt = gr.Button('Interrupt', elem_id="interrupt") interrupt = gr.Button('Interrupt', elem_id=f"{id_part}_interrupt")
submit = gr.Button('Generate', elem_id="generate", variant='primary') submit = gr.Button('Generate', elem_id="generate", variant='primary')
interrupt.click( interrupt.click(
@ -369,18 +371,18 @@ def create_toprow(is_img2img):
return prompt, roll, prompt_style, negative_prompt, prompt_style2, submit, interrogate, prompt_style_apply, save_style return prompt, roll, prompt_style, negative_prompt, prompt_style2, submit, interrogate, prompt_style_apply, save_style
def setup_progressbar(progressbar, preview): def setup_progressbar(progressbar, preview, id_part):
check_progress = gr.Button('Check progress', elem_id="check_progress", visible=False) check_progress = gr.Button('Check progress', elem_id=f"{id_part}_check_progress", visible=False)
check_progress.click( check_progress.click(
fn=check_progress_call, fn=lambda: check_progress_call(id_part),
show_progress=False, show_progress=False,
inputs=[], inputs=[],
outputs=[progressbar, preview, preview], outputs=[progressbar, preview, preview],
) )
check_progress_initial = gr.Button('Check progress (first)', elem_id="check_progress_initial", visible=False) check_progress_initial = gr.Button('Check progress (first)', elem_id=f"{id_part}_check_progress_initial", visible=False)
check_progress_initial.click( check_progress_initial.click(
fn=check_progress_call_initial, fn=lambda: check_progress_call_initial(id_part),
show_progress=False, show_progress=False,
inputs=[], inputs=[],
outputs=[progressbar, preview, preview], outputs=[progressbar, preview, preview],
@ -392,14 +394,14 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo):
txt2img_prompt, roll, txt2img_prompt_style, txt2img_negative_prompt, txt2img_prompt_style2, submit, _, txt2img_prompt_style_apply, txt2img_save_style = create_toprow(is_img2img=False) txt2img_prompt, roll, txt2img_prompt_style, txt2img_negative_prompt, txt2img_prompt_style2, submit, _, txt2img_prompt_style_apply, txt2img_save_style = create_toprow(is_img2img=False)
dummy_component = gr.Label(visible=False) dummy_component = gr.Label(visible=False)
with gr.Row(elem_id='progressRow'): with gr.Row(elem_id='txt2img_progress_row'):
with gr.Column(scale=1): with gr.Column(scale=1):
columnEmpty = "Empty" pass
with gr.Column(scale=1): with gr.Column(scale=1):
progressbar = gr.HTML(elem_id="progressbar") progressbar = gr.HTML(elem_id="txt2img_progressbar")
txt2img_preview = gr.Image(elem_id='txt2img_preview', visible=False) txt2img_preview = gr.Image(elem_id='txt2img_preview', visible=False)
setup_progressbar(progressbar, txt2img_preview) setup_progressbar(progressbar, txt2img_preview, 'txt2img')
with gr.Row().style(equal_height=False): with gr.Row().style(equal_height=False):
with gr.Column(variant='panel'): with gr.Column(variant='panel'):
@ -518,14 +520,14 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo):
with gr.Blocks(analytics_enabled=False) as img2img_interface: with gr.Blocks(analytics_enabled=False) as img2img_interface:
img2img_prompt, roll, img2img_prompt_style, img2img_negative_prompt, img2img_prompt_style2, submit, img2img_interrogate, img2img_prompt_style_apply, img2img_save_style = create_toprow(is_img2img=True) img2img_prompt, roll, img2img_prompt_style, img2img_negative_prompt, img2img_prompt_style2, submit, img2img_interrogate, img2img_prompt_style_apply, img2img_save_style = create_toprow(is_img2img=True)
with gr.Row(elem_id='progressRow'): with gr.Row(elem_id='img2img_progress_row'):
with gr.Column(scale=1): with gr.Column(scale=1):
columnEmpty = "Empty" pass
with gr.Column(scale=1): with gr.Column(scale=1):
progressbar = gr.HTML(elem_id="progressbar") progressbar = gr.HTML(elem_id="img2img_progressbar")
img2img_preview = gr.Image(elem_id='img2img_preview', visible=False) img2img_preview = gr.Image(elem_id='img2img_preview', visible=False)
setup_progressbar(progressbar, img2img_preview) setup_progressbar(progressbar, img2img_preview, 'img2img')
with gr.Row().style(equal_height=False): with gr.Row().style(equal_height=False):
with gr.Column(variant='panel'): with gr.Column(variant='panel'):
@ -536,7 +538,6 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo):
with gr.TabItem('Inpaint'): with gr.TabItem('Inpaint'):
init_img_with_mask = gr.Image(label="Image for inpainting with mask", show_label=False, elem_id="img2maskimg", source="upload", interactive=True, type="pil", tool="sketch", image_mode="RGBA") init_img_with_mask = gr.Image(label="Image for inpainting with mask", show_label=False, elem_id="img2maskimg", source="upload", interactive=True, type="pil", tool="sketch", image_mode="RGBA")
init_img_with_mask_comment = gr.HTML(elem_id="mask_bug_info", value="<small>if the editor shows ERROR, switch to another tab and back, then to \"Upload mask\" mode above and back</small>")
init_img_inpaint = gr.Image(label="Image for img2img", show_label=False, source="upload", interactive=True, type="pil", visible=False) init_img_inpaint = gr.Image(label="Image for img2img", show_label=False, source="upload", interactive=True, type="pil", visible=False)
init_mask_inpaint = gr.Image(label="Mask", source="upload", interactive=True, type="pil", visible=False) init_mask_inpaint = gr.Image(label="Mask", source="upload", interactive=True, type="pil", visible=False)
@ -597,7 +598,6 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo):
img2img_send_to_img2img = gr.Button('Send to img2img') img2img_send_to_img2img = gr.Button('Send to img2img')
img2img_send_to_inpaint = gr.Button('Send to inpaint') img2img_send_to_inpaint = gr.Button('Send to inpaint')
img2img_send_to_extras = gr.Button('Send to extras') img2img_send_to_extras = gr.Button('Send to extras')
img2img_save_style = gr.Button('Save prompt as style')
with gr.Group(): with gr.Group():
html_info = gr.HTML() html_info = gr.HTML()
@ -608,16 +608,13 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo):
mask_mode.change( mask_mode.change(
lambda mode, img: { lambda mode, img: {
#init_img_with_mask: gr.Image.update(visible=mode == 0, value=img["image"]),
init_img_with_mask: gr_show(mode == 0), init_img_with_mask: gr_show(mode == 0),
init_img_with_mask_comment: gr_show(mode == 0),
init_img_inpaint: gr_show(mode == 1), init_img_inpaint: gr_show(mode == 1),
init_mask_inpaint: gr_show(mode == 1), init_mask_inpaint: gr_show(mode == 1),
}, },
inputs=[mask_mode, init_img_with_mask], inputs=[mask_mode, init_img_with_mask],
outputs=[ outputs=[
init_img_with_mask, init_img_with_mask,
init_img_with_mask_comment,
init_img_inpaint, init_img_inpaint,
init_mask_inpaint, init_mask_inpaint,
], ],
@ -938,18 +935,6 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo):
outputs=[text_settings], outputs=[text_settings],
) )
tabs.change(
fn=lambda x: x,
inputs=[init_img_with_mask],
outputs=[init_img_with_mask],
)
tabs_img2img_mode.change(
fn=lambda x: x,
inputs=[init_img_with_mask],
outputs=[init_img_with_mask],
)
send_to_img2img.click( send_to_img2img.click(
fn=lambda x: image_from_url_text(x), fn=lambda x: image_from_url_text(x),
_js="extract_image_from_gallery_img2img", _js="extract_image_from_gallery_img2img",

View File

@ -2,7 +2,7 @@ transformers==4.19.2
diffusers==0.3.0 diffusers==0.3.0
basicsr==1.4.2 basicsr==1.4.2
gfpgan==1.3.8 gfpgan==1.3.8
gradio==3.3.1 gradio==3.4b3
numpy==1.23.3 numpy==1.23.3
Pillow==9.2.0 Pillow==9.2.0
realesrgan==0.3.0 realesrgan==0.3.0

View File

@ -89,7 +89,7 @@
min-width: 8em !important; min-width: 8em !important;
} }
#style_index, #style2_index{ #txt2img_style_index, #txt2img_style2_index, #img2img_style_index, #img2img_style2_index{
margin-top: 1em; margin-top: 1em;
} }
@ -210,7 +210,7 @@ input[type="range"]{
#txt2img_negative_prompt, #img2img_negative_prompt{ #txt2img_negative_prompt, #img2img_negative_prompt{
} }
#progressbar{ #txt2img_progressbar, #img2img_progressbar{
position: absolute; position: absolute;
z-index: 1000; z-index: 1000;
right: 0; right: 0;
@ -219,7 +219,7 @@ input[type="range"]{
display: block; display: block;
} }
#progressRow{ #txt2img_progress_row, #img2img_progress_row{
margin-bottom: 10px; margin-bottom: 10px;
margin-top: -18px; margin-top: -18px;
} }
@ -354,7 +354,7 @@ input[type="range"]{
display:none display:none
} }
#interrupt{ #txt2img_interrupt, #img2img_interrupt{
position: absolute; position: absolute;
width: 100%; width: 100%;
height: 72px; height: 72px;