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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import random
|
| 3 |
+
import os
|
| 4 |
+
import json
|
| 5 |
+
import time
|
| 6 |
+
import shared
|
| 7 |
+
import modules.config
|
| 8 |
+
import fooocus_version
|
| 9 |
+
import modules.html
|
| 10 |
+
import modules.async_worker as worker
|
| 11 |
+
import modules.constants as constants
|
| 12 |
+
import modules.flags as flags
|
| 13 |
+
import modules.gradio_hijack as grh
|
| 14 |
+
import modules.style_sorter as style_sorter
|
| 15 |
+
import modules.meta_parser
|
| 16 |
+
import args_manager
|
| 17 |
+
import copy
|
| 18 |
+
import launch
|
| 19 |
+
from extras.inpaint_mask import SAMOptions
|
| 20 |
+
|
| 21 |
+
from modules.sdxl_styles import legal_style_names
|
| 22 |
+
from modules.private_logger import get_current_html_path
|
| 23 |
+
from modules.ui_gradio_extensions import reload_javascript
|
| 24 |
+
from modules.auth import auth_enabled, check_auth
|
| 25 |
+
from modules.util import is_json
|
| 26 |
+
|
| 27 |
+
def get_task(*args):
|
| 28 |
+
args = list(args)
|
| 29 |
+
args.pop(0)
|
| 30 |
+
|
| 31 |
+
return worker.AsyncTask(args=args)
|
| 32 |
+
|
| 33 |
+
def generate_clicked(task: worker.AsyncTask):
|
| 34 |
+
import ldm_patched.modules.model_management as model_management
|
| 35 |
+
|
| 36 |
+
with model_management.interrupt_processing_mutex:
|
| 37 |
+
model_management.interrupt_processing = False
|
| 38 |
+
# outputs=[progress_html, progress_window, progress_gallery, gallery]
|
| 39 |
+
|
| 40 |
+
if len(task.args) == 0:
|
| 41 |
+
return
|
| 42 |
+
|
| 43 |
+
execution_start_time = time.perf_counter()
|
| 44 |
+
finished = False
|
| 45 |
+
|
| 46 |
+
yield gr.update(visible=True, value=modules.html.make_progress_html(1, 'Waiting for task to start ...')), \
|
| 47 |
+
gr.update(visible=True, value=None), \
|
| 48 |
+
gr.update(visible=False, value=None), \
|
| 49 |
+
gr.update(visible=False)
|
| 50 |
+
|
| 51 |
+
worker.async_tasks.append(task)
|
| 52 |
+
|
| 53 |
+
while not finished:
|
| 54 |
+
time.sleep(0.01)
|
| 55 |
+
if len(task.yields) > 0:
|
| 56 |
+
flag, product = task.yields.pop(0)
|
| 57 |
+
if flag == 'preview':
|
| 58 |
+
|
| 59 |
+
# help bad internet connection by skipping duplicated preview
|
| 60 |
+
if len(task.yields) > 0: # if we have the next item
|
| 61 |
+
if task.yields[0][0] == 'preview': # if the next item is also a preview
|
| 62 |
+
# print('Skipped one preview for better internet connection.')
|
| 63 |
+
continue
|
| 64 |
+
|
| 65 |
+
percentage, title, image = product
|
| 66 |
+
yield gr.update(visible=True, value=modules.html.make_progress_html(percentage, title)), \
|
| 67 |
+
gr.update(visible=True, value=image) if image is not None else gr.update(), \
|
| 68 |
+
gr.update(), \
|
| 69 |
+
gr.update(visible=False)
|
| 70 |
+
if flag == 'results':
|
| 71 |
+
yield gr.update(visible=True), \
|
| 72 |
+
gr.update(visible=True), \
|
| 73 |
+
gr.update(visible=True, value=product), \
|
| 74 |
+
gr.update(visible=False)
|
| 75 |
+
if flag == 'finish':
|
| 76 |
+
if not args_manager.args.disable_enhance_output_sorting:
|
| 77 |
+
product = sort_enhance_images(product, task)
|
| 78 |
+
|
| 79 |
+
yield gr.update(visible=False), \
|
| 80 |
+
gr.update(visible=False), \
|
| 81 |
+
gr.update(visible=False), \
|
| 82 |
+
gr.update(visible=True, value=product)
|
| 83 |
+
finished = True
|
| 84 |
+
|
| 85 |
+
# delete Fooocus temp images, only keep gradio temp images
|
| 86 |
+
if args_manager.args.disable_image_log:
|
| 87 |
+
for filepath in product:
|
| 88 |
+
if isinstance(filepath, str) and os.path.exists(filepath):
|
| 89 |
+
os.remove(filepath)
|
| 90 |
+
|
| 91 |
+
execution_time = time.perf_counter() - execution_start_time
|
| 92 |
+
print(f'Total time: {execution_time:.2f} seconds')
|
| 93 |
+
return
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def sort_enhance_images(images, task):
|
| 97 |
+
if not task.should_enhance or len(images) <= task.images_to_enhance_count:
|
| 98 |
+
return images
|
| 99 |
+
|
| 100 |
+
sorted_images = []
|
| 101 |
+
walk_index = task.images_to_enhance_count
|
| 102 |
+
|
| 103 |
+
for index, enhanced_img in enumerate(images[:task.images_to_enhance_count]):
|
| 104 |
+
sorted_images.append(enhanced_img)
|
| 105 |
+
if index not in task.enhance_stats:
|
| 106 |
+
continue
|
| 107 |
+
target_index = walk_index + task.enhance_stats[index]
|
| 108 |
+
if walk_index < len(images) and target_index <= len(images):
|
| 109 |
+
sorted_images += images[walk_index:target_index]
|
| 110 |
+
walk_index += task.enhance_stats[index]
|
| 111 |
+
|
| 112 |
+
return sorted_images
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def inpaint_mode_change(mode, inpaint_engine_version):
|
| 116 |
+
assert mode in modules.flags.inpaint_options
|
| 117 |
+
|
| 118 |
+
# inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts,
|
| 119 |
+
# inpaint_disable_initial_latent, inpaint_engine,
|
| 120 |
+
# inpaint_strength, inpaint_respective_field
|
| 121 |
+
|
| 122 |
+
if mode == modules.flags.inpaint_option_detail:
|
| 123 |
+
return [
|
| 124 |
+
gr.update(visible=True), gr.update(visible=False, value=[]),
|
| 125 |
+
gr.Dataset.update(visible=True, samples=modules.config.example_inpaint_prompts),
|
| 126 |
+
False, 'None', 0.5, 0.0
|
| 127 |
+
]
|
| 128 |
+
|
| 129 |
+
if inpaint_engine_version == 'empty':
|
| 130 |
+
inpaint_engine_version = modules.config.default_inpaint_engine_version
|
| 131 |
+
|
| 132 |
+
if mode == modules.flags.inpaint_option_modify:
|
| 133 |
+
return [
|
| 134 |
+
gr.update(visible=True), gr.update(visible=False, value=[]),
|
| 135 |
+
gr.Dataset.update(visible=False, samples=modules.config.example_inpaint_prompts),
|
| 136 |
+
True, inpaint_engine_version, 1.0, 0.0
|
| 137 |
+
]
|
| 138 |
+
|
| 139 |
+
return [
|
| 140 |
+
gr.update(visible=False, value=''), gr.update(visible=True),
|
| 141 |
+
gr.Dataset.update(visible=False, samples=modules.config.example_inpaint_prompts),
|
| 142 |
+
False, inpaint_engine_version, 1.0, 0.618
|
| 143 |
+
]
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
reload_javascript()
|
| 147 |
+
|
| 148 |
+
title = f'Fooocus {fooocus_version.version}'
|
| 149 |
+
|
| 150 |
+
if isinstance(args_manager.args.preset, str):
|
| 151 |
+
title += ' ' + args_manager.args.preset
|
| 152 |
+
|
| 153 |
+
shared.gradio_root = gr.Blocks(title=title).queue()
|
| 154 |
+
|
| 155 |
+
with shared.gradio_root:
|
| 156 |
+
currentTask = gr.State(worker.AsyncTask(args=[]))
|
| 157 |
+
inpaint_engine_state = gr.State('empty')
|
| 158 |
+
with gr.Row():
|
| 159 |
+
with gr.Column(scale=2):
|
| 160 |
+
with gr.Row():
|
| 161 |
+
progress_window = grh.Image(label='Preview', show_label=True, visible=False, height=768,
|
| 162 |
+
elem_classes=['main_view'])
|
| 163 |
+
progress_gallery = gr.Gallery(label='Finished Images', show_label=True, object_fit='contain',
|
| 164 |
+
height=768, visible=False, elem_classes=['main_view', 'image_gallery'])
|
| 165 |
+
progress_html = gr.HTML(value=modules.html.make_progress_html(32, 'Progress 32%'), visible=False,
|
| 166 |
+
elem_id='progress-bar', elem_classes='progress-bar')
|
| 167 |
+
gallery = gr.Gallery(label='Gallery', show_label=False, object_fit='contain', visible=True, height=768,
|
| 168 |
+
elem_classes=['resizable_area', 'main_view', 'final_gallery', 'image_gallery'],
|
| 169 |
+
elem_id='final_gallery')
|
| 170 |
+
with gr.Row():
|
| 171 |
+
with gr.Column(scale=17):
|
| 172 |
+
prompt = gr.Textbox(show_label=False, placeholder="Type prompt here or paste parameters.", elem_id='positive_prompt',
|
| 173 |
+
autofocus=True, lines=3)
|
| 174 |
+
|
| 175 |
+
default_prompt = modules.config.default_prompt
|
| 176 |
+
if isinstance(default_prompt, str) and default_prompt != '':
|
| 177 |
+
shared.gradio_root.load(lambda: default_prompt, outputs=prompt)
|
| 178 |
+
|
| 179 |
+
with gr.Column(scale=3, min_width=0):
|
| 180 |
+
generate_button = gr.Button(label="Generate", value="Generate", elem_classes='type_row', elem_id='generate_button', visible=True)
|
| 181 |
+
reset_button = gr.Button(label="Reconnect", value="Reconnect", elem_classes='type_row', elem_id='reset_button', visible=False)
|
| 182 |
+
load_parameter_button = gr.Button(label="Load Parameters", value="Load Parameters", elem_classes='type_row', elem_id='load_parameter_button', visible=False)
|
| 183 |
+
skip_button = gr.Button(label="Skip", value="Skip", elem_classes='type_row_half', elem_id='skip_button', visible=False)
|
| 184 |
+
stop_button = gr.Button(label="Stop", value="Stop", elem_classes='type_row_half', elem_id='stop_button', visible=False)
|
| 185 |
+
|
| 186 |
+
def stop_clicked(currentTask):
|
| 187 |
+
import ldm_patched.modules.model_management as model_management
|
| 188 |
+
currentTask.last_stop = 'stop'
|
| 189 |
+
if (currentTask.processing):
|
| 190 |
+
model_management.interrupt_current_processing()
|
| 191 |
+
return currentTask
|
| 192 |
+
|
| 193 |
+
def skip_clicked(currentTask):
|
| 194 |
+
import ldm_patched.modules.model_management as model_management
|
| 195 |
+
currentTask.last_stop = 'skip'
|
| 196 |
+
if (currentTask.processing):
|
| 197 |
+
model_management.interrupt_current_processing()
|
| 198 |
+
return currentTask
|
| 199 |
+
|
| 200 |
+
stop_button.click(stop_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False, _js='cancelGenerateForever')
|
| 201 |
+
skip_button.click(skip_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False)
|
| 202 |
+
with gr.Row(elem_classes='advanced_check_row'):
|
| 203 |
+
input_image_checkbox = gr.Checkbox(label='Input Image', value=modules.config.default_image_prompt_checkbox, container=False, elem_classes='min_check')
|
| 204 |
+
enhance_checkbox = gr.Checkbox(label='Enhance', value=modules.config.default_enhance_checkbox, container=False, elem_classes='min_check')
|
| 205 |
+
advanced_checkbox = gr.Checkbox(label='Advanced', value=modules.config.default_advanced_checkbox, container=False, elem_classes='min_check')
|
| 206 |
+
with gr.Row(visible=modules.config.default_image_prompt_checkbox) as image_input_panel:
|
| 207 |
+
with gr.Tabs(selected=modules.config.default_selected_image_input_tab_id):
|
| 208 |
+
with gr.Tab(label='Upscale or Variation', id='uov_tab') as uov_tab:
|
| 209 |
+
with gr.Row():
|
| 210 |
+
with gr.Column():
|
| 211 |
+
uov_input_image = grh.Image(label='Image', source='upload', type='numpy', show_label=False)
|
| 212 |
+
with gr.Column():
|
| 213 |
+
uov_method = gr.Radio(label='Upscale or Variation:', choices=flags.uov_list, value=modules.config.default_uov_method)
|
| 214 |
+
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/390" target="_blank">\U0001F4D4 Documentation</a>')
|
| 215 |
+
with gr.Tab(label='Image Prompt', id='ip_tab') as ip_tab:
|
| 216 |
+
with gr.Row():
|
| 217 |
+
ip_images = []
|
| 218 |
+
ip_types = []
|
| 219 |
+
ip_stops = []
|
| 220 |
+
ip_weights = []
|
| 221 |
+
ip_ctrls = []
|
| 222 |
+
ip_ad_cols = []
|
| 223 |
+
for image_count in range(modules.config.default_controlnet_image_count):
|
| 224 |
+
image_count += 1
|
| 225 |
+
with gr.Column():
|
| 226 |
+
ip_image = grh.Image(label='Image', source='upload', type='numpy', show_label=False, height=300, value=modules.config.default_ip_images[image_count])
|
| 227 |
+
ip_images.append(ip_image)
|
| 228 |
+
ip_ctrls.append(ip_image)
|
| 229 |
+
with gr.Column(visible=modules.config.default_image_prompt_advanced_checkbox) as ad_col:
|
| 230 |
+
with gr.Row():
|
| 231 |
+
ip_stop = gr.Slider(label='Stop At', minimum=0.0, maximum=1.0, step=0.001, value=modules.config.default_ip_stop_ats[image_count])
|
| 232 |
+
ip_stops.append(ip_stop)
|
| 233 |
+
ip_ctrls.append(ip_stop)
|
| 234 |
+
|
| 235 |
+
ip_weight = gr.Slider(label='Weight', minimum=0.0, maximum=2.0, step=0.001, value=modules.config.default_ip_weights[image_count])
|
| 236 |
+
ip_weights.append(ip_weight)
|
| 237 |
+
ip_ctrls.append(ip_weight)
|
| 238 |
+
|
| 239 |
+
ip_type = gr.Radio(label='Type', choices=flags.ip_list, value=modules.config.default_ip_types[image_count], container=False)
|
| 240 |
+
ip_types.append(ip_type)
|
| 241 |
+
ip_ctrls.append(ip_type)
|
| 242 |
+
|
| 243 |
+
ip_type.change(lambda x: flags.default_parameters[x], inputs=[ip_type], outputs=[ip_stop, ip_weight], queue=False, show_progress=False)
|
| 244 |
+
ip_ad_cols.append(ad_col)
|
| 245 |
+
ip_advanced = gr.Checkbox(label='Advanced', value=modules.config.default_image_prompt_advanced_checkbox, container=False)
|
| 246 |
+
gr.HTML('* \"Image Prompt\" is powered by Fooocus Image Mixture Engine (v1.0.1). <a href="https://github.com/lllyasviel/Fooocus/discussions/557" target="_blank">\U0001F4D4 Documentation</a>')
|
| 247 |
+
|
| 248 |
+
def ip_advance_checked(x):
|
| 249 |
+
return [gr.update(visible=x)] * len(ip_ad_cols) + \
|
| 250 |
+
[flags.default_ip] * len(ip_types) + \
|
| 251 |
+
[flags.default_parameters[flags.default_ip][0]] * len(ip_stops) + \
|
| 252 |
+
[flags.default_parameters[flags.default_ip][1]] * len(ip_weights)
|
| 253 |
+
|
| 254 |
+
ip_advanced.change(ip_advance_checked, inputs=ip_advanced,
|
| 255 |
+
outputs=ip_ad_cols + ip_types + ip_stops + ip_weights,
|
| 256 |
+
queue=False, show_progress=False)
|
| 257 |
+
|
| 258 |
+
with gr.Tab(label='Inpaint or Outpaint', id='inpaint_tab') as inpaint_tab:
|
| 259 |
+
with gr.Row():
|
| 260 |
+
with gr.Column():
|
| 261 |
+
inpaint_input_image = grh.Image(label='Image', source='upload', type='numpy', tool='sketch', height=500, brush_color="#FFFFFF", elem_id='inpaint_canvas', show_label=False)
|
| 262 |
+
inpaint_advanced_masking_checkbox = gr.Checkbox(label='Enable Advanced Masking Features', value=modules.config.default_inpaint_advanced_masking_checkbox)
|
| 263 |
+
inpaint_mode = gr.Dropdown(choices=modules.flags.inpaint_options, value=modules.config.default_inpaint_method, label='Method')
|
| 264 |
+
inpaint_additional_prompt = gr.Textbox(placeholder="Describe what you want to inpaint.", elem_id='inpaint_additional_prompt', label='Inpaint Additional Prompt', visible=False)
|
| 265 |
+
outpaint_selections = gr.CheckboxGroup(choices=['Left', 'Right', 'Top', 'Bottom'], value=[], label='Outpaint Direction')
|
| 266 |
+
example_inpaint_prompts = gr.Dataset(samples=modules.config.example_inpaint_prompts,
|
| 267 |
+
label='Additional Prompt Quick List',
|
| 268 |
+
components=[inpaint_additional_prompt],
|
| 269 |
+
visible=False)
|
| 270 |
+
gr.HTML('* Powered by Fooocus Inpaint Engine <a href="https://github.com/lllyasviel/Fooocus/discussions/414" target="_blank">\U0001F4D4 Documentation</a>')
|
| 271 |
+
example_inpaint_prompts.click(lambda x: x[0], inputs=example_inpaint_prompts, outputs=inpaint_additional_prompt, show_progress=False, queue=False)
|
| 272 |
+
|
| 273 |
+
with gr.Column(visible=modules.config.default_inpaint_advanced_masking_checkbox) as inpaint_mask_generation_col:
|
| 274 |
+
inpaint_mask_image = grh.Image(label='Mask Upload', source='upload', type='numpy', tool='sketch', height=500, brush_color="#FFFFFF", mask_opacity=1, elem_id='inpaint_mask_canvas')
|
| 275 |
+
invert_mask_checkbox = gr.Checkbox(label='Invert Mask When Generating', value=modules.config.default_invert_mask_checkbox)
|
| 276 |
+
inpaint_mask_model = gr.Dropdown(label='Mask generation model',
|
| 277 |
+
choices=flags.inpaint_mask_models,
|
| 278 |
+
value=modules.config.default_inpaint_mask_model)
|
| 279 |
+
inpaint_mask_cloth_category = gr.Dropdown(label='Cloth category',
|
| 280 |
+
choices=flags.inpaint_mask_cloth_category,
|
| 281 |
+
value=modules.config.default_inpaint_mask_cloth_category,
|
| 282 |
+
visible=False)
|
| 283 |
+
inpaint_mask_dino_prompt_text = gr.Textbox(label='Detection prompt', value='', visible=False, info='Use singular whenever possible', placeholder='Describe what you want to detect.')
|
| 284 |
+
example_inpaint_mask_dino_prompt_text = gr.Dataset(
|
| 285 |
+
samples=modules.config.example_enhance_detection_prompts,
|
| 286 |
+
label='Detection Prompt Quick List',
|
| 287 |
+
components=[inpaint_mask_dino_prompt_text],
|
| 288 |
+
visible=modules.config.default_inpaint_mask_model == 'sam')
|
| 289 |
+
example_inpaint_mask_dino_prompt_text.click(lambda x: x[0],
|
| 290 |
+
inputs=example_inpaint_mask_dino_prompt_text,
|
| 291 |
+
outputs=inpaint_mask_dino_prompt_text,
|
| 292 |
+
show_progress=False, queue=False)
|
| 293 |
+
|
| 294 |
+
with gr.Accordion("Advanced options", visible=False, open=False) as inpaint_mask_advanced_options:
|
| 295 |
+
inpaint_mask_sam_model = gr.Dropdown(label='SAM model', choices=flags.inpaint_mask_sam_model, value=modules.config.default_inpaint_mask_sam_model)
|
| 296 |
+
inpaint_mask_box_threshold = gr.Slider(label="Box Threshold", minimum=0.0, maximum=1.0, value=0.3, step=0.05)
|
| 297 |
+
inpaint_mask_text_threshold = gr.Slider(label="Text Threshold", minimum=0.0, maximum=1.0, value=0.25, step=0.05)
|
| 298 |
+
inpaint_mask_sam_max_detections = gr.Slider(label="Maximum number of detections", info="Set to 0 to detect all", minimum=0, maximum=10, value=modules.config.default_sam_max_detections, step=1, interactive=True)
|
| 299 |
+
generate_mask_button = gr.Button(value='Generate mask from image')
|
| 300 |
+
|
| 301 |
+
def generate_mask(image, mask_model, cloth_category, dino_prompt_text, sam_model, box_threshold, text_threshold, sam_max_detections, dino_erode_or_dilate, dino_debug):
|
| 302 |
+
from extras.inpaint_mask import generate_mask_from_image
|
| 303 |
+
|
| 304 |
+
extras = {}
|
| 305 |
+
sam_options = None
|
| 306 |
+
if mask_model == 'u2net_cloth_seg':
|
| 307 |
+
extras['cloth_category'] = cloth_category
|
| 308 |
+
elif mask_model == 'sam':
|
| 309 |
+
sam_options = SAMOptions(
|
| 310 |
+
dino_prompt=dino_prompt_text,
|
| 311 |
+
dino_box_threshold=box_threshold,
|
| 312 |
+
dino_text_threshold=text_threshold,
|
| 313 |
+
dino_erode_or_dilate=dino_erode_or_dilate,
|
| 314 |
+
dino_debug=dino_debug,
|
| 315 |
+
max_detections=sam_max_detections,
|
| 316 |
+
model_type=sam_model
|
| 317 |
+
)
|
| 318 |
+
|
| 319 |
+
mask, _, _, _ = generate_mask_from_image(image, mask_model, extras, sam_options)
|
| 320 |
+
|
| 321 |
+
return mask
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
inpaint_mask_model.change(lambda x: [gr.update(visible=x == 'u2net_cloth_seg')] +
|
| 325 |
+
[gr.update(visible=x == 'sam')] * 2 +
|
| 326 |
+
[gr.Dataset.update(visible=x == 'sam',
|
| 327 |
+
samples=modules.config.example_enhance_detection_prompts)],
|
| 328 |
+
inputs=inpaint_mask_model,
|
| 329 |
+
outputs=[inpaint_mask_cloth_category,
|
| 330 |
+
inpaint_mask_dino_prompt_text,
|
| 331 |
+
inpaint_mask_advanced_options,
|
| 332 |
+
example_inpaint_mask_dino_prompt_text],
|
| 333 |
+
queue=False, show_progress=False)
|
| 334 |
+
|
| 335 |
+
with gr.Tab(label='Describe', id='describe_tab') as describe_tab:
|
| 336 |
+
with gr.Row():
|
| 337 |
+
with gr.Column():
|
| 338 |
+
describe_input_image = grh.Image(label='Image', source='upload', type='numpy', show_label=False)
|
| 339 |
+
with gr.Column():
|
| 340 |
+
describe_methods = gr.CheckboxGroup(
|
| 341 |
+
label='Content Type',
|
| 342 |
+
choices=flags.describe_types,
|
| 343 |
+
value=modules.config.default_describe_content_type)
|
| 344 |
+
describe_apply_styles = gr.Checkbox(label='Apply Styles', value=modules.config.default_describe_apply_prompts_checkbox)
|
| 345 |
+
describe_btn = gr.Button(value='Describe this Image into Prompt')
|
| 346 |
+
describe_image_size = gr.Textbox(label='Image Size and Recommended Size', elem_id='describe_image_size', visible=False)
|
| 347 |
+
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/1363" target="_blank">\U0001F4D4 Documentation</a>')
|
| 348 |
+
|
| 349 |
+
def trigger_show_image_properties(image):
|
| 350 |
+
value = modules.util.get_image_size_info(image, modules.flags.sdxl_aspect_ratios)
|
| 351 |
+
return gr.update(value=value, visible=True)
|
| 352 |
+
|
| 353 |
+
describe_input_image.upload(trigger_show_image_properties, inputs=describe_input_image,
|
| 354 |
+
outputs=describe_image_size, show_progress=False, queue=False)
|
| 355 |
+
|
| 356 |
+
with gr.Tab(label='Enhance', id='enhance_tab') as enhance_tab:
|
| 357 |
+
with gr.Row():
|
| 358 |
+
with gr.Column():
|
| 359 |
+
enhance_input_image = grh.Image(label='Use with Enhance, skips image generation', source='upload', type='numpy')
|
| 360 |
+
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/3281" target="_blank">\U0001F4D4 Documentation</a>')
|
| 361 |
+
|
| 362 |
+
with gr.Tab(label='Metadata', id='metadata_tab') as metadata_tab:
|
| 363 |
+
with gr.Column():
|
| 364 |
+
metadata_input_image = grh.Image(label='For images created by Fooocus', source='upload', type='pil')
|
| 365 |
+
metadata_json = gr.JSON(label='Metadata')
|
| 366 |
+
metadata_import_button = gr.Button(value='Apply Metadata')
|
| 367 |
+
|
| 368 |
+
def trigger_metadata_preview(file):
|
| 369 |
+
parameters, metadata_scheme = modules.meta_parser.read_info_from_image(file)
|
| 370 |
+
|
| 371 |
+
results = {}
|
| 372 |
+
if parameters is not None:
|
| 373 |
+
results['parameters'] = parameters
|
| 374 |
+
|
| 375 |
+
if isinstance(metadata_scheme, flags.MetadataScheme):
|
| 376 |
+
results['metadata_scheme'] = metadata_scheme.value
|
| 377 |
+
|
| 378 |
+
return results
|
| 379 |
+
|
| 380 |
+
metadata_input_image.upload(trigger_metadata_preview, inputs=metadata_input_image,
|
| 381 |
+
outputs=metadata_json, queue=False, show_progress=True)
|
| 382 |
+
|
| 383 |
+
with gr.Row(visible=modules.config.default_enhance_checkbox) as enhance_input_panel:
|
| 384 |
+
with gr.Tabs():
|
| 385 |
+
with gr.Tab(label='Upscale or Variation'):
|
| 386 |
+
with gr.Row():
|
| 387 |
+
with gr.Column():
|
| 388 |
+
enhance_uov_method = gr.Radio(label='Upscale or Variation:', choices=flags.uov_list,
|
| 389 |
+
value=modules.config.default_enhance_uov_method)
|
| 390 |
+
enhance_uov_processing_order = gr.Radio(label='Order of Processing',
|
| 391 |
+
info='Use before to enhance small details and after to enhance large areas.',
|
| 392 |
+
choices=flags.enhancement_uov_processing_order,
|
| 393 |
+
value=modules.config.default_enhance_uov_processing_order)
|
| 394 |
+
enhance_uov_prompt_type = gr.Radio(label='Prompt',
|
| 395 |
+
info='Choose which prompt to use for Upscale or Variation.',
|
| 396 |
+
choices=flags.enhancement_uov_prompt_types,
|
| 397 |
+
value=modules.config.default_enhance_uov_prompt_type,
|
| 398 |
+
visible=modules.config.default_enhance_uov_processing_order == flags.enhancement_uov_after)
|
| 399 |
+
|
| 400 |
+
enhance_uov_processing_order.change(lambda x: gr.update(visible=x == flags.enhancement_uov_after),
|
| 401 |
+
inputs=enhance_uov_processing_order,
|
| 402 |
+
outputs=enhance_uov_prompt_type,
|
| 403 |
+
queue=False, show_progress=False)
|
| 404 |
+
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/3281" target="_blank">\U0001F4D4 Documentation</a>')
|
| 405 |
+
enhance_ctrls = []
|
| 406 |
+
enhance_inpaint_mode_ctrls = []
|
| 407 |
+
enhance_inpaint_engine_ctrls = []
|
| 408 |
+
enhance_inpaint_update_ctrls = []
|
| 409 |
+
for index in range(modules.config.default_enhance_tabs):
|
| 410 |
+
with gr.Tab(label=f'#{index + 1}') as enhance_tab_item:
|
| 411 |
+
enhance_enabled = gr.Checkbox(label='Enable', value=False, elem_classes='min_check',
|
| 412 |
+
container=False)
|
| 413 |
+
|
| 414 |
+
enhance_mask_dino_prompt_text = gr.Textbox(label='Detection prompt',
|
| 415 |
+
info='Use singular whenever possible',
|
| 416 |
+
placeholder='Describe what you want to detect.',
|
| 417 |
+
interactive=True,
|
| 418 |
+
visible=modules.config.default_enhance_inpaint_mask_model == 'sam')
|
| 419 |
+
example_enhance_mask_dino_prompt_text = gr.Dataset(
|
| 420 |
+
samples=modules.config.example_enhance_detection_prompts,
|
| 421 |
+
label='Detection Prompt Quick List',
|
| 422 |
+
components=[enhance_mask_dino_prompt_text],
|
| 423 |
+
visible=modules.config.default_enhance_inpaint_mask_model == 'sam')
|
| 424 |
+
example_enhance_mask_dino_prompt_text.click(lambda x: x[0],
|
| 425 |
+
inputs=example_enhance_mask_dino_prompt_text,
|
| 426 |
+
outputs=enhance_mask_dino_prompt_text,
|
| 427 |
+
show_progress=False, queue=False)
|
| 428 |
+
|
| 429 |
+
enhance_prompt = gr.Textbox(label="Enhancement positive prompt",
|
| 430 |
+
placeholder="Uses original prompt instead if empty.",
|
| 431 |
+
elem_id='enhance_prompt')
|
| 432 |
+
enhance_negative_prompt = gr.Textbox(label="Enhancement negative prompt",
|
| 433 |
+
placeholder="Uses original negative prompt instead if empty.",
|
| 434 |
+
elem_id='enhance_negative_prompt')
|
| 435 |
+
|
| 436 |
+
with gr.Accordion("Detection", open=False):
|
| 437 |
+
enhance_mask_model = gr.Dropdown(label='Mask generation model',
|
| 438 |
+
choices=flags.inpaint_mask_models,
|
| 439 |
+
value=modules.config.default_enhance_inpaint_mask_model)
|
| 440 |
+
enhance_mask_cloth_category = gr.Dropdown(label='Cloth category',
|
| 441 |
+
choices=flags.inpaint_mask_cloth_category,
|
| 442 |
+
value=modules.config.default_inpaint_mask_cloth_category,
|
| 443 |
+
visible=modules.config.default_enhance_inpaint_mask_model == 'u2net_cloth_seg',
|
| 444 |
+
interactive=True)
|
| 445 |
+
|
| 446 |
+
with gr.Accordion("SAM Options",
|
| 447 |
+
visible=modules.config.default_enhance_inpaint_mask_model == 'sam',
|
| 448 |
+
open=False) as sam_options:
|
| 449 |
+
enhance_mask_sam_model = gr.Dropdown(label='SAM model',
|
| 450 |
+
choices=flags.inpaint_mask_sam_model,
|
| 451 |
+
value=modules.config.default_inpaint_mask_sam_model,
|
| 452 |
+
interactive=True)
|
| 453 |
+
enhance_mask_box_threshold = gr.Slider(label="Box Threshold", minimum=0.0,
|
| 454 |
+
maximum=1.0, value=0.3, step=0.05,
|
| 455 |
+
interactive=True)
|
| 456 |
+
enhance_mask_text_threshold = gr.Slider(label="Text Threshold", minimum=0.0,
|
| 457 |
+
maximum=1.0, value=0.25, step=0.05,
|
| 458 |
+
interactive=True)
|
| 459 |
+
enhance_mask_sam_max_detections = gr.Slider(label="Maximum number of detections",
|
| 460 |
+
info="Set to 0 to detect all",
|
| 461 |
+
minimum=0, maximum=10,
|
| 462 |
+
value=modules.config.default_sam_max_detections,
|
| 463 |
+
step=1, interactive=True)
|
| 464 |
+
|
| 465 |
+
with gr.Accordion("Inpaint", visible=True, open=False):
|
| 466 |
+
enhance_inpaint_mode = gr.Dropdown(choices=modules.flags.inpaint_options,
|
| 467 |
+
value=modules.config.default_inpaint_method,
|
| 468 |
+
label='Method', interactive=True)
|
| 469 |
+
enhance_inpaint_disable_initial_latent = gr.Checkbox(
|
| 470 |
+
label='Disable initial latent in inpaint', value=False)
|
| 471 |
+
enhance_inpaint_engine = gr.Dropdown(label='Inpaint Engine',
|
| 472 |
+
value=modules.config.default_inpaint_engine_version,
|
| 473 |
+
choices=flags.inpaint_engine_versions,
|
| 474 |
+
info='Version of Fooocus inpaint model. If set, use performance Quality or Speed (no performance LoRAs) for best results.')
|
| 475 |
+
enhance_inpaint_strength = gr.Slider(label='Inpaint Denoising Strength',
|
| 476 |
+
minimum=0.0, maximum=1.0, step=0.001,
|
| 477 |
+
value=1.0,
|
| 478 |
+
info='Same as the denoising strength in A1111 inpaint. '
|
| 479 |
+
'Only used in inpaint, not used in outpaint. '
|
| 480 |
+
'(Outpaint always use 1.0)')
|
| 481 |
+
enhance_inpaint_respective_field = gr.Slider(label='Inpaint Respective Field',
|
| 482 |
+
minimum=0.0, maximum=1.0, step=0.001,
|
| 483 |
+
value=0.618,
|
| 484 |
+
info='The area to inpaint. '
|
| 485 |
+
'Value 0 is same as "Only Masked" in A1111. '
|
| 486 |
+
'Value 1 is same as "Whole Image" in A1111. '
|
| 487 |
+
'Only used in inpaint, not used in outpaint. '
|
| 488 |
+
'(Outpaint always use 1.0)')
|
| 489 |
+
enhance_inpaint_erode_or_dilate = gr.Slider(label='Mask Erode or Dilate',
|
| 490 |
+
minimum=-64, maximum=64, step=1, value=0,
|
| 491 |
+
info='Positive value will make white area in the mask larger, '
|
| 492 |
+
'negative value will make white area smaller. '
|
| 493 |
+
'(default is 0, always processed before any mask invert)')
|
| 494 |
+
enhance_mask_invert = gr.Checkbox(label='Invert Mask', value=False)
|
| 495 |
+
|
| 496 |
+
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/3281" target="_blank">\U0001F4D4 Documentation</a>')
|
| 497 |
+
|
| 498 |
+
enhance_ctrls += [
|
| 499 |
+
enhance_enabled,
|
| 500 |
+
enhance_mask_dino_prompt_text,
|
| 501 |
+
enhance_prompt,
|
| 502 |
+
enhance_negative_prompt,
|
| 503 |
+
enhance_mask_model,
|
| 504 |
+
enhance_mask_cloth_category,
|
| 505 |
+
enhance_mask_sam_model,
|
| 506 |
+
enhance_mask_text_threshold,
|
| 507 |
+
enhance_mask_box_threshold,
|
| 508 |
+
enhance_mask_sam_max_detections,
|
| 509 |
+
enhance_inpaint_disable_initial_latent,
|
| 510 |
+
enhance_inpaint_engine,
|
| 511 |
+
enhance_inpaint_strength,
|
| 512 |
+
enhance_inpaint_respective_field,
|
| 513 |
+
enhance_inpaint_erode_or_dilate,
|
| 514 |
+
enhance_mask_invert
|
| 515 |
+
]
|
| 516 |
+
|
| 517 |
+
enhance_inpaint_mode_ctrls += [enhance_inpaint_mode]
|
| 518 |
+
enhance_inpaint_engine_ctrls += [enhance_inpaint_engine]
|
| 519 |
+
|
| 520 |
+
enhance_inpaint_update_ctrls += [[
|
| 521 |
+
enhance_inpaint_mode, enhance_inpaint_disable_initial_latent, enhance_inpaint_engine,
|
| 522 |
+
enhance_inpaint_strength, enhance_inpaint_respective_field
|
| 523 |
+
]]
|
| 524 |
+
|
| 525 |
+
enhance_inpaint_mode.change(inpaint_mode_change, inputs=[enhance_inpaint_mode, inpaint_engine_state], outputs=[
|
| 526 |
+
inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts,
|
| 527 |
+
enhance_inpaint_disable_initial_latent, enhance_inpaint_engine,
|
| 528 |
+
enhance_inpaint_strength, enhance_inpaint_respective_field
|
| 529 |
+
], show_progress=False, queue=False)
|
| 530 |
+
|
| 531 |
+
enhance_mask_model.change(
|
| 532 |
+
lambda x: [gr.update(visible=x == 'u2net_cloth_seg')] +
|
| 533 |
+
[gr.update(visible=x == 'sam')] * 2 +
|
| 534 |
+
[gr.Dataset.update(visible=x == 'sam',
|
| 535 |
+
samples=modules.config.example_enhance_detection_prompts)],
|
| 536 |
+
inputs=enhance_mask_model,
|
| 537 |
+
outputs=[enhance_mask_cloth_category, enhance_mask_dino_prompt_text, sam_options,
|
| 538 |
+
example_enhance_mask_dino_prompt_text],
|
| 539 |
+
queue=False, show_progress=False)
|
| 540 |
+
|
| 541 |
+
switch_js = "(x) => {if(x){viewer_to_bottom(100);viewer_to_bottom(500);}else{viewer_to_top();} return x;}"
|
| 542 |
+
down_js = "() => {viewer_to_bottom();}"
|
| 543 |
+
|
| 544 |
+
input_image_checkbox.change(lambda x: gr.update(visible=x), inputs=input_image_checkbox,
|
| 545 |
+
outputs=image_input_panel, queue=False, show_progress=False, _js=switch_js)
|
| 546 |
+
ip_advanced.change(lambda: None, queue=False, show_progress=False, _js=down_js)
|
| 547 |
+
|
| 548 |
+
current_tab = gr.Textbox(value='uov', visible=False)
|
| 549 |
+
uov_tab.select(lambda: 'uov', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
|
| 550 |
+
inpaint_tab.select(lambda: 'inpaint', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
|
| 551 |
+
ip_tab.select(lambda: 'ip', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
|
| 552 |
+
describe_tab.select(lambda: 'desc', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
|
| 553 |
+
enhance_tab.select(lambda: 'enhance', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
|
| 554 |
+
metadata_tab.select(lambda: 'metadata', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
|
| 555 |
+
enhance_checkbox.change(lambda x: gr.update(visible=x), inputs=enhance_checkbox,
|
| 556 |
+
outputs=enhance_input_panel, queue=False, show_progress=False, _js=switch_js)
|
| 557 |
+
|
| 558 |
+
with gr.Column(scale=1, visible=modules.config.default_advanced_checkbox) as advanced_column:
|
| 559 |
+
with gr.Tab(label='Settings'):
|
| 560 |
+
if not args_manager.args.disable_preset_selection:
|
| 561 |
+
preset_selection = gr.Dropdown(label='Preset',
|
| 562 |
+
choices=modules.config.available_presets,
|
| 563 |
+
value=args_manager.args.preset if args_manager.args.preset else "initial",
|
| 564 |
+
interactive=True)
|
| 565 |
+
|
| 566 |
+
performance_selection = gr.Radio(label='Performance',
|
| 567 |
+
choices=flags.Performance.values(),
|
| 568 |
+
value=modules.config.default_performance,
|
| 569 |
+
elem_classes=['performance_selection'])
|
| 570 |
+
|
| 571 |
+
with gr.Accordion(label='Aspect Ratios', open=False, elem_id='aspect_ratios_accordion') as aspect_ratios_accordion:
|
| 572 |
+
aspect_ratios_selection = gr.Radio(label='Aspect Ratios', show_label=False,
|
| 573 |
+
choices=modules.config.available_aspect_ratios_labels,
|
| 574 |
+
value=modules.config.default_aspect_ratio,
|
| 575 |
+
info='width × height',
|
| 576 |
+
elem_classes='aspect_ratios')
|
| 577 |
+
|
| 578 |
+
aspect_ratios_selection.change(lambda x: None, inputs=aspect_ratios_selection, queue=False, show_progress=False, _js='(x)=>{refresh_aspect_ratios_label(x);}')
|
| 579 |
+
shared.gradio_root.load(lambda x: None, inputs=aspect_ratios_selection, queue=False, show_progress=False, _js='(x)=>{refresh_aspect_ratios_label(x);}')
|
| 580 |
+
|
| 581 |
+
image_number = gr.Slider(label='Image Number', minimum=1, maximum=modules.config.default_max_image_number, step=1, value=modules.config.default_image_number)
|
| 582 |
+
|
| 583 |
+
output_format = gr.Radio(label='Output Format',
|
| 584 |
+
choices=flags.OutputFormat.list(),
|
| 585 |
+
value=modules.config.default_output_format)
|
| 586 |
+
|
| 587 |
+
negative_prompt = gr.Textbox(label='Negative Prompt', show_label=True, placeholder="Type prompt here.",
|
| 588 |
+
info='Describing what you do not want to see.', lines=2,
|
| 589 |
+
elem_id='negative_prompt',
|
| 590 |
+
value=modules.config.default_prompt_negative)
|
| 591 |
+
seed_random = gr.Checkbox(label='Random', value=True)
|
| 592 |
+
image_seed = gr.Textbox(label='Seed', value=0, max_lines=1, visible=False) # workaround for https://github.com/gradio-app/gradio/issues/5354
|
| 593 |
+
|
| 594 |
+
def random_checked(r):
|
| 595 |
+
return gr.update(visible=not r)
|
| 596 |
+
|
| 597 |
+
def refresh_seed(r, seed_string):
|
| 598 |
+
if r:
|
| 599 |
+
return random.randint(constants.MIN_SEED, constants.MAX_SEED)
|
| 600 |
+
else:
|
| 601 |
+
try:
|
| 602 |
+
seed_value = int(seed_string)
|
| 603 |
+
if constants.MIN_SEED <= seed_value <= constants.MAX_SEED:
|
| 604 |
+
return seed_value
|
| 605 |
+
except ValueError:
|
| 606 |
+
pass
|
| 607 |
+
return random.randint(constants.MIN_SEED, constants.MAX_SEED)
|
| 608 |
+
|
| 609 |
+
seed_random.change(random_checked, inputs=[seed_random], outputs=[image_seed],
|
| 610 |
+
queue=False, show_progress=False)
|
| 611 |
+
|
| 612 |
+
def update_history_link():
|
| 613 |
+
if args_manager.args.disable_image_log:
|
| 614 |
+
return gr.update(value='')
|
| 615 |
+
|
| 616 |
+
return gr.update(value=f'<a href="file={get_current_html_path(output_format)}" target="_blank">\U0001F4DA History Log</a>')
|
| 617 |
+
|
| 618 |
+
history_link = gr.HTML()
|
| 619 |
+
shared.gradio_root.load(update_history_link, outputs=history_link, queue=False, show_progress=False)
|
| 620 |
+
|
| 621 |
+
with gr.Tab(label='Styles', elem_classes=['style_selections_tab']):
|
| 622 |
+
style_sorter.try_load_sorted_styles(
|
| 623 |
+
style_names=legal_style_names,
|
| 624 |
+
default_selected=modules.config.default_styles)
|
| 625 |
+
|
| 626 |
+
style_search_bar = gr.Textbox(show_label=False, container=False,
|
| 627 |
+
placeholder="\U0001F50E Type here to search styles ...",
|
| 628 |
+
value="",
|
| 629 |
+
label='Search Styles')
|
| 630 |
+
style_selections = gr.CheckboxGroup(show_label=False, container=False,
|
| 631 |
+
choices=copy.deepcopy(style_sorter.all_styles),
|
| 632 |
+
value=copy.deepcopy(modules.config.default_styles),
|
| 633 |
+
label='Selected Styles',
|
| 634 |
+
elem_classes=['style_selections'])
|
| 635 |
+
gradio_receiver_style_selections = gr.Textbox(elem_id='gradio_receiver_style_selections', visible=False)
|
| 636 |
+
|
| 637 |
+
shared.gradio_root.load(lambda: gr.update(choices=copy.deepcopy(style_sorter.all_styles)),
|
| 638 |
+
outputs=style_selections)
|
| 639 |
+
|
| 640 |
+
style_search_bar.change(style_sorter.search_styles,
|
| 641 |
+
inputs=[style_selections, style_search_bar],
|
| 642 |
+
outputs=style_selections,
|
| 643 |
+
queue=False,
|
| 644 |
+
show_progress=False).then(
|
| 645 |
+
lambda: None, _js='()=>{refresh_style_localization();}')
|
| 646 |
+
|
| 647 |
+
gradio_receiver_style_selections.input(style_sorter.sort_styles,
|
| 648 |
+
inputs=style_selections,
|
| 649 |
+
outputs=style_selections,
|
| 650 |
+
queue=False,
|
| 651 |
+
show_progress=False).then(
|
| 652 |
+
lambda: None, _js='()=>{refresh_style_localization();}')
|
| 653 |
+
|
| 654 |
+
with gr.Tab(label='Models'):
|
| 655 |
+
with gr.Group():
|
| 656 |
+
with gr.Row():
|
| 657 |
+
base_model = gr.Dropdown(label='Base Model (SDXL only)', choices=modules.config.model_filenames, value=modules.config.default_base_model_name, show_label=True)
|
| 658 |
+
refiner_model = gr.Dropdown(label='Refiner (SDXL or SD 1.5)', choices=['None'] + modules.config.model_filenames, value=modules.config.default_refiner_model_name, show_label=True)
|
| 659 |
+
|
| 660 |
+
refiner_switch = gr.Slider(label='Refiner Switch At', minimum=0.1, maximum=1.0, step=0.0001,
|
| 661 |
+
info='Use 0.4 for SD1.5 realistic models; '
|
| 662 |
+
'or 0.667 for SD1.5 anime models; '
|
| 663 |
+
'or 0.8 for XL-refiners; '
|
| 664 |
+
'or any value for switching two SDXL models.',
|
| 665 |
+
value=modules.config.default_refiner_switch,
|
| 666 |
+
visible=modules.config.default_refiner_model_name != 'None')
|
| 667 |
+
|
| 668 |
+
refiner_model.change(lambda x: gr.update(visible=x != 'None'),
|
| 669 |
+
inputs=refiner_model, outputs=refiner_switch, show_progress=False, queue=False)
|
| 670 |
+
|
| 671 |
+
with gr.Group():
|
| 672 |
+
lora_ctrls = []
|
| 673 |
+
|
| 674 |
+
for i, (enabled, filename, weight) in enumerate(modules.config.default_loras):
|
| 675 |
+
with gr.Row():
|
| 676 |
+
lora_enabled = gr.Checkbox(label='Enable', value=enabled,
|
| 677 |
+
elem_classes=['lora_enable', 'min_check'], scale=1)
|
| 678 |
+
lora_model = gr.Dropdown(label=f'LoRA {i + 1}',
|
| 679 |
+
choices=['None'] + modules.config.lora_filenames, value=filename,
|
| 680 |
+
elem_classes='lora_model', scale=5)
|
| 681 |
+
lora_weight = gr.Slider(label='Weight', minimum=modules.config.default_loras_min_weight,
|
| 682 |
+
maximum=modules.config.default_loras_max_weight, step=0.01, value=weight,
|
| 683 |
+
elem_classes='lora_weight', scale=5)
|
| 684 |
+
lora_ctrls += [lora_enabled, lora_model, lora_weight]
|
| 685 |
+
|
| 686 |
+
with gr.Row():
|
| 687 |
+
refresh_files = gr.Button(label='Refresh', value='\U0001f504 Refresh All Files', variant='secondary', elem_classes='refresh_button')
|
| 688 |
+
with gr.Tab(label='Advanced'):
|
| 689 |
+
guidance_scale = gr.Slider(label='Guidance Scale', minimum=1.0, maximum=30.0, step=0.01,
|
| 690 |
+
value=modules.config.default_cfg_scale,
|
| 691 |
+
info='Higher value means style is cleaner, vivider, and more artistic.')
|
| 692 |
+
sharpness = gr.Slider(label='Image Sharpness', minimum=0.0, maximum=30.0, step=0.001,
|
| 693 |
+
value=modules.config.default_sample_sharpness,
|
| 694 |
+
info='Higher value means image and texture are sharper.')
|
| 695 |
+
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/117" target="_blank">\U0001F4D4 Documentation</a>')
|
| 696 |
+
dev_mode = gr.Checkbox(label='Developer Debug Mode', value=modules.config.default_developer_debug_mode_checkbox, container=False)
|
| 697 |
+
|
| 698 |
+
with gr.Column(visible=modules.config.default_developer_debug_mode_checkbox) as dev_tools:
|
| 699 |
+
with gr.Tab(label='Debug Tools'):
|
| 700 |
+
adm_scaler_positive = gr.Slider(label='Positive ADM Guidance Scaler', minimum=0.1, maximum=3.0,
|
| 701 |
+
step=0.001, value=1.5, info='The scaler multiplied to positive ADM (use 1.0 to disable). ')
|
| 702 |
+
adm_scaler_negative = gr.Slider(label='Negative ADM Guidance Scaler', minimum=0.1, maximum=3.0,
|
| 703 |
+
step=0.001, value=0.8, info='The scaler multiplied to negative ADM (use 1.0 to disable). ')
|
| 704 |
+
adm_scaler_end = gr.Slider(label='ADM Guidance End At Step', minimum=0.0, maximum=1.0,
|
| 705 |
+
step=0.001, value=0.3,
|
| 706 |
+
info='When to end the guidance from positive/negative ADM. ')
|
| 707 |
+
|
| 708 |
+
refiner_swap_method = gr.Dropdown(label='Refiner swap method', value=flags.refiner_swap_method,
|
| 709 |
+
choices=['joint', 'separate', 'vae'])
|
| 710 |
+
|
| 711 |
+
adaptive_cfg = gr.Slider(label='CFG Mimicking from TSNR', minimum=1.0, maximum=30.0, step=0.01,
|
| 712 |
+
value=modules.config.default_cfg_tsnr,
|
| 713 |
+
info='Enabling Fooocus\'s implementation of CFG mimicking for TSNR '
|
| 714 |
+
'(effective when real CFG > mimicked CFG).')
|
| 715 |
+
clip_skip = gr.Slider(label='CLIP Skip', minimum=1, maximum=flags.clip_skip_max, step=1,
|
| 716 |
+
value=modules.config.default_clip_skip,
|
| 717 |
+
info='Bypass CLIP layers to avoid overfitting (use 1 to not skip any layers, 2 is recommended).')
|
| 718 |
+
sampler_name = gr.Dropdown(label='Sampler', choices=flags.sampler_list,
|
| 719 |
+
value=modules.config.default_sampler)
|
| 720 |
+
scheduler_name = gr.Dropdown(label='Scheduler', choices=flags.scheduler_list,
|
| 721 |
+
value=modules.config.default_scheduler)
|
| 722 |
+
vae_name = gr.Dropdown(label='VAE', choices=[modules.flags.default_vae] + modules.config.vae_filenames,
|
| 723 |
+
value=modules.config.default_vae, show_label=True)
|
| 724 |
+
|
| 725 |
+
generate_image_grid = gr.Checkbox(label='Generate Image Grid for Each Batch',
|
| 726 |
+
info='(Experimental) This may cause performance problems on some computers and certain internet conditions.',
|
| 727 |
+
value=False)
|
| 728 |
+
|
| 729 |
+
overwrite_step = gr.Slider(label='Forced Overwrite of Sampling Step',
|
| 730 |
+
minimum=-1, maximum=200, step=1,
|
| 731 |
+
value=modules.config.default_overwrite_step,
|
| 732 |
+
info='Set as -1 to disable. For developer debugging.')
|
| 733 |
+
overwrite_switch = gr.Slider(label='Forced Overwrite of Refiner Switch Step',
|
| 734 |
+
minimum=-1, maximum=200, step=1,
|
| 735 |
+
value=modules.config.default_overwrite_switch,
|
| 736 |
+
info='Set as -1 to disable. For developer debugging.')
|
| 737 |
+
overwrite_width = gr.Slider(label='Forced Overwrite of Generating Width',
|
| 738 |
+
minimum=-1, maximum=2048, step=1, value=-1,
|
| 739 |
+
info='Set as -1 to disable. For developer debugging. '
|
| 740 |
+
'Results will be worse for non-standard numbers that SDXL is not trained on.')
|
| 741 |
+
overwrite_height = gr.Slider(label='Forced Overwrite of Generating Height',
|
| 742 |
+
minimum=-1, maximum=2048, step=1, value=-1,
|
| 743 |
+
info='Set as -1 to disable. For developer debugging. '
|
| 744 |
+
'Results will be worse for non-standard numbers that SDXL is not trained on.')
|
| 745 |
+
overwrite_vary_strength = gr.Slider(label='Forced Overwrite of Denoising Strength of "Vary"',
|
| 746 |
+
minimum=-1, maximum=1.0, step=0.001, value=-1,
|
| 747 |
+
info='Set as negative number to disable. For developer debugging.')
|
| 748 |
+
overwrite_upscale_strength = gr.Slider(label='Forced Overwrite of Denoising Strength of "Upscale"',
|
| 749 |
+
minimum=-1, maximum=1.0, step=0.001,
|
| 750 |
+
value=modules.config.default_overwrite_upscale,
|
| 751 |
+
info='Set as negative number to disable. For developer debugging.')
|
| 752 |
+
|
| 753 |
+
disable_preview = gr.Checkbox(label='Disable Preview', value=modules.config.default_black_out_nsfw,
|
| 754 |
+
interactive=not modules.config.default_black_out_nsfw,
|
| 755 |
+
info='Disable preview during generation.')
|
| 756 |
+
disable_intermediate_results = gr.Checkbox(label='Disable Intermediate Results',
|
| 757 |
+
value=flags.Performance.has_restricted_features(modules.config.default_performance),
|
| 758 |
+
info='Disable intermediate results during generation, only show final gallery.')
|
| 759 |
+
|
| 760 |
+
disable_seed_increment = gr.Checkbox(label='Disable seed increment',
|
| 761 |
+
info='Disable automatic seed increment when image number is > 1.',
|
| 762 |
+
value=False)
|
| 763 |
+
read_wildcards_in_order = gr.Checkbox(label="Read wildcards in order", value=False)
|
| 764 |
+
|
| 765 |
+
black_out_nsfw = gr.Checkbox(label='Black Out NSFW', value=modules.config.default_black_out_nsfw,
|
| 766 |
+
interactive=not modules.config.default_black_out_nsfw,
|
| 767 |
+
info='Use black image if NSFW is detected.')
|
| 768 |
+
|
| 769 |
+
black_out_nsfw.change(lambda x: gr.update(value=x, interactive=not x),
|
| 770 |
+
inputs=black_out_nsfw, outputs=disable_preview, queue=False,
|
| 771 |
+
show_progress=False)
|
| 772 |
+
|
| 773 |
+
if not args_manager.args.disable_image_log:
|
| 774 |
+
save_final_enhanced_image_only = gr.Checkbox(label='Save only final enhanced image',
|
| 775 |
+
value=modules.config.default_save_only_final_enhanced_image)
|
| 776 |
+
|
| 777 |
+
if not args_manager.args.disable_metadata:
|
| 778 |
+
save_metadata_to_images = gr.Checkbox(label='Save Metadata to Images', value=modules.config.default_save_metadata_to_images,
|
| 779 |
+
info='Adds parameters to generated images allowing manual regeneration.')
|
| 780 |
+
metadata_scheme = gr.Radio(label='Metadata Scheme', choices=flags.metadata_scheme, value=modules.config.default_metadata_scheme,
|
| 781 |
+
info='Image Prompt parameters are not included. Use png and a1111 for compatibility with Civitai.',
|
| 782 |
+
visible=modules.config.default_save_metadata_to_images)
|
| 783 |
+
|
| 784 |
+
save_metadata_to_images.change(lambda x: gr.update(visible=x), inputs=[save_metadata_to_images], outputs=[metadata_scheme],
|
| 785 |
+
queue=False, show_progress=False)
|
| 786 |
+
|
| 787 |
+
with gr.Tab(label='Control'):
|
| 788 |
+
debugging_cn_preprocessor = gr.Checkbox(label='Debug Preprocessors', value=False,
|
| 789 |
+
info='See the results from preprocessors.')
|
| 790 |
+
skipping_cn_preprocessor = gr.Checkbox(label='Skip Preprocessors', value=False,
|
| 791 |
+
info='Do not preprocess images. (Inputs are already canny/depth/cropped-face/etc.)')
|
| 792 |
+
|
| 793 |
+
mixing_image_prompt_and_vary_upscale = gr.Checkbox(label='Mixing Image Prompt and Vary/Upscale',
|
| 794 |
+
value=False)
|
| 795 |
+
mixing_image_prompt_and_inpaint = gr.Checkbox(label='Mixing Image Prompt and Inpaint',
|
| 796 |
+
value=False)
|
| 797 |
+
|
| 798 |
+
controlnet_softness = gr.Slider(label='Softness of ControlNet', minimum=0.0, maximum=1.0,
|
| 799 |
+
step=0.001, value=0.25,
|
| 800 |
+
info='Similar to the Control Mode in A1111 (use 0.0 to disable). ')
|
| 801 |
+
|
| 802 |
+
with gr.Tab(label='Canny'):
|
| 803 |
+
canny_low_threshold = gr.Slider(label='Canny Low Threshold', minimum=1, maximum=255,
|
| 804 |
+
step=1, value=64)
|
| 805 |
+
canny_high_threshold = gr.Slider(label='Canny High Threshold', minimum=1, maximum=255,
|
| 806 |
+
step=1, value=128)
|
| 807 |
+
|
| 808 |
+
with gr.Tab(label='Inpaint'):
|
| 809 |
+
debugging_inpaint_preprocessor = gr.Checkbox(label='Debug Inpaint Preprocessing', value=False)
|
| 810 |
+
debugging_enhance_masks_checkbox = gr.Checkbox(label='Debug Enhance Masks', value=False,
|
| 811 |
+
info='Show enhance masks in preview and final results')
|
| 812 |
+
debugging_dino = gr.Checkbox(label='Debug GroundingDINO', value=False,
|
| 813 |
+
info='Use GroundingDINO boxes instead of more detailed SAM masks')
|
| 814 |
+
inpaint_disable_initial_latent = gr.Checkbox(label='Disable initial latent in inpaint', value=False)
|
| 815 |
+
inpaint_engine = gr.Dropdown(label='Inpaint Engine',
|
| 816 |
+
value=modules.config.default_inpaint_engine_version,
|
| 817 |
+
choices=flags.inpaint_engine_versions,
|
| 818 |
+
info='Version of Fooocus inpaint model. If set, use performance Quality or Speed (no performance LoRAs) for best results.')
|
| 819 |
+
inpaint_strength = gr.Slider(label='Inpaint Denoising Strength',
|
| 820 |
+
minimum=0.0, maximum=1.0, step=0.001, value=1.0,
|
| 821 |
+
info='Same as the denoising strength in A1111 inpaint. '
|
| 822 |
+
'Only used in inpaint, not used in outpaint. '
|
| 823 |
+
'(Outpaint always use 1.0)')
|
| 824 |
+
inpaint_respective_field = gr.Slider(label='Inpaint Respective Field',
|
| 825 |
+
minimum=0.0, maximum=1.0, step=0.001, value=0.618,
|
| 826 |
+
info='The area to inpaint. '
|
| 827 |
+
'Value 0 is same as "Only Masked" in A1111. '
|
| 828 |
+
'Value 1 is same as "Whole Image" in A1111. '
|
| 829 |
+
'Only used in inpaint, not used in outpaint. '
|
| 830 |
+
'(Outpaint always use 1.0)')
|
| 831 |
+
inpaint_erode_or_dilate = gr.Slider(label='Mask Erode or Dilate',
|
| 832 |
+
minimum=-64, maximum=64, step=1, value=0,
|
| 833 |
+
info='Positive value will make white area in the mask larger, '
|
| 834 |
+
'negative value will make white area smaller. '
|
| 835 |
+
'(default is 0, always processed before any mask invert)')
|
| 836 |
+
dino_erode_or_dilate = gr.Slider(label='GroundingDINO Box Erode or Dilate',
|
| 837 |
+
minimum=-64, maximum=64, step=1, value=0,
|
| 838 |
+
info='Positive value will make white area in the mask larger, '
|
| 839 |
+
'negative value will make white area smaller. '
|
| 840 |
+
'(default is 0, processed before SAM)')
|
| 841 |
+
|
| 842 |
+
inpaint_mask_color = gr.ColorPicker(label='Inpaint brush color', value='#FFFFFF', elem_id='inpaint_brush_color')
|
| 843 |
+
|
| 844 |
+
inpaint_ctrls = [debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine,
|
| 845 |
+
inpaint_strength, inpaint_respective_field,
|
| 846 |
+
inpaint_advanced_masking_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate]
|
| 847 |
+
|
| 848 |
+
inpaint_advanced_masking_checkbox.change(lambda x: [gr.update(visible=x)] * 2,
|
| 849 |
+
inputs=inpaint_advanced_masking_checkbox,
|
| 850 |
+
outputs=[inpaint_mask_image, inpaint_mask_generation_col],
|
| 851 |
+
queue=False, show_progress=False)
|
| 852 |
+
|
| 853 |
+
inpaint_mask_color.change(lambda x: gr.update(brush_color=x), inputs=inpaint_mask_color,
|
| 854 |
+
outputs=inpaint_input_image,
|
| 855 |
+
queue=False, show_progress=False)
|
| 856 |
+
|
| 857 |
+
with gr.Tab(label='FreeU'):
|
| 858 |
+
freeu_enabled = gr.Checkbox(label='Enabled', value=False)
|
| 859 |
+
freeu_b1 = gr.Slider(label='B1', minimum=0, maximum=2, step=0.01, value=1.01)
|
| 860 |
+
freeu_b2 = gr.Slider(label='B2', minimum=0, maximum=2, step=0.01, value=1.02)
|
| 861 |
+
freeu_s1 = gr.Slider(label='S1', minimum=0, maximum=4, step=0.01, value=0.99)
|
| 862 |
+
freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95)
|
| 863 |
+
freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2]
|
| 864 |
+
|
| 865 |
+
def dev_mode_checked(r):
|
| 866 |
+
return gr.update(visible=r)
|
| 867 |
+
|
| 868 |
+
dev_mode.change(dev_mode_checked, inputs=[dev_mode], outputs=[dev_tools],
|
| 869 |
+
queue=False, show_progress=False)
|
| 870 |
+
|
| 871 |
+
def refresh_files_clicked():
|
| 872 |
+
modules.config.update_files()
|
| 873 |
+
results = [gr.update(choices=modules.config.model_filenames)]
|
| 874 |
+
results += [gr.update(choices=['None'] + modules.config.model_filenames)]
|
| 875 |
+
results += [gr.update(choices=[flags.default_vae] + modules.config.vae_filenames)]
|
| 876 |
+
if not args_manager.args.disable_preset_selection:
|
| 877 |
+
results += [gr.update(choices=modules.config.available_presets)]
|
| 878 |
+
for i in range(modules.config.default_max_lora_number):
|
| 879 |
+
results += [gr.update(interactive=True),
|
| 880 |
+
gr.update(choices=['None'] + modules.config.lora_filenames), gr.update()]
|
| 881 |
+
return results
|
| 882 |
+
|
| 883 |
+
refresh_files_output = [base_model, refiner_model, vae_name]
|
| 884 |
+
if not args_manager.args.disable_preset_selection:
|
| 885 |
+
refresh_files_output += [preset_selection]
|
| 886 |
+
refresh_files.click(refresh_files_clicked, [], refresh_files_output + lora_ctrls,
|
| 887 |
+
queue=False, show_progress=False)
|
| 888 |
+
|
| 889 |
+
state_is_generating = gr.State(False)
|
| 890 |
+
|
| 891 |
+
# Ensure Stop button always restores Generate button to active state,
|
| 892 |
+
# even if generation already finished and the generate_clicked chain was lost.
|
| 893 |
+
stop_button.click(lambda: (gr.update(visible=True, interactive=True),
|
| 894 |
+
gr.update(visible=False, interactive=False),
|
| 895 |
+
gr.update(visible=False, interactive=False),
|
| 896 |
+
False),
|
| 897 |
+
outputs=[generate_button, stop_button, skip_button, state_is_generating],
|
| 898 |
+
queue=False, show_progress=False)
|
| 899 |
+
|
| 900 |
+
load_data_outputs = [advanced_checkbox, image_number, prompt, negative_prompt, style_selections,
|
| 901 |
+
performance_selection, overwrite_step, overwrite_switch, aspect_ratios_selection,
|
| 902 |
+
overwrite_width, overwrite_height, guidance_scale, sharpness, adm_scaler_positive,
|
| 903 |
+
adm_scaler_negative, adm_scaler_end, refiner_swap_method, adaptive_cfg, clip_skip,
|
| 904 |
+
base_model, refiner_model, refiner_switch, sampler_name, scheduler_name, vae_name,
|
| 905 |
+
seed_random, image_seed, inpaint_engine, inpaint_engine_state,
|
| 906 |
+
inpaint_mode] + enhance_inpaint_mode_ctrls + [generate_button,
|
| 907 |
+
load_parameter_button] + freeu_ctrls + lora_ctrls
|
| 908 |
+
|
| 909 |
+
if not args_manager.args.disable_preset_selection:
|
| 910 |
+
def preset_selection_change(preset, is_generating, inpaint_mode):
|
| 911 |
+
preset_content = modules.config.try_get_preset_content(preset) if preset != 'initial' else {}
|
| 912 |
+
preset_prepared = modules.meta_parser.parse_meta_from_preset(preset_content)
|
| 913 |
+
|
| 914 |
+
default_model = preset_prepared.get('base_model')
|
| 915 |
+
previous_default_models = preset_prepared.get('previous_default_models', [])
|
| 916 |
+
checkpoint_downloads = preset_prepared.get('checkpoint_downloads', {})
|
| 917 |
+
embeddings_downloads = preset_prepared.get('embeddings_downloads', {})
|
| 918 |
+
lora_downloads = preset_prepared.get('lora_downloads', {})
|
| 919 |
+
vae_downloads = preset_prepared.get('vae_downloads', {})
|
| 920 |
+
|
| 921 |
+
preset_prepared['base_model'], preset_prepared['checkpoint_downloads'] = launch.download_models(
|
| 922 |
+
default_model, previous_default_models, checkpoint_downloads, embeddings_downloads, lora_downloads,
|
| 923 |
+
vae_downloads)
|
| 924 |
+
|
| 925 |
+
if 'prompt' in preset_prepared and preset_prepared.get('prompt') == '':
|
| 926 |
+
del preset_prepared['prompt']
|
| 927 |
+
|
| 928 |
+
return modules.meta_parser.load_parameter_button_click(json.dumps(preset_prepared), is_generating, inpaint_mode)
|
| 929 |
+
|
| 930 |
+
|
| 931 |
+
def inpaint_engine_state_change(inpaint_engine_version, *args):
|
| 932 |
+
if inpaint_engine_version == 'empty':
|
| 933 |
+
inpaint_engine_version = modules.config.default_inpaint_engine_version
|
| 934 |
+
|
| 935 |
+
result = []
|
| 936 |
+
for inpaint_mode in args:
|
| 937 |
+
if inpaint_mode != modules.flags.inpaint_option_detail:
|
| 938 |
+
result.append(gr.update(value=inpaint_engine_version))
|
| 939 |
+
else:
|
| 940 |
+
result.append(gr.update())
|
| 941 |
+
|
| 942 |
+
return result
|
| 943 |
+
|
| 944 |
+
preset_selection.change(preset_selection_change, inputs=[preset_selection, state_is_generating, inpaint_mode], outputs=load_data_outputs, queue=False, show_progress=True) \
|
| 945 |
+
.then(fn=style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False) \
|
| 946 |
+
.then(lambda: None, _js='()=>{refresh_style_localization();}') \
|
| 947 |
+
.then(inpaint_engine_state_change, inputs=[inpaint_engine_state] + enhance_inpaint_mode_ctrls, outputs=enhance_inpaint_engine_ctrls, queue=False, show_progress=False)
|
| 948 |
+
|
| 949 |
+
performance_selection.change(lambda x: [gr.update(interactive=not flags.Performance.has_restricted_features(x))] * 11 +
|
| 950 |
+
[gr.update(visible=not flags.Performance.has_restricted_features(x))] * 1 +
|
| 951 |
+
[gr.update(value=flags.Performance.has_restricted_features(x))] * 1,
|
| 952 |
+
inputs=performance_selection,
|
| 953 |
+
outputs=[
|
| 954 |
+
guidance_scale, sharpness, adm_scaler_end, adm_scaler_positive,
|
| 955 |
+
adm_scaler_negative, refiner_switch, refiner_model, sampler_name,
|
| 956 |
+
scheduler_name, adaptive_cfg, refiner_swap_method, negative_prompt, disable_intermediate_results
|
| 957 |
+
], queue=False, show_progress=False)
|
| 958 |
+
|
| 959 |
+
output_format.input(lambda x: gr.update(output_format=x), inputs=output_format)
|
| 960 |
+
|
| 961 |
+
advanced_checkbox.change(lambda x: gr.update(visible=x), advanced_checkbox, advanced_column,
|
| 962 |
+
queue=False, show_progress=False) \
|
| 963 |
+
.then(fn=lambda: None, _js='refresh_grid_delayed', queue=False, show_progress=False)
|
| 964 |
+
|
| 965 |
+
inpaint_mode.change(inpaint_mode_change, inputs=[inpaint_mode, inpaint_engine_state], outputs=[
|
| 966 |
+
inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts,
|
| 967 |
+
inpaint_disable_initial_latent, inpaint_engine,
|
| 968 |
+
inpaint_strength, inpaint_respective_field
|
| 969 |
+
], show_progress=False, queue=False)
|
| 970 |
+
|
| 971 |
+
# load configured default_inpaint_method
|
| 972 |
+
default_inpaint_ctrls = [inpaint_mode, inpaint_disable_initial_latent, inpaint_engine, inpaint_strength, inpaint_respective_field]
|
| 973 |
+
for mode, disable_initial_latent, engine, strength, respective_field in [default_inpaint_ctrls] + enhance_inpaint_update_ctrls:
|
| 974 |
+
shared.gradio_root.load(inpaint_mode_change, inputs=[mode, inpaint_engine_state], outputs=[
|
| 975 |
+
inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts, disable_initial_latent,
|
| 976 |
+
engine, strength, respective_field
|
| 977 |
+
], show_progress=False, queue=False)
|
| 978 |
+
|
| 979 |
+
generate_mask_button.click(fn=generate_mask,
|
| 980 |
+
inputs=[inpaint_input_image, inpaint_mask_model, inpaint_mask_cloth_category,
|
| 981 |
+
inpaint_mask_dino_prompt_text, inpaint_mask_sam_model,
|
| 982 |
+
inpaint_mask_box_threshold, inpaint_mask_text_threshold,
|
| 983 |
+
inpaint_mask_sam_max_detections, dino_erode_or_dilate, debugging_dino],
|
| 984 |
+
outputs=inpaint_mask_image, show_progress=True, queue=True)
|
| 985 |
+
|
| 986 |
+
ctrls = [currentTask, generate_image_grid]
|
| 987 |
+
ctrls += [
|
| 988 |
+
prompt, negative_prompt, style_selections,
|
| 989 |
+
performance_selection, aspect_ratios_selection, image_number, output_format, image_seed,
|
| 990 |
+
read_wildcards_in_order, sharpness, guidance_scale
|
| 991 |
+
]
|
| 992 |
+
|
| 993 |
+
ctrls += [base_model, refiner_model, refiner_switch] + lora_ctrls
|
| 994 |
+
ctrls += [input_image_checkbox, current_tab]
|
| 995 |
+
ctrls += [uov_method, uov_input_image]
|
| 996 |
+
ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image]
|
| 997 |
+
ctrls += [disable_preview, disable_intermediate_results, disable_seed_increment, black_out_nsfw]
|
| 998 |
+
ctrls += [adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, clip_skip]
|
| 999 |
+
ctrls += [sampler_name, scheduler_name, vae_name]
|
| 1000 |
+
ctrls += [overwrite_step, overwrite_switch, overwrite_width, overwrite_height, overwrite_vary_strength]
|
| 1001 |
+
ctrls += [overwrite_upscale_strength, mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint]
|
| 1002 |
+
ctrls += [debugging_cn_preprocessor, skipping_cn_preprocessor, canny_low_threshold, canny_high_threshold]
|
| 1003 |
+
ctrls += [refiner_swap_method, controlnet_softness]
|
| 1004 |
+
ctrls += freeu_ctrls
|
| 1005 |
+
ctrls += inpaint_ctrls
|
| 1006 |
+
|
| 1007 |
+
if not args_manager.args.disable_image_log:
|
| 1008 |
+
ctrls += [save_final_enhanced_image_only]
|
| 1009 |
+
|
| 1010 |
+
if not args_manager.args.disable_metadata:
|
| 1011 |
+
ctrls += [save_metadata_to_images, metadata_scheme]
|
| 1012 |
+
|
| 1013 |
+
ctrls += ip_ctrls
|
| 1014 |
+
ctrls += [debugging_dino, dino_erode_or_dilate, debugging_enhance_masks_checkbox,
|
| 1015 |
+
enhance_input_image, enhance_checkbox, enhance_uov_method, enhance_uov_processing_order,
|
| 1016 |
+
enhance_uov_prompt_type]
|
| 1017 |
+
ctrls += enhance_ctrls
|
| 1018 |
+
|
| 1019 |
+
def parse_meta(raw_prompt_txt, is_generating):
|
| 1020 |
+
loaded_json = None
|
| 1021 |
+
if is_json(raw_prompt_txt):
|
| 1022 |
+
loaded_json = json.loads(raw_prompt_txt)
|
| 1023 |
+
|
| 1024 |
+
if loaded_json is None:
|
| 1025 |
+
if is_generating:
|
| 1026 |
+
return gr.update(), gr.update(visible=False), gr.update()
|
| 1027 |
+
else:
|
| 1028 |
+
return gr.update(), gr.update(visible=True), gr.update(visible=False)
|
| 1029 |
+
|
| 1030 |
+
if is_generating:
|
| 1031 |
+
return json.dumps(loaded_json), gr.update(visible=False), gr.update(visible=False)
|
| 1032 |
+
return json.dumps(loaded_json), gr.update(visible=True), gr.update(visible=True)
|
| 1033 |
+
|
| 1034 |
+
prompt.input(parse_meta, inputs=[prompt, state_is_generating], outputs=[prompt, generate_button, load_parameter_button], queue=False, show_progress=False)
|
| 1035 |
+
|
| 1036 |
+
load_parameter_button.click(modules.meta_parser.load_parameter_button_click, inputs=[prompt, state_is_generating, inpaint_mode], outputs=load_data_outputs, queue=False, show_progress=False)
|
| 1037 |
+
|
| 1038 |
+
def trigger_metadata_import(file, state_is_generating):
|
| 1039 |
+
parameters, metadata_scheme = modules.meta_parser.read_info_from_image(file)
|
| 1040 |
+
if parameters is None:
|
| 1041 |
+
print('Could not find metadata in the image!')
|
| 1042 |
+
parsed_parameters = {}
|
| 1043 |
+
else:
|
| 1044 |
+
metadata_parser = modules.meta_parser.get_metadata_parser(metadata_scheme)
|
| 1045 |
+
parsed_parameters = metadata_parser.to_json(parameters)
|
| 1046 |
+
|
| 1047 |
+
return modules.meta_parser.load_parameter_button_click(parsed_parameters, state_is_generating, inpaint_mode)
|
| 1048 |
+
|
| 1049 |
+
metadata_import_button.click(trigger_metadata_import, inputs=[metadata_input_image, state_is_generating], outputs=load_data_outputs, queue=False, show_progress=True) \
|
| 1050 |
+
.then(style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False)
|
| 1051 |
+
|
| 1052 |
+
generate_button.click(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), [], True),
|
| 1053 |
+
outputs=[stop_button, skip_button, generate_button, gallery, state_is_generating]) \
|
| 1054 |
+
.then(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed) \
|
| 1055 |
+
.then(fn=get_task, inputs=ctrls, outputs=currentTask) \
|
| 1056 |
+
.then(fn=generate_clicked, inputs=currentTask, outputs=[progress_html, progress_window, progress_gallery, gallery]) \
|
| 1057 |
+
.then(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), gr.update(visible=False, interactive=False), False),
|
| 1058 |
+
outputs=[generate_button, stop_button, skip_button, state_is_generating]) \
|
| 1059 |
+
.then(fn=update_history_link, outputs=history_link) \
|
| 1060 |
+
.then(fn=lambda: None, _js='playNotification').then(fn=lambda: None, _js='refresh_grid_delayed')
|
| 1061 |
+
|
| 1062 |
+
reset_button.click(lambda: [worker.AsyncTask(args=[]), False, gr.update(visible=True, interactive=True)] +
|
| 1063 |
+
[gr.update(visible=False)] * 6 +
|
| 1064 |
+
[gr.update(visible=True, value=[])],
|
| 1065 |
+
outputs=[currentTask, state_is_generating, generate_button,
|
| 1066 |
+
reset_button, stop_button, skip_button,
|
| 1067 |
+
progress_html, progress_window, progress_gallery, gallery],
|
| 1068 |
+
queue=False)
|
| 1069 |
+
|
| 1070 |
+
for notification_file in ['notification.ogg', 'notification.mp3']:
|
| 1071 |
+
if os.path.exists(notification_file):
|
| 1072 |
+
gr.Audio(interactive=False, value=notification_file, elem_id='audio_notification', visible=False)
|
| 1073 |
+
break
|
| 1074 |
+
|
| 1075 |
+
def trigger_describe(modes, img, apply_styles):
|
| 1076 |
+
describe_prompts = []
|
| 1077 |
+
styles = set()
|
| 1078 |
+
|
| 1079 |
+
if flags.describe_type_photo in modes:
|
| 1080 |
+
from extras.interrogate import default_interrogator as default_interrogator_photo
|
| 1081 |
+
describe_prompts.append(default_interrogator_photo(img))
|
| 1082 |
+
styles.update(["Fooocus V2", "Fooocus Enhance", "Fooocus Sharp"])
|
| 1083 |
+
|
| 1084 |
+
if flags.describe_type_anime in modes:
|
| 1085 |
+
from extras.wd14tagger import default_interrogator as default_interrogator_anime
|
| 1086 |
+
describe_prompts.append(default_interrogator_anime(img))
|
| 1087 |
+
styles.update(["Fooocus V2", "Fooocus Masterpiece"])
|
| 1088 |
+
|
| 1089 |
+
if len(styles) == 0 or not apply_styles:
|
| 1090 |
+
styles = gr.update()
|
| 1091 |
+
else:
|
| 1092 |
+
styles = list(styles)
|
| 1093 |
+
|
| 1094 |
+
if len(describe_prompts) == 0:
|
| 1095 |
+
describe_prompt = gr.update()
|
| 1096 |
+
else:
|
| 1097 |
+
describe_prompt = ', '.join(describe_prompts)
|
| 1098 |
+
|
| 1099 |
+
return describe_prompt, styles
|
| 1100 |
+
|
| 1101 |
+
describe_btn.click(trigger_describe, inputs=[describe_methods, describe_input_image, describe_apply_styles],
|
| 1102 |
+
outputs=[prompt, style_selections], show_progress=True, queue=True) \
|
| 1103 |
+
.then(fn=style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False) \
|
| 1104 |
+
.then(lambda: None, _js='()=>{refresh_style_localization();}')
|
| 1105 |
+
|
| 1106 |
+
if args_manager.args.enable_auto_describe_image:
|
| 1107 |
+
def trigger_auto_describe(mode, img, prompt, apply_styles):
|
| 1108 |
+
# keep prompt if not empty
|
| 1109 |
+
if prompt == '':
|
| 1110 |
+
return trigger_describe(mode, img, apply_styles)
|
| 1111 |
+
return gr.update(), gr.update()
|
| 1112 |
+
|
| 1113 |
+
uov_input_image.upload(trigger_auto_describe, inputs=[describe_methods, uov_input_image, prompt, describe_apply_styles],
|
| 1114 |
+
outputs=[prompt, style_selections], show_progress=True, queue=True) \
|
| 1115 |
+
.then(fn=style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False) \
|
| 1116 |
+
.then(lambda: None, _js='()=>{refresh_style_localization();}')
|
| 1117 |
+
|
| 1118 |
+
enhance_input_image.upload(lambda: gr.update(value=True), outputs=enhance_checkbox, queue=False, show_progress=False) \
|
| 1119 |
+
.then(trigger_auto_describe, inputs=[describe_methods, enhance_input_image, prompt, describe_apply_styles],
|
| 1120 |
+
outputs=[prompt, style_selections], show_progress=True, queue=True) \
|
| 1121 |
+
.then(fn=style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False) \
|
| 1122 |
+
.then(lambda: None, _js='()=>{refresh_style_localization();}')
|
| 1123 |
+
|
| 1124 |
+
def dump_default_english_config():
|
| 1125 |
+
from modules.localization import dump_english_config
|
| 1126 |
+
dump_english_config(grh.all_components)
|
| 1127 |
+
|
| 1128 |
+
|
| 1129 |
+
# dump_default_english_config()
|
| 1130 |
+
|
| 1131 |
+
shared.gradio_root.launch(
|
| 1132 |
+
inbrowser=args_manager.args.in_browser,
|
| 1133 |
+
server_name=args_manager.args.listen,
|
| 1134 |
+
server_port=args_manager.args.port,
|
| 1135 |
+
share=args_manager.args.share,
|
| 1136 |
+
auth=check_auth if (args_manager.args.share or args_manager.args.listen) and auth_enabled else None,
|
| 1137 |
+
allowed_paths=[modules.config.path_outputs],
|
| 1138 |
+
blocked_paths=[constants.AUTH_FILENAME]
|
| 1139 |
+
)
|