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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.advanced_parameters as advanced_parameters
|
| 15 |
+
import modules.style_sorter as style_sorter
|
| 16 |
+
import modules.meta_parser
|
| 17 |
+
import args_manager
|
| 18 |
+
import copy
|
| 19 |
+
|
| 20 |
+
from modules.sdxl_styles import legal_style_names
|
| 21 |
+
from modules.private_logger import get_current_html_path
|
| 22 |
+
from modules.ui_gradio_extensions import reload_javascript
|
| 23 |
+
from modules.auth import auth_enabled, check_auth
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def generate_clicked(*args):
|
| 27 |
+
import ldm_patched.modules.model_management as model_management
|
| 28 |
+
|
| 29 |
+
with model_management.interrupt_processing_mutex:
|
| 30 |
+
model_management.interrupt_processing = False
|
| 31 |
+
|
| 32 |
+
# outputs=[progress_html, progress_window, progress_gallery, gallery]
|
| 33 |
+
|
| 34 |
+
execution_start_time = time.perf_counter()
|
| 35 |
+
task = worker.AsyncTask(args=list(args))
|
| 36 |
+
finished = False
|
| 37 |
+
|
| 38 |
+
yield gr.update(visible=True, value=modules.html.make_progress_html(1, 'Waiting for task to start ...')), \
|
| 39 |
+
gr.update(visible=True, value=None), \
|
| 40 |
+
gr.update(visible=False, value=None), \
|
| 41 |
+
gr.update(visible=False)
|
| 42 |
+
|
| 43 |
+
worker.async_tasks.append(task)
|
| 44 |
+
|
| 45 |
+
while not finished:
|
| 46 |
+
time.sleep(0.01)
|
| 47 |
+
if len(task.yields) > 0:
|
| 48 |
+
flag, product = task.yields.pop(0)
|
| 49 |
+
if flag == 'preview':
|
| 50 |
+
|
| 51 |
+
# help bad internet connection by skipping duplicated preview
|
| 52 |
+
if len(task.yields) > 0: # if we have the next item
|
| 53 |
+
if task.yields[0][0] == 'preview': # if the next item is also a preview
|
| 54 |
+
# print('Skipped one preview for better internet connection.')
|
| 55 |
+
continue
|
| 56 |
+
|
| 57 |
+
percentage, title, image = product
|
| 58 |
+
yield gr.update(visible=True, value=modules.html.make_progress_html(percentage, title)), \
|
| 59 |
+
gr.update(visible=True, value=image) if image is not None else gr.update(), \
|
| 60 |
+
gr.update(), \
|
| 61 |
+
gr.update(visible=False)
|
| 62 |
+
if flag == 'results':
|
| 63 |
+
yield gr.update(visible=True), \
|
| 64 |
+
gr.update(visible=True), \
|
| 65 |
+
gr.update(visible=True, value=product), \
|
| 66 |
+
gr.update(visible=False)
|
| 67 |
+
if flag == 'finish':
|
| 68 |
+
yield gr.update(visible=False), \
|
| 69 |
+
gr.update(visible=False), \
|
| 70 |
+
gr.update(visible=False), \
|
| 71 |
+
gr.update(visible=True, value=product)
|
| 72 |
+
finished = True
|
| 73 |
+
|
| 74 |
+
execution_time = time.perf_counter() - execution_start_time
|
| 75 |
+
print(f'Total time: {execution_time:.2f} seconds')
|
| 76 |
+
return
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
reload_javascript()
|
| 80 |
+
|
| 81 |
+
title = f'Fooocus {fooocus_version.version}'
|
| 82 |
+
|
| 83 |
+
if isinstance(args_manager.args.preset, str):
|
| 84 |
+
title += ' ' + args_manager.args.preset
|
| 85 |
+
|
| 86 |
+
shared.gradio_root = gr.Blocks(
|
| 87 |
+
title=title,
|
| 88 |
+
css=modules.html.css).queue()
|
| 89 |
+
|
| 90 |
+
with shared.gradio_root:
|
| 91 |
+
with gr.Row():
|
| 92 |
+
with gr.Column(scale=2):
|
| 93 |
+
with gr.Row():
|
| 94 |
+
progress_window = grh.Image(label='Preview', show_label=True, visible=False, height=768,
|
| 95 |
+
elem_classes=['main_view'])
|
| 96 |
+
progress_gallery = gr.Gallery(label='Finished Images', show_label=True, object_fit='contain',
|
| 97 |
+
height=768, visible=False, elem_classes=['main_view', 'image_gallery'])
|
| 98 |
+
progress_html = gr.HTML(value=modules.html.make_progress_html(32, 'Progress 32%'), visible=False,
|
| 99 |
+
elem_id='progress-bar', elem_classes='progress-bar')
|
| 100 |
+
gallery = gr.Gallery(label='Gallery', show_label=False, object_fit='contain', visible=True, height=768,
|
| 101 |
+
elem_classes=['resizable_area', 'main_view', 'final_gallery', 'image_gallery'],
|
| 102 |
+
elem_id='final_gallery')
|
| 103 |
+
with gr.Row(elem_classes='type_row'):
|
| 104 |
+
with gr.Column(scale=17):
|
| 105 |
+
prompt = gr.Textbox(show_label=False, placeholder="Type prompt here or paste parameters.", elem_id='positive_prompt',
|
| 106 |
+
container=False, autofocus=True, elem_classes='type_row', lines=1024)
|
| 107 |
+
|
| 108 |
+
default_prompt = modules.config.default_prompt
|
| 109 |
+
if isinstance(default_prompt, str) and default_prompt != '':
|
| 110 |
+
shared.gradio_root.load(lambda: default_prompt, outputs=prompt)
|
| 111 |
+
|
| 112 |
+
with gr.Column(scale=3, min_width=0):
|
| 113 |
+
generate_button = gr.Button(label="Generate", value="Generate", elem_classes='type_row', elem_id='generate_button', visible=True)
|
| 114 |
+
load_parameter_button = gr.Button(label="Load Parameters", value="Load Parameters", elem_classes='type_row', elem_id='load_parameter_button', visible=False)
|
| 115 |
+
skip_button = gr.Button(label="Skip", value="Skip", elem_classes='type_row_half', visible=False)
|
| 116 |
+
stop_button = gr.Button(label="Stop", value="Stop", elem_classes='type_row_half', elem_id='stop_button', visible=False)
|
| 117 |
+
|
| 118 |
+
def stop_clicked():
|
| 119 |
+
import ldm_patched.modules.model_management as model_management
|
| 120 |
+
shared.last_stop = 'stop'
|
| 121 |
+
model_management.interrupt_current_processing()
|
| 122 |
+
return [gr.update(interactive=False)] * 2
|
| 123 |
+
|
| 124 |
+
def skip_clicked():
|
| 125 |
+
import ldm_patched.modules.model_management as model_management
|
| 126 |
+
shared.last_stop = 'skip'
|
| 127 |
+
model_management.interrupt_current_processing()
|
| 128 |
+
return
|
| 129 |
+
|
| 130 |
+
stop_button.click(stop_clicked, outputs=[skip_button, stop_button],
|
| 131 |
+
queue=False, show_progress=False, _js='cancelGenerateForever')
|
| 132 |
+
skip_button.click(skip_clicked, queue=False, show_progress=False)
|
| 133 |
+
with gr.Row(elem_classes='advanced_check_row'):
|
| 134 |
+
input_image_checkbox = gr.Checkbox(label='Input Image', value=False, container=False, elem_classes='min_check')
|
| 135 |
+
advanced_checkbox = gr.Checkbox(label='Advanced', value=modules.config.default_advanced_checkbox, container=False, elem_classes='min_check')
|
| 136 |
+
with gr.Row(visible=False) as image_input_panel:
|
| 137 |
+
with gr.Tabs():
|
| 138 |
+
with gr.TabItem(label='Upscale or Variation') as uov_tab:
|
| 139 |
+
with gr.Row():
|
| 140 |
+
with gr.Column():
|
| 141 |
+
uov_input_image = grh.Image(label='Drag above image to here', source='upload', type='numpy')
|
| 142 |
+
with gr.Column():
|
| 143 |
+
uov_method = gr.Radio(label='Upscale or Variation:', choices=flags.uov_list, value=flags.disabled)
|
| 144 |
+
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/390" target="_blank">\U0001F4D4 Document</a>')
|
| 145 |
+
with gr.TabItem(label='Image Prompt') as ip_tab:
|
| 146 |
+
with gr.Row():
|
| 147 |
+
ip_images = []
|
| 148 |
+
ip_types = []
|
| 149 |
+
ip_stops = []
|
| 150 |
+
ip_weights = []
|
| 151 |
+
ip_ctrls = []
|
| 152 |
+
ip_ad_cols = []
|
| 153 |
+
for _ in range(4):
|
| 154 |
+
with gr.Column():
|
| 155 |
+
ip_image = grh.Image(label='Image', source='upload', type='numpy', show_label=False, height=300)
|
| 156 |
+
ip_images.append(ip_image)
|
| 157 |
+
ip_ctrls.append(ip_image)
|
| 158 |
+
with gr.Column(visible=False) as ad_col:
|
| 159 |
+
with gr.Row():
|
| 160 |
+
default_end, default_weight = flags.default_parameters[flags.default_ip]
|
| 161 |
+
|
| 162 |
+
ip_stop = gr.Slider(label='Stop At', minimum=0.0, maximum=1.0, step=0.001, value=default_end)
|
| 163 |
+
ip_stops.append(ip_stop)
|
| 164 |
+
ip_ctrls.append(ip_stop)
|
| 165 |
+
|
| 166 |
+
ip_weight = gr.Slider(label='Weight', minimum=0.0, maximum=2.0, step=0.001, value=default_weight)
|
| 167 |
+
ip_weights.append(ip_weight)
|
| 168 |
+
ip_ctrls.append(ip_weight)
|
| 169 |
+
|
| 170 |
+
ip_type = gr.Radio(label='Type', choices=flags.ip_list, value=flags.default_ip, container=False)
|
| 171 |
+
ip_types.append(ip_type)
|
| 172 |
+
ip_ctrls.append(ip_type)
|
| 173 |
+
|
| 174 |
+
ip_type.change(lambda x: flags.default_parameters[x], inputs=[ip_type], outputs=[ip_stop, ip_weight], queue=False, show_progress=False)
|
| 175 |
+
ip_ad_cols.append(ad_col)
|
| 176 |
+
ip_advanced = gr.Checkbox(label='Advanced', value=False, container=False)
|
| 177 |
+
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 Document</a>')
|
| 178 |
+
|
| 179 |
+
def ip_advance_checked(x):
|
| 180 |
+
return [gr.update(visible=x)] * len(ip_ad_cols) + \
|
| 181 |
+
[flags.default_ip] * len(ip_types) + \
|
| 182 |
+
[flags.default_parameters[flags.default_ip][0]] * len(ip_stops) + \
|
| 183 |
+
[flags.default_parameters[flags.default_ip][1]] * len(ip_weights)
|
| 184 |
+
|
| 185 |
+
ip_advanced.change(ip_advance_checked, inputs=ip_advanced,
|
| 186 |
+
outputs=ip_ad_cols + ip_types + ip_stops + ip_weights,
|
| 187 |
+
queue=False, show_progress=False)
|
| 188 |
+
with gr.TabItem(label='Inpaint or Outpaint') as inpaint_tab:
|
| 189 |
+
with gr.Row():
|
| 190 |
+
inpaint_input_image = grh.Image(label='Drag inpaint or outpaint image to here', source='upload', type='numpy', tool='sketch', height=500, brush_color="#FFFFFF", elem_id='inpaint_canvas')
|
| 191 |
+
inpaint_mask_image = grh.Image(label='Mask Upload', source='upload', type='numpy', height=500, visible=False)
|
| 192 |
+
|
| 193 |
+
with gr.Row():
|
| 194 |
+
inpaint_additional_prompt = gr.Textbox(placeholder="Describe what you want to inpaint.", elem_id='inpaint_additional_prompt', label='Inpaint Additional Prompt', visible=False)
|
| 195 |
+
outpaint_selections = gr.CheckboxGroup(choices=['Left', 'Right', 'Top', 'Bottom'], value=[], label='Outpaint Direction')
|
| 196 |
+
inpaint_mode = gr.Dropdown(choices=modules.flags.inpaint_options, value=modules.flags.inpaint_option_default, label='Method')
|
| 197 |
+
example_inpaint_prompts = gr.Dataset(samples=modules.config.example_inpaint_prompts, label='Additional Prompt Quick List', components=[inpaint_additional_prompt], visible=False)
|
| 198 |
+
gr.HTML('* Powered by Fooocus Inpaint Engine <a href="https://github.com/lllyasviel/Fooocus/discussions/414" target="_blank">\U0001F4D4 Document</a>')
|
| 199 |
+
example_inpaint_prompts.click(lambda x: x[0], inputs=example_inpaint_prompts, outputs=inpaint_additional_prompt, show_progress=False, queue=False)
|
| 200 |
+
with gr.TabItem(label='Describe') as desc_tab:
|
| 201 |
+
with gr.Row():
|
| 202 |
+
with gr.Column():
|
| 203 |
+
desc_input_image = grh.Image(label='Drag any image to here', source='upload', type='numpy')
|
| 204 |
+
with gr.Column():
|
| 205 |
+
desc_method = gr.Radio(
|
| 206 |
+
label='Content Type',
|
| 207 |
+
choices=[flags.desc_type_photo, flags.desc_type_anime],
|
| 208 |
+
value=flags.desc_type_photo)
|
| 209 |
+
desc_btn = gr.Button(value='Describe this Image into Prompt')
|
| 210 |
+
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/1363" target="_blank">\U0001F4D4 Document</a>')
|
| 211 |
+
switch_js = "(x) => {if(x){viewer_to_bottom(100);viewer_to_bottom(500);}else{viewer_to_top();} return x;}"
|
| 212 |
+
down_js = "() => {viewer_to_bottom();}"
|
| 213 |
+
|
| 214 |
+
input_image_checkbox.change(lambda x: gr.update(visible=x), inputs=input_image_checkbox,
|
| 215 |
+
outputs=image_input_panel, queue=False, show_progress=False, _js=switch_js)
|
| 216 |
+
ip_advanced.change(lambda: None, queue=False, show_progress=False, _js=down_js)
|
| 217 |
+
|
| 218 |
+
current_tab = gr.Textbox(value='uov', visible=False)
|
| 219 |
+
uov_tab.select(lambda: 'uov', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
|
| 220 |
+
inpaint_tab.select(lambda: 'inpaint', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
|
| 221 |
+
ip_tab.select(lambda: 'ip', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
|
| 222 |
+
desc_tab.select(lambda: 'desc', outputs=current_tab, queue=False, _js=down_js, show_progress=False)
|
| 223 |
+
|
| 224 |
+
with gr.Column(scale=1, visible=modules.config.default_advanced_checkbox) as advanced_column:
|
| 225 |
+
with gr.Tab(label='Setting'):
|
| 226 |
+
performance_selection = gr.Radio(label='Performance',
|
| 227 |
+
choices=modules.flags.performance_selections,
|
| 228 |
+
value=modules.config.default_performance)
|
| 229 |
+
aspect_ratios_selection = gr.Radio(label='Aspect Ratios', choices=modules.config.available_aspect_ratios,
|
| 230 |
+
value=modules.config.default_aspect_ratio, info='width × height',
|
| 231 |
+
elem_classes='aspect_ratios')
|
| 232 |
+
image_number = gr.Slider(label='Image Number', minimum=1, maximum=modules.config.default_max_image_number, step=1, value=modules.config.default_image_number)
|
| 233 |
+
negative_prompt = gr.Textbox(label='Negative Prompt', show_label=True, placeholder="Type prompt here.",
|
| 234 |
+
info='Describing what you do not want to see.', lines=2,
|
| 235 |
+
elem_id='negative_prompt',
|
| 236 |
+
value=modules.config.default_prompt_negative)
|
| 237 |
+
seed_random = gr.Checkbox(label='Random', value=True)
|
| 238 |
+
image_seed = gr.Textbox(label='Seed', value=0, max_lines=1, visible=False) # workaround for https://github.com/gradio-app/gradio/issues/5354
|
| 239 |
+
|
| 240 |
+
def random_checked(r):
|
| 241 |
+
return gr.update(visible=not r)
|
| 242 |
+
|
| 243 |
+
def refresh_seed(r, seed_string):
|
| 244 |
+
if r:
|
| 245 |
+
return random.randint(constants.MIN_SEED, constants.MAX_SEED)
|
| 246 |
+
else:
|
| 247 |
+
try:
|
| 248 |
+
seed_value = int(seed_string)
|
| 249 |
+
if constants.MIN_SEED <= seed_value <= constants.MAX_SEED:
|
| 250 |
+
return seed_value
|
| 251 |
+
except ValueError:
|
| 252 |
+
pass
|
| 253 |
+
return random.randint(constants.MIN_SEED, constants.MAX_SEED)
|
| 254 |
+
|
| 255 |
+
seed_random.change(random_checked, inputs=[seed_random], outputs=[image_seed],
|
| 256 |
+
queue=False, show_progress=False)
|
| 257 |
+
|
| 258 |
+
def update_history_link():
|
| 259 |
+
if args_manager.args.disable_image_log:
|
| 260 |
+
return gr.update(value='')
|
| 261 |
+
|
| 262 |
+
return gr.update(value=f'<a href="file={get_current_html_path()}" target="_blank">\U0001F4DA History Log</a>')
|
| 263 |
+
|
| 264 |
+
history_link = gr.HTML()
|
| 265 |
+
shared.gradio_root.load(update_history_link, outputs=history_link, queue=False, show_progress=False)
|
| 266 |
+
|
| 267 |
+
with gr.Tab(label='Style'):
|
| 268 |
+
style_sorter.try_load_sorted_styles(
|
| 269 |
+
style_names=legal_style_names,
|
| 270 |
+
default_selected=modules.config.default_styles)
|
| 271 |
+
|
| 272 |
+
style_search_bar = gr.Textbox(show_label=False, container=False,
|
| 273 |
+
placeholder="\U0001F50E Type here to search styles ...",
|
| 274 |
+
value="",
|
| 275 |
+
label='Search Styles')
|
| 276 |
+
style_selections = gr.CheckboxGroup(show_label=False, container=False,
|
| 277 |
+
choices=copy.deepcopy(style_sorter.all_styles),
|
| 278 |
+
value=copy.deepcopy(modules.config.default_styles),
|
| 279 |
+
label='Selected Styles',
|
| 280 |
+
elem_classes=['style_selections'])
|
| 281 |
+
gradio_receiver_style_selections = gr.Textbox(elem_id='gradio_receiver_style_selections', visible=False)
|
| 282 |
+
|
| 283 |
+
shared.gradio_root.load(lambda: gr.update(choices=copy.deepcopy(style_sorter.all_styles)),
|
| 284 |
+
outputs=style_selections)
|
| 285 |
+
|
| 286 |
+
style_search_bar.change(style_sorter.search_styles,
|
| 287 |
+
inputs=[style_selections, style_search_bar],
|
| 288 |
+
outputs=style_selections,
|
| 289 |
+
queue=False,
|
| 290 |
+
show_progress=False).then(
|
| 291 |
+
lambda: None, _js='()=>{refresh_style_localization();}')
|
| 292 |
+
|
| 293 |
+
gradio_receiver_style_selections.input(style_sorter.sort_styles,
|
| 294 |
+
inputs=style_selections,
|
| 295 |
+
outputs=style_selections,
|
| 296 |
+
queue=False,
|
| 297 |
+
show_progress=False).then(
|
| 298 |
+
lambda: None, _js='()=>{refresh_style_localization();}')
|
| 299 |
+
|
| 300 |
+
with gr.Tab(label='Model'):
|
| 301 |
+
with gr.Group():
|
| 302 |
+
with gr.Row():
|
| 303 |
+
base_model = gr.Dropdown(label='Base Model (SDXL only)', choices=modules.config.model_filenames, value=modules.config.default_base_model_name, show_label=True)
|
| 304 |
+
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)
|
| 305 |
+
|
| 306 |
+
refiner_switch = gr.Slider(label='Refiner Switch At', minimum=0.1, maximum=1.0, step=0.0001,
|
| 307 |
+
info='Use 0.4 for SD1.5 realistic models; '
|
| 308 |
+
'or 0.667 for SD1.5 anime models; '
|
| 309 |
+
'or 0.8 for XL-refiners; '
|
| 310 |
+
'or any value for switching two SDXL models.',
|
| 311 |
+
value=modules.config.default_refiner_switch,
|
| 312 |
+
visible=modules.config.default_refiner_model_name != 'None')
|
| 313 |
+
|
| 314 |
+
refiner_model.change(lambda x: gr.update(visible=x != 'None'),
|
| 315 |
+
inputs=refiner_model, outputs=refiner_switch, show_progress=False, queue=False)
|
| 316 |
+
|
| 317 |
+
with gr.Group():
|
| 318 |
+
lora_ctrls = []
|
| 319 |
+
|
| 320 |
+
for i, (n, v) in enumerate(modules.config.default_loras):
|
| 321 |
+
with gr.Row():
|
| 322 |
+
lora_model = gr.Dropdown(label=f'LoRA {i + 1}',
|
| 323 |
+
choices=['None'] + modules.config.lora_filenames, value=n)
|
| 324 |
+
lora_weight = gr.Slider(label='Weight', minimum=-2, maximum=2, step=0.01, value=v,
|
| 325 |
+
elem_classes='lora_weight')
|
| 326 |
+
lora_ctrls += [lora_model, lora_weight]
|
| 327 |
+
|
| 328 |
+
with gr.Row():
|
| 329 |
+
model_refresh = gr.Button(label='Refresh', value='\U0001f504 Refresh All Files', variant='secondary', elem_classes='refresh_button')
|
| 330 |
+
with gr.Tab(label='Advanced'):
|
| 331 |
+
guidance_scale = gr.Slider(label='Guidance Scale', minimum=1.0, maximum=30.0, step=0.01,
|
| 332 |
+
value=modules.config.default_cfg_scale,
|
| 333 |
+
info='Higher value means style is cleaner, vivider, and more artistic.')
|
| 334 |
+
sharpness = gr.Slider(label='Image Sharpness', minimum=0.0, maximum=30.0, step=0.001,
|
| 335 |
+
value=modules.config.default_sample_sharpness,
|
| 336 |
+
info='Higher value means image and texture are sharper.')
|
| 337 |
+
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/117" target="_blank">\U0001F4D4 Document</a>')
|
| 338 |
+
dev_mode = gr.Checkbox(label='Developer Debug Mode', value=False, container=False)
|
| 339 |
+
|
| 340 |
+
with gr.Column(visible=False) as dev_tools:
|
| 341 |
+
with gr.Tab(label='Debug Tools'):
|
| 342 |
+
adm_scaler_positive = gr.Slider(label='Positive ADM Guidance Scaler', minimum=0.1, maximum=3.0,
|
| 343 |
+
step=0.001, value=1.5, info='The scaler multiplied to positive ADM (use 1.0 to disable). ')
|
| 344 |
+
adm_scaler_negative = gr.Slider(label='Negative ADM Guidance Scaler', minimum=0.1, maximum=3.0,
|
| 345 |
+
step=0.001, value=0.8, info='The scaler multiplied to negative ADM (use 1.0 to disable). ')
|
| 346 |
+
adm_scaler_end = gr.Slider(label='ADM Guidance End At Step', minimum=0.0, maximum=1.0,
|
| 347 |
+
step=0.001, value=0.3,
|
| 348 |
+
info='When to end the guidance from positive/negative ADM. ')
|
| 349 |
+
|
| 350 |
+
refiner_swap_method = gr.Dropdown(label='Refiner swap method', value='joint',
|
| 351 |
+
choices=['joint', 'separate', 'vae'])
|
| 352 |
+
|
| 353 |
+
adaptive_cfg = gr.Slider(label='CFG Mimicking from TSNR', minimum=1.0, maximum=30.0, step=0.01,
|
| 354 |
+
value=modules.config.default_cfg_tsnr,
|
| 355 |
+
info='Enabling Fooocus\'s implementation of CFG mimicking for TSNR '
|
| 356 |
+
'(effective when real CFG > mimicked CFG).')
|
| 357 |
+
sampler_name = gr.Dropdown(label='Sampler', choices=flags.sampler_list,
|
| 358 |
+
value=modules.config.default_sampler)
|
| 359 |
+
scheduler_name = gr.Dropdown(label='Scheduler', choices=flags.scheduler_list,
|
| 360 |
+
value=modules.config.default_scheduler)
|
| 361 |
+
|
| 362 |
+
generate_image_grid = gr.Checkbox(label='Generate Image Grid for Each Batch',
|
| 363 |
+
info='(Experimental) This may cause performance problems on some computers and certain internet conditions.',
|
| 364 |
+
value=False)
|
| 365 |
+
|
| 366 |
+
overwrite_step = gr.Slider(label='Forced Overwrite of Sampling Step',
|
| 367 |
+
minimum=-1, maximum=200, step=1,
|
| 368 |
+
value=modules.config.default_overwrite_step,
|
| 369 |
+
info='Set as -1 to disable. For developer debugging.')
|
| 370 |
+
overwrite_switch = gr.Slider(label='Forced Overwrite of Refiner Switch Step',
|
| 371 |
+
minimum=-1, maximum=200, step=1,
|
| 372 |
+
value=modules.config.default_overwrite_switch,
|
| 373 |
+
info='Set as -1 to disable. For developer debugging.')
|
| 374 |
+
overwrite_width = gr.Slider(label='Forced Overwrite of Generating Width',
|
| 375 |
+
minimum=-1, maximum=2048, step=1, value=-1,
|
| 376 |
+
info='Set as -1 to disable. For developer debugging. '
|
| 377 |
+
'Results will be worse for non-standard numbers that SDXL is not trained on.')
|
| 378 |
+
overwrite_height = gr.Slider(label='Forced Overwrite of Generating Height',
|
| 379 |
+
minimum=-1, maximum=2048, step=1, value=-1,
|
| 380 |
+
info='Set as -1 to disable. For developer debugging. '
|
| 381 |
+
'Results will be worse for non-standard numbers that SDXL is not trained on.')
|
| 382 |
+
overwrite_vary_strength = gr.Slider(label='Forced Overwrite of Denoising Strength of "Vary"',
|
| 383 |
+
minimum=-1, maximum=1.0, step=0.001, value=-1,
|
| 384 |
+
info='Set as negative number to disable. For developer debugging.')
|
| 385 |
+
overwrite_upscale_strength = gr.Slider(label='Forced Overwrite of Denoising Strength of "Upscale"',
|
| 386 |
+
minimum=-1, maximum=1.0, step=0.001, value=-1,
|
| 387 |
+
info='Set as negative number to disable. For developer debugging.')
|
| 388 |
+
disable_preview = gr.Checkbox(label='Disable Preview', value=False,
|
| 389 |
+
info='Disable preview during generation.')
|
| 390 |
+
|
| 391 |
+
with gr.Tab(label='Control'):
|
| 392 |
+
debugging_cn_preprocessor = gr.Checkbox(label='Debug Preprocessors', value=False,
|
| 393 |
+
info='See the results from preprocessors.')
|
| 394 |
+
skipping_cn_preprocessor = gr.Checkbox(label='Skip Preprocessors', value=False,
|
| 395 |
+
info='Do not preprocess images. (Inputs are already canny/depth/cropped-face/etc.)')
|
| 396 |
+
|
| 397 |
+
mixing_image_prompt_and_vary_upscale = gr.Checkbox(label='Mixing Image Prompt and Vary/Upscale',
|
| 398 |
+
value=False)
|
| 399 |
+
mixing_image_prompt_and_inpaint = gr.Checkbox(label='Mixing Image Prompt and Inpaint',
|
| 400 |
+
value=False)
|
| 401 |
+
|
| 402 |
+
controlnet_softness = gr.Slider(label='Softness of ControlNet', minimum=0.0, maximum=1.0,
|
| 403 |
+
step=0.001, value=0.25,
|
| 404 |
+
info='Similar to the Control Mode in A1111 (use 0.0 to disable). ')
|
| 405 |
+
|
| 406 |
+
with gr.Tab(label='Canny'):
|
| 407 |
+
canny_low_threshold = gr.Slider(label='Canny Low Threshold', minimum=1, maximum=255,
|
| 408 |
+
step=1, value=64)
|
| 409 |
+
canny_high_threshold = gr.Slider(label='Canny High Threshold', minimum=1, maximum=255,
|
| 410 |
+
step=1, value=128)
|
| 411 |
+
|
| 412 |
+
with gr.Tab(label='Inpaint'):
|
| 413 |
+
debugging_inpaint_preprocessor = gr.Checkbox(label='Debug Inpaint Preprocessing', value=False)
|
| 414 |
+
inpaint_disable_initial_latent = gr.Checkbox(label='Disable initial latent in inpaint', value=False)
|
| 415 |
+
inpaint_engine = gr.Dropdown(label='Inpaint Engine',
|
| 416 |
+
value=modules.config.default_inpaint_engine_version,
|
| 417 |
+
choices=flags.inpaint_engine_versions,
|
| 418 |
+
info='Version of Fooocus inpaint model')
|
| 419 |
+
inpaint_strength = gr.Slider(label='Inpaint Denoising Strength',
|
| 420 |
+
minimum=0.0, maximum=1.0, step=0.001, value=1.0,
|
| 421 |
+
info='Same as the denoising strength in A1111 inpaint. '
|
| 422 |
+
'Only used in inpaint, not used in outpaint. '
|
| 423 |
+
'(Outpaint always use 1.0)')
|
| 424 |
+
inpaint_respective_field = gr.Slider(label='Inpaint Respective Field',
|
| 425 |
+
minimum=0.0, maximum=1.0, step=0.001, value=0.618,
|
| 426 |
+
info='The area to inpaint. '
|
| 427 |
+
'Value 0 is same as "Only Masked" in A1111. '
|
| 428 |
+
'Value 1 is same as "Whole Image" in A1111. '
|
| 429 |
+
'Only used in inpaint, not used in outpaint. '
|
| 430 |
+
'(Outpaint always use 1.0)')
|
| 431 |
+
inpaint_erode_or_dilate = gr.Slider(label='Mask Erode or Dilate',
|
| 432 |
+
minimum=-64, maximum=64, step=1, value=0,
|
| 433 |
+
info='Positive value will make white area in the mask larger, '
|
| 434 |
+
'negative value will make white area smaller.'
|
| 435 |
+
'(default is 0, always process before any mask invert)')
|
| 436 |
+
inpaint_mask_upload_checkbox = gr.Checkbox(label='Enable Mask Upload', value=False)
|
| 437 |
+
invert_mask_checkbox = gr.Checkbox(label='Invert Mask', value=False)
|
| 438 |
+
|
| 439 |
+
inpaint_ctrls = [debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine,
|
| 440 |
+
inpaint_strength, inpaint_respective_field,
|
| 441 |
+
inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate]
|
| 442 |
+
|
| 443 |
+
inpaint_mask_upload_checkbox.change(lambda x: gr.update(visible=x),
|
| 444 |
+
inputs=inpaint_mask_upload_checkbox,
|
| 445 |
+
outputs=inpaint_mask_image, queue=False, show_progress=False)
|
| 446 |
+
|
| 447 |
+
with gr.Tab(label='FreeU'):
|
| 448 |
+
freeu_enabled = gr.Checkbox(label='Enabled', value=False)
|
| 449 |
+
freeu_b1 = gr.Slider(label='B1', minimum=0, maximum=2, step=0.01, value=1.01)
|
| 450 |
+
freeu_b2 = gr.Slider(label='B2', minimum=0, maximum=2, step=0.01, value=1.02)
|
| 451 |
+
freeu_s1 = gr.Slider(label='S1', minimum=0, maximum=4, step=0.01, value=0.99)
|
| 452 |
+
freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95)
|
| 453 |
+
freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2]
|
| 454 |
+
|
| 455 |
+
adps = [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name,
|
| 456 |
+
scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height,
|
| 457 |
+
overwrite_vary_strength, overwrite_upscale_strength,
|
| 458 |
+
mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint,
|
| 459 |
+
debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness,
|
| 460 |
+
canny_low_threshold, canny_high_threshold, refiner_swap_method]
|
| 461 |
+
adps += freeu_ctrls
|
| 462 |
+
adps += inpaint_ctrls
|
| 463 |
+
|
| 464 |
+
def dev_mode_checked(r):
|
| 465 |
+
return gr.update(visible=r)
|
| 466 |
+
|
| 467 |
+
|
| 468 |
+
dev_mode.change(dev_mode_checked, inputs=[dev_mode], outputs=[dev_tools],
|
| 469 |
+
queue=False, show_progress=False)
|
| 470 |
+
|
| 471 |
+
def model_refresh_clicked():
|
| 472 |
+
modules.config.update_all_model_names()
|
| 473 |
+
results = []
|
| 474 |
+
results += [gr.update(choices=modules.config.model_filenames), gr.update(choices=['None'] + modules.config.model_filenames)]
|
| 475 |
+
for i in range(5):
|
| 476 |
+
results += [gr.update(choices=['None'] + modules.config.lora_filenames), gr.update()]
|
| 477 |
+
return results
|
| 478 |
+
|
| 479 |
+
model_refresh.click(model_refresh_clicked, [], [base_model, refiner_model] + lora_ctrls,
|
| 480 |
+
queue=False, show_progress=False)
|
| 481 |
+
|
| 482 |
+
performance_selection.change(lambda x: [gr.update(interactive=x != 'Extreme Speed')] * 11 +
|
| 483 |
+
[gr.update(visible=x != 'Extreme Speed')] * 1,
|
| 484 |
+
inputs=performance_selection,
|
| 485 |
+
outputs=[
|
| 486 |
+
guidance_scale, sharpness, adm_scaler_end, adm_scaler_positive,
|
| 487 |
+
adm_scaler_negative, refiner_switch, refiner_model, sampler_name,
|
| 488 |
+
scheduler_name, adaptive_cfg, refiner_swap_method, negative_prompt
|
| 489 |
+
], queue=False, show_progress=False)
|
| 490 |
+
|
| 491 |
+
advanced_checkbox.change(lambda x: gr.update(visible=x), advanced_checkbox, advanced_column,
|
| 492 |
+
queue=False, show_progress=False) \
|
| 493 |
+
.then(fn=lambda: None, _js='refresh_grid_delayed', queue=False, show_progress=False)
|
| 494 |
+
|
| 495 |
+
def inpaint_mode_change(mode):
|
| 496 |
+
assert mode in modules.flags.inpaint_options
|
| 497 |
+
|
| 498 |
+
# inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts,
|
| 499 |
+
# inpaint_disable_initial_latent, inpaint_engine,
|
| 500 |
+
# inpaint_strength, inpaint_respective_field
|
| 501 |
+
|
| 502 |
+
if mode == modules.flags.inpaint_option_detail:
|
| 503 |
+
return [
|
| 504 |
+
gr.update(visible=True), gr.update(visible=False, value=[]),
|
| 505 |
+
gr.Dataset.update(visible=True, samples=modules.config.example_inpaint_prompts),
|
| 506 |
+
False, 'None', 0.5, 0.0
|
| 507 |
+
]
|
| 508 |
+
|
| 509 |
+
if mode == modules.flags.inpaint_option_modify:
|
| 510 |
+
return [
|
| 511 |
+
gr.update(visible=True), gr.update(visible=False, value=[]),
|
| 512 |
+
gr.Dataset.update(visible=False, samples=modules.config.example_inpaint_prompts),
|
| 513 |
+
True, modules.config.default_inpaint_engine_version, 1.0, 0.0
|
| 514 |
+
]
|
| 515 |
+
|
| 516 |
+
return [
|
| 517 |
+
gr.update(visible=False, value=''), gr.update(visible=True),
|
| 518 |
+
gr.Dataset.update(visible=False, samples=modules.config.example_inpaint_prompts),
|
| 519 |
+
False, modules.config.default_inpaint_engine_version, 1.0, 0.618
|
| 520 |
+
]
|
| 521 |
+
|
| 522 |
+
inpaint_mode.input(inpaint_mode_change, inputs=inpaint_mode, outputs=[
|
| 523 |
+
inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts,
|
| 524 |
+
inpaint_disable_initial_latent, inpaint_engine,
|
| 525 |
+
inpaint_strength, inpaint_respective_field
|
| 526 |
+
], show_progress=False, queue=False)
|
| 527 |
+
|
| 528 |
+
ctrls = [
|
| 529 |
+
prompt, negative_prompt, style_selections,
|
| 530 |
+
performance_selection, aspect_ratios_selection, image_number, image_seed, sharpness, guidance_scale
|
| 531 |
+
]
|
| 532 |
+
|
| 533 |
+
ctrls += [base_model, refiner_model, refiner_switch] + lora_ctrls
|
| 534 |
+
ctrls += [input_image_checkbox, current_tab]
|
| 535 |
+
ctrls += [uov_method, uov_input_image]
|
| 536 |
+
ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image]
|
| 537 |
+
ctrls += ip_ctrls
|
| 538 |
+
|
| 539 |
+
state_is_generating = gr.State(False)
|
| 540 |
+
|
| 541 |
+
def parse_meta(raw_prompt_txt, is_generating):
|
| 542 |
+
loaded_json = None
|
| 543 |
+
try:
|
| 544 |
+
if '{' in raw_prompt_txt:
|
| 545 |
+
if '}' in raw_prompt_txt:
|
| 546 |
+
if ':' in raw_prompt_txt:
|
| 547 |
+
loaded_json = json.loads(raw_prompt_txt)
|
| 548 |
+
assert isinstance(loaded_json, dict)
|
| 549 |
+
except:
|
| 550 |
+
loaded_json = None
|
| 551 |
+
|
| 552 |
+
if loaded_json is None:
|
| 553 |
+
if is_generating:
|
| 554 |
+
return gr.update(), gr.update(), gr.update()
|
| 555 |
+
else:
|
| 556 |
+
return gr.update(), gr.update(visible=True), gr.update(visible=False)
|
| 557 |
+
|
| 558 |
+
return json.dumps(loaded_json), gr.update(visible=False), gr.update(visible=True)
|
| 559 |
+
|
| 560 |
+
prompt.input(parse_meta, inputs=[prompt, state_is_generating], outputs=[prompt, generate_button, load_parameter_button], queue=False, show_progress=False)
|
| 561 |
+
|
| 562 |
+
load_parameter_button.click(modules.meta_parser.load_parameter_button_click, inputs=[prompt, state_is_generating], outputs=[
|
| 563 |
+
advanced_checkbox,
|
| 564 |
+
image_number,
|
| 565 |
+
prompt,
|
| 566 |
+
negative_prompt,
|
| 567 |
+
style_selections,
|
| 568 |
+
performance_selection,
|
| 569 |
+
aspect_ratios_selection,
|
| 570 |
+
overwrite_width,
|
| 571 |
+
overwrite_height,
|
| 572 |
+
sharpness,
|
| 573 |
+
guidance_scale,
|
| 574 |
+
adm_scaler_positive,
|
| 575 |
+
adm_scaler_negative,
|
| 576 |
+
adm_scaler_end,
|
| 577 |
+
base_model,
|
| 578 |
+
refiner_model,
|
| 579 |
+
refiner_switch,
|
| 580 |
+
sampler_name,
|
| 581 |
+
scheduler_name,
|
| 582 |
+
seed_random,
|
| 583 |
+
image_seed,
|
| 584 |
+
generate_button,
|
| 585 |
+
load_parameter_button
|
| 586 |
+
] + lora_ctrls, queue=False, show_progress=False)
|
| 587 |
+
|
| 588 |
+
generate_button.click(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), [], True),
|
| 589 |
+
outputs=[stop_button, skip_button, generate_button, gallery, state_is_generating]) \
|
| 590 |
+
.then(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed) \
|
| 591 |
+
.then(advanced_parameters.set_all_advanced_parameters, inputs=adps) \
|
| 592 |
+
.then(fn=generate_clicked, inputs=ctrls, outputs=[progress_html, progress_window, progress_gallery, gallery]) \
|
| 593 |
+
.then(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), gr.update(visible=False, interactive=False), False),
|
| 594 |
+
outputs=[generate_button, stop_button, skip_button, state_is_generating]) \
|
| 595 |
+
.then(fn=update_history_link, outputs=history_link) \
|
| 596 |
+
.then(fn=lambda: None, _js='playNotification').then(fn=lambda: None, _js='refresh_grid_delayed')
|
| 597 |
+
|
| 598 |
+
for notification_file in ['notification.ogg', 'notification.mp3']:
|
| 599 |
+
if os.path.exists(notification_file):
|
| 600 |
+
gr.Audio(interactive=False, value=notification_file, elem_id='audio_notification', visible=False)
|
| 601 |
+
break
|
| 602 |
+
|
| 603 |
+
def trigger_describe(mode, img):
|
| 604 |
+
if mode == flags.desc_type_photo:
|
| 605 |
+
from extras.interrogate import default_interrogator as default_interrogator_photo
|
| 606 |
+
return default_interrogator_photo(img), ["Fooocus V2", "Fooocus Enhance", "Fooocus Sharp"]
|
| 607 |
+
if mode == flags.desc_type_anime:
|
| 608 |
+
from extras.wd14tagger import default_interrogator as default_interrogator_anime
|
| 609 |
+
return default_interrogator_anime(img), ["Fooocus V2", "Fooocus Masterpiece"]
|
| 610 |
+
return mode, ["Fooocus V2"]
|
| 611 |
+
|
| 612 |
+
desc_btn.click(trigger_describe, inputs=[desc_method, desc_input_image],
|
| 613 |
+
outputs=[prompt, style_selections], show_progress=True, queue=True)
|
| 614 |
+
|
| 615 |
+
|
| 616 |
+
def dump_default_english_config():
|
| 617 |
+
from modules.localization import dump_english_config
|
| 618 |
+
dump_english_config(grh.all_components)
|
| 619 |
+
|
| 620 |
+
|
| 621 |
+
# dump_default_english_config()
|
| 622 |
+
|
| 623 |
+
shared.gradio_root.launch(
|
| 624 |
+
inbrowser=args_manager.args.in_browser,
|
| 625 |
+
server_name=args_manager.args.listen,
|
| 626 |
+
server_port=args_manager.args.port,
|
| 627 |
+
share=args_manager.args.share,
|
| 628 |
+
auth=check_auth if (args_manager.args.share or args_manager.args.listen) and auth_enabled else None,
|
| 629 |
+
blocked_paths=[constants.AUTH_FILENAME]
|
| 630 |
+
)
|