Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This change allows Lists of Prompts to be processed. #818

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ __pycache__/
# C extensions
*.so

# Visual Studio Garbage
/.vs

# Distribution / packaging
.Python
build/
Expand Down
7 changes: 4 additions & 3 deletions configs/webui/webui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ txt2img:
# 3: Save grid
# 4: Sort samples by prompt
# 5: Write sample info files
# 6: write sample info to log file
# 6: Write sample info to log file
# 7: jpg samples
# 8: Fix faces using GFPGAN
# 9: Upscale images using RealESRGAN
# 8: Iterate seed every line when processing prompt lists
# 9: Fix faces using GFPGAN
# 10: Upscale images using RealESRGAN
toggles: [1, 2, 3, 4, 5]
sampler_name: k_lms
ddim_eta: 0.0 # legacy name, applies to all algorithms.
Expand Down
59 changes: 43 additions & 16 deletions frontend/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
import frontend.ui_functions as uifn
import uuid

def draw_gradio_ui(opt, img2img=lambda x: x, txt2img=lambda x: x,imgproc=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,
def draw_gradio_ui(opt, img2img=lambda x: x, singleprompt2image=lambda x: x,imgproc=lambda x: x, promptlist2img=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,
img2img_resize_modes=None, imgproc_defaults={},imgproc_mode_toggles={},user_defaults={}, run_GFPGAN=lambda x: x, run_RealESRGAN=lambda x: x,
job_manager: JobManager = None) -> gr.Blocks:

Expand Down Expand Up @@ -102,14 +102,35 @@ def draw_gradio_ui(opt, img2img=lambda x: x, txt2img=lambda x: x,imgproc=lambda
max_lines=1, value=txt2img_defaults["variant_seed"])
txt2img_embeddings = gr.File(label="Embeddings file for textual inversion",
visible=show_embeddings)

txt2img_func = txt2img
txt2img_inputs = [txt2img_prompt, txt2img_steps, txt2img_sampling, txt2img_toggles,
with gr.Box():
with gr.Tabs() as txt2img_promptlist_tabs:
with gr.TabItem('From Textbox', id="tab_promptlist_textbox"):
txt2img_promptlist_txt = gr.TextArea(value="", interactive=True, label="List of Prompts", placeholder="Add one prompt per line to this textbox.")
with gr.TabItem('From Text File', id="tab_promptlist_file"):
txt2img_promptlist_filepath = gr.File(label='Prompt List Text File', show_label=True)
txt2img_promptlist_markdown = gr.Markdown("Upload a text file: each line will be processed once per batch.", elem_id="prompt_list_info")

txt2img_promptlist_btn = gr.Button("Generate From Prompt List", elem_id="generateFromList")
txt2img_promptlist_filepath.change( uifn.change_promptlist_filepath, inputs=[txt2img_promptlist_filepath ],
outputs=[txt2img_promptlist_txt, txt2img_promptlist_markdown, txt2img_promptlist_tabs] );
txt2img_promptlist_filepath.clear( uifn.clear_promptlist_filepath,
inputs=[txt2img_promptlist_filepath ],
outputs=[txt2img_promptlist_markdown] );

txt2img_func = singleprompt2image
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_promptlist_func = promptlist2img
txt2img_promptlist_inputs = [txt2img_promptlist_txt, 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]
txt2img_promptlist_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:
Expand All @@ -129,6 +150,11 @@ def draw_gradio_ui(opt, img2img=lambda x: x, txt2img=lambda x: x,imgproc=lambda
txt2img_inputs,
txt2img_outputs
)
txt2img_promptlist_btn.click(
txt2img_promptlist_func,
txt2img_promptlist_inputs,
txt2img_promptlist_outputs
)

# 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)
Expand Down Expand Up @@ -332,8 +358,8 @@ def img2img_submit_params():
# img2img_denoising, img2img_seed, img2img_height, img2img_width, img2img_resize,
# img2img_image_editor, img2img_image_mask, img2img_embeddings])
return (img2img_func,
img2img_inputs,
img2img_outputs)
img2img_inputs,
img2img_outputs)

img2img_btn_editor.click(*img2img_submit_params())

Expand All @@ -351,19 +377,20 @@ def img2img_submit_params():
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)


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")
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'):
imgproc_folder = gr.File(label="Batch Process", file_count="multiple",source="upload", interactive=True, type="file")
with gr.TabItem('Batch Process'):
imgproc_folder = gr.File(label="Batch Process", file_count="multiple",source="upload", 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")
Expand Down
20 changes: 17 additions & 3 deletions frontend/ui_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import base64
import re


def change_image_editor_mode(choice, cropped_image, masked_image, resize_mode, width, height):
def change_image_editor_mode(choice, cropped_image, resize_mode, width, height):
if choice == "Mask":
update_image_result = update_image_mask(cropped_image, resize_mode, width, height)
return [gr.update(visible=False), update_image_result, gr.update(visible=False), gr.update(visible=True), gr.update(visible=False), gr.update(visible=True), gr.update(visible=True)]
Expand All @@ -16,7 +15,7 @@ def change_image_editor_mode(choice, cropped_image, masked_image, resize_mode, w

def update_image_mask(cropped_image, resize_mode, width, height):
resized_cropped_image = resize_image(resize_mode, cropped_image, width, height) if cropped_image else None
return gr.update(value=resized_cropped_image, visible=True)
return gr.update(value=resized_cropped_image)

def toggle_options_gfpgan(selection):
if 0 in selection:
Expand Down Expand Up @@ -217,3 +216,18 @@ def load_settings(*values):
values[cbg_index] = [cbg_choices[i] for i in values[cbg_index]]

return values

def clear_promptlist_filepath(txt2img_promptlist_filepath):
return "Upload a text file: each line will be processed once per batch."

def change_promptlist_filepath(txt2img_promptlist_filepath):
if (txt2img_promptlist_filepath is None or txt2img_promptlist_filepath.name is None):
return gr.TextArea.update(), "Upload a text file: each line will be processed once per batch.", gr.Tabs.update()

with open(txt2img_promptlist_filepath.name) as f:
prompts = [line.rstrip() for line in f]

processed_textarea = "\n".join(prompts)
processed_markdown = "File parsed, " + str(len(prompts)) + " prompts loaded."
tabs_update = gr.Tabs.update(selected='tab_promptlist_textbox')
return processed_textarea, processed_markdown, tabs_update
Loading