wezyai commited on
Commit
6c64678
1 Parent(s): 5213b2e

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +623 -0
README.md ADDED
@@ -0,0 +1,623 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ if not args_manager.args.disable_image_log:
259
+ gr.HTML(f'<a href="file={get_current_html_path()}" target="_blank">\U0001F4DA History Log</a>')
260
+
261
+ with gr.Tab(label='Style'):
262
+ style_sorter.try_load_sorted_styles(
263
+ style_names=legal_style_names,
264
+ default_selected=modules.config.default_styles)
265
+
266
+ style_search_bar = gr.Textbox(show_label=False, container=False,
267
+ placeholder="\U0001F50E Type here to search styles ...",
268
+ value="",
269
+ label='Search Styles')
270
+ style_selections = gr.CheckboxGroup(show_label=False, container=False,
271
+ choices=copy.deepcopy(style_sorter.all_styles),
272
+ value=copy.deepcopy(modules.config.default_styles),
273
+ label='Selected Styles',
274
+ elem_classes=['style_selections'])
275
+ gradio_receiver_style_selections = gr.Textbox(elem_id='gradio_receiver_style_selections', visible=False)
276
+
277
+ shared.gradio_root.load(lambda: gr.update(choices=copy.deepcopy(style_sorter.all_styles)),
278
+ outputs=style_selections)
279
+
280
+ style_search_bar.change(style_sorter.search_styles,
281
+ inputs=[style_selections, style_search_bar],
282
+ outputs=style_selections,
283
+ queue=False,
284
+ show_progress=False).then(
285
+ lambda: None, _js='()=>{refresh_style_localization();}')
286
+
287
+ gradio_receiver_style_selections.input(style_sorter.sort_styles,
288
+ inputs=style_selections,
289
+ outputs=style_selections,
290
+ queue=False,
291
+ show_progress=False).then(
292
+ lambda: None, _js='()=>{refresh_style_localization();}')
293
+
294
+ with gr.Tab(label='Model'):
295
+ with gr.Group():
296
+ with gr.Row():
297
+ base_model = gr.Dropdown(label='Base Model (SDXL only)', choices=modules.config.model_filenames, value=modules.config.default_base_model_name, show_label=True)
298
+ 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)
299
+
300
+ refiner_switch = gr.Slider(label='Refiner Switch At', minimum=0.1, maximum=1.0, step=0.0001,
301
+ info='Use 0.4 for SD1.5 realistic models; '
302
+ 'or 0.667 for SD1.5 anime models; '
303
+ 'or 0.8 for XL-refiners; '
304
+ 'or any value for switching two SDXL models.',
305
+ value=modules.config.default_refiner_switch,
306
+ visible=modules.config.default_refiner_model_name != 'None')
307
+
308
+ refiner_model.change(lambda x: gr.update(visible=x != 'None'),
309
+ inputs=refiner_model, outputs=refiner_switch, show_progress=False, queue=False)
310
+
311
+ with gr.Group():
312
+ lora_ctrls = []
313
+
314
+ for i, (n, v) in enumerate(modules.config.default_loras):
315
+ with gr.Row():
316
+ lora_model = gr.Dropdown(label=f'LoRA {i + 1}',
317
+ choices=['None'] + modules.config.lora_filenames, value=n)
318
+ lora_weight = gr.Slider(label='Weight', minimum=-2, maximum=2, step=0.01, value=v,
319
+ elem_classes='lora_weight')
320
+ lora_ctrls += [lora_model, lora_weight]
321
+
322
+ with gr.Row():
323
+ model_refresh = gr.Button(label='Refresh', value='\U0001f504 Refresh All Files', variant='secondary', elem_classes='refresh_button')
324
+ with gr.Tab(label='Advanced'):
325
+ guidance_scale = gr.Slider(label='Guidance Scale', minimum=1.0, maximum=30.0, step=0.01,
326
+ value=modules.config.default_cfg_scale,
327
+ info='Higher value means style is cleaner, vivider, and more artistic.')
328
+ sharpness = gr.Slider(label='Image Sharpness', minimum=0.0, maximum=30.0, step=0.001,
329
+ value=modules.config.default_sample_sharpness,
330
+ info='Higher value means image and texture are sharper.')
331
+ gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/117" target="_blank">\U0001F4D4 Document</a>')
332
+ dev_mode = gr.Checkbox(label='Developer Debug Mode', value=False, container=False)
333
+
334
+ with gr.Column(visible=False) as dev_tools:
335
+ with gr.Tab(label='Debug Tools'):
336
+ adm_scaler_positive = gr.Slider(label='Positive ADM Guidance Scaler', minimum=0.1, maximum=3.0,
337
+ step=0.001, value=1.5, info='The scaler multiplied to positive ADM (use 1.0 to disable). ')
338
+ adm_scaler_negative = gr.Slider(label='Negative ADM Guidance Scaler', minimum=0.1, maximum=3.0,
339
+ step=0.001, value=0.8, info='The scaler multiplied to negative ADM (use 1.0 to disable). ')
340
+ adm_scaler_end = gr.Slider(label='ADM Guidance End At Step', minimum=0.0, maximum=1.0,
341
+ step=0.001, value=0.3,
342
+ info='When to end the guidance from positive/negative ADM. ')
343
+
344
+ refiner_swap_method = gr.Dropdown(label='Refiner swap method', value='joint',
345
+ choices=['joint', 'separate', 'vae'])
346
+
347
+ adaptive_cfg = gr.Slider(label='CFG Mimicking from TSNR', minimum=1.0, maximum=30.0, step=0.01,
348
+ value=modules.config.default_cfg_tsnr,
349
+ info='Enabling Fooocus\'s implementation of CFG mimicking for TSNR '
350
+ '(effective when real CFG > mimicked CFG).')
351
+ sampler_name = gr.Dropdown(label='Sampler', choices=flags.sampler_list,
352
+ value=modules.config.default_sampler)
353
+ scheduler_name = gr.Dropdown(label='Scheduler', choices=flags.scheduler_list,
354
+ value=modules.config.default_scheduler)
355
+
356
+ generate_image_grid = gr.Checkbox(label='Generate Image Grid for Each Batch',
357
+ info='(Experimental) This may cause performance problems on some computers and certain internet conditions.',
358
+ value=False)
359
+
360
+ overwrite_step = gr.Slider(label='Forced Overwrite of Sampling Step',
361
+ minimum=-1, maximum=200, step=1,
362
+ value=modules.config.default_overwrite_step,
363
+ info='Set as -1 to disable. For developer debugging.')
364
+ overwrite_switch = gr.Slider(label='Forced Overwrite of Refiner Switch Step',
365
+ minimum=-1, maximum=200, step=1,
366
+ value=modules.config.default_overwrite_switch,
367
+ info='Set as -1 to disable. For developer debugging.')
368
+ overwrite_width = gr.Slider(label='Forced Overwrite of Generating Width',
369
+ minimum=-1, maximum=2048, step=1, value=-1,
370
+ info='Set as -1 to disable. For developer debugging. '
371
+ 'Results will be worse for non-standard numbers that SDXL is not trained on.')
372
+ overwrite_height = gr.Slider(label='Forced Overwrite of Generating Height',
373
+ minimum=-1, maximum=2048, step=1, value=-1,
374
+ info='Set as -1 to disable. For developer debugging. '
375
+ 'Results will be worse for non-standard numbers that SDXL is not trained on.')
376
+ overwrite_vary_strength = gr.Slider(label='Forced Overwrite of Denoising Strength of "Vary"',
377
+ minimum=-1, maximum=1.0, step=0.001, value=-1,
378
+ info='Set as negative number to disable. For developer debugging.')
379
+ overwrite_upscale_strength = gr.Slider(label='Forced Overwrite of Denoising Strength of "Upscale"',
380
+ minimum=-1, maximum=1.0, step=0.001, value=-1,
381
+ info='Set as negative number to disable. For developer debugging.')
382
+ disable_preview = gr.Checkbox(label='Disable Preview', value=False,
383
+ info='Disable preview during generation.')
384
+
385
+ with gr.Tab(label='Control'):
386
+ debugging_cn_preprocessor = gr.Checkbox(label='Debug Preprocessors', value=False,
387
+ info='See the results from preprocessors.')
388
+ skipping_cn_preprocessor = gr.Checkbox(label='Skip Preprocessors', value=False,
389
+ info='Do not preprocess images. (Inputs are already canny/depth/cropped-face/etc.)')
390
+
391
+ mixing_image_prompt_and_vary_upscale = gr.Checkbox(label='Mixing Image Prompt and Vary/Upscale',
392
+ value=False)
393
+ mixing_image_prompt_and_inpaint = gr.Checkbox(label='Mixing Image Prompt and Inpaint',
394
+ value=False)
395
+
396
+ controlnet_softness = gr.Slider(label='Softness of ControlNet', minimum=0.0, maximum=1.0,
397
+ step=0.001, value=0.25,
398
+ info='Similar to the Control Mode in A1111 (use 0.0 to disable). ')
399
+
400
+ with gr.Tab(label='Canny'):
401
+ canny_low_threshold = gr.Slider(label='Canny Low Threshold', minimum=1, maximum=255,
402
+ step=1, value=64)
403
+ canny_high_threshold = gr.Slider(label='Canny High Threshold', minimum=1, maximum=255,
404
+ step=1, value=128)
405
+
406
+ with gr.Tab(label='Inpaint'):
407
+ debugging_inpaint_preprocessor = gr.Checkbox(label='Debug Inpaint Preprocessing', value=False)
408
+ inpaint_disable_initial_latent = gr.Checkbox(label='Disable initial latent in inpaint', value=False)
409
+ inpaint_engine = gr.Dropdown(label='Inpaint Engine',
410
+ value=modules.config.default_inpaint_engine_version,
411
+ choices=flags.inpaint_engine_versions,
412
+ info='Version of Fooocus inpaint model')
413
+ inpaint_strength = gr.Slider(label='Inpaint Denoising Strength',
414
+ minimum=0.0, maximum=1.0, step=0.001, value=1.0,
415
+ info='Same as the denoising strength in A1111 inpaint. '
416
+ 'Only used in inpaint, not used in outpaint. '
417
+ '(Outpaint always use 1.0)')
418
+ inpaint_respective_field = gr.Slider(label='Inpaint Respective Field',
419
+ minimum=0.0, maximum=1.0, step=0.001, value=0.618,
420
+ info='The area to inpaint. '
421
+ 'Value 0 is same as "Only Masked" in A1111. '
422
+ 'Value 1 is same as "Whole Image" in A1111. '
423
+ 'Only used in inpaint, not used in outpaint. '
424
+ '(Outpaint always use 1.0)')
425
+ inpaint_erode_or_dilate = gr.Slider(label='Mask Erode or Dilate',
426
+ minimum=-64, maximum=64, step=1, value=0,
427
+ info='Positive value will make white area in the mask larger, '
428
+ 'negative value will make white area smaller.'
429
+ '(default is 0, always process before any mask invert)')
430
+ inpaint_mask_upload_checkbox = gr.Checkbox(label='Enable Mask Upload', value=False)
431
+ invert_mask_checkbox = gr.Checkbox(label='Invert Mask', value=False)
432
+
433
+ inpaint_ctrls = [debugging_inpaint_preprocessor, inpaint_disable_initial_latent, inpaint_engine,
434
+ inpaint_strength, inpaint_respective_field,
435
+ inpaint_mask_upload_checkbox, invert_mask_checkbox, inpaint_erode_or_dilate]
436
+
437
+ inpaint_mask_upload_checkbox.change(lambda x: gr.update(visible=x),
438
+ inputs=inpaint_mask_upload_checkbox,
439
+ outputs=inpaint_mask_image, queue=False, show_progress=False)
440
+
441
+ with gr.Tab(label='FreeU'):
442
+ freeu_enabled = gr.Checkbox(label='Enabled', value=False)
443
+ freeu_b1 = gr.Slider(label='B1', minimum=0, maximum=2, step=0.01, value=1.01)
444
+ freeu_b2 = gr.Slider(label='B2', minimum=0, maximum=2, step=0.01, value=1.02)
445
+ freeu_s1 = gr.Slider(label='S1', minimum=0, maximum=4, step=0.01, value=0.99)
446
+ freeu_s2 = gr.Slider(label='S2', minimum=0, maximum=4, step=0.01, value=0.95)
447
+ freeu_ctrls = [freeu_enabled, freeu_b1, freeu_b2, freeu_s1, freeu_s2]
448
+
449
+ adps = [disable_preview, adm_scaler_positive, adm_scaler_negative, adm_scaler_end, adaptive_cfg, sampler_name,
450
+ scheduler_name, generate_image_grid, overwrite_step, overwrite_switch, overwrite_width, overwrite_height,
451
+ overwrite_vary_strength, overwrite_upscale_strength,
452
+ mixing_image_prompt_and_vary_upscale, mixing_image_prompt_and_inpaint,
453
+ debugging_cn_preprocessor, skipping_cn_preprocessor, controlnet_softness,
454
+ canny_low_threshold, canny_high_threshold, refiner_swap_method]
455
+ adps += freeu_ctrls
456
+ adps += inpaint_ctrls
457
+
458
+ def dev_mode_checked(r):
459
+ return gr.update(visible=r)
460
+
461
+
462
+ dev_mode.change(dev_mode_checked, inputs=[dev_mode], outputs=[dev_tools],
463
+ queue=False, show_progress=False)
464
+
465
+ def model_refresh_clicked():
466
+ modules.config.update_all_model_names()
467
+ results = []
468
+ results += [gr.update(choices=modules.config.model_filenames), gr.update(choices=['None'] + modules.config.model_filenames)]
469
+ for i in range(5):
470
+ results += [gr.update(choices=['None'] + modules.config.lora_filenames), gr.update()]
471
+ return results
472
+
473
+ model_refresh.click(model_refresh_clicked, [], [base_model, refiner_model] + lora_ctrls,
474
+ queue=False, show_progress=False)
475
+
476
+ performance_selection.change(lambda x: [gr.update(interactive=x != 'Extreme Speed')] * 11 +
477
+ [gr.update(visible=x != 'Extreme Speed')] * 1,
478
+ inputs=performance_selection,
479
+ outputs=[
480
+ guidance_scale, sharpness, adm_scaler_end, adm_scaler_positive,
481
+ adm_scaler_negative, refiner_switch, refiner_model, sampler_name,
482
+ scheduler_name, adaptive_cfg, refiner_swap_method, negative_prompt
483
+ ], queue=False, show_progress=False)
484
+
485
+ advanced_checkbox.change(lambda x: gr.update(visible=x), advanced_checkbox, advanced_column,
486
+ queue=False, show_progress=False) \
487
+ .then(fn=lambda: None, _js='refresh_grid_delayed', queue=False, show_progress=False)
488
+
489
+ def inpaint_mode_change(mode):
490
+ assert mode in modules.flags.inpaint_options
491
+
492
+ # inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts,
493
+ # inpaint_disable_initial_latent, inpaint_engine,
494
+ # inpaint_strength, inpaint_respective_field
495
+
496
+ if mode == modules.flags.inpaint_option_detail:
497
+ return [
498
+ gr.update(visible=True), gr.update(visible=False, value=[]),
499
+ gr.Dataset.update(visible=True, samples=modules.config.example_inpaint_prompts),
500
+ False, 'None', 0.5, 0.0
501
+ ]
502
+
503
+ if mode == modules.flags.inpaint_option_modify:
504
+ return [
505
+ gr.update(visible=True), gr.update(visible=False, value=[]),
506
+ gr.Dataset.update(visible=False, samples=modules.config.example_inpaint_prompts),
507
+ True, modules.config.default_inpaint_engine_version, 1.0, 0.0
508
+ ]
509
+
510
+ return [
511
+ gr.update(visible=False, value=''), gr.update(visible=True),
512
+ gr.Dataset.update(visible=False, samples=modules.config.example_inpaint_prompts),
513
+ False, modules.config.default_inpaint_engine_version, 1.0, 0.618
514
+ ]
515
+
516
+ inpaint_mode.input(inpaint_mode_change, inputs=inpaint_mode, outputs=[
517
+ inpaint_additional_prompt, outpaint_selections, example_inpaint_prompts,
518
+ inpaint_disable_initial_latent, inpaint_engine,
519
+ inpaint_strength, inpaint_respective_field
520
+ ], show_progress=False, queue=False)
521
+
522
+ ctrls = [
523
+ prompt, negative_prompt, style_selections,
524
+ performance_selection, aspect_ratios_selection, image_number, image_seed, sharpness, guidance_scale
525
+ ]
526
+
527
+ ctrls += [base_model, refiner_model, refiner_switch] + lora_ctrls
528
+ ctrls += [input_image_checkbox, current_tab]
529
+ ctrls += [uov_method, uov_input_image]
530
+ ctrls += [outpaint_selections, inpaint_input_image, inpaint_additional_prompt, inpaint_mask_image]
531
+ ctrls += ip_ctrls
532
+
533
+ state_is_generating = gr.State(False)
534
+
535
+ def parse_meta(raw_prompt_txt, is_generating):
536
+ loaded_json = None
537
+ try:
538
+ if '{' in raw_prompt_txt:
539
+ if '}' in raw_prompt_txt:
540
+ if ':' in raw_prompt_txt:
541
+ loaded_json = json.loads(raw_prompt_txt)
542
+ assert isinstance(loaded_json, dict)
543
+ except:
544
+ loaded_json = None
545
+
546
+ if loaded_json is None:
547
+ if is_generating:
548
+ return gr.update(), gr.update(), gr.update()
549
+ else:
550
+ return gr.update(), gr.update(visible=True), gr.update(visible=False)
551
+
552
+ return json.dumps(loaded_json), gr.update(visible=False), gr.update(visible=True)
553
+
554
+ prompt.input(parse_meta, inputs=[prompt, state_is_generating], outputs=[prompt, generate_button, load_parameter_button], queue=False, show_progress=False)
555
+
556
+ load_parameter_button.click(modules.meta_parser.load_parameter_button_click, inputs=[prompt, state_is_generating], outputs=[
557
+ advanced_checkbox,
558
+ image_number,
559
+ prompt,
560
+ negative_prompt,
561
+ style_selections,
562
+ performance_selection,
563
+ aspect_ratios_selection,
564
+ overwrite_width,
565
+ overwrite_height,
566
+ sharpness,
567
+ guidance_scale,
568
+ adm_scaler_positive,
569
+ adm_scaler_negative,
570
+ adm_scaler_end,
571
+ base_model,
572
+ refiner_model,
573
+ refiner_switch,
574
+ sampler_name,
575
+ scheduler_name,
576
+ seed_random,
577
+ image_seed,
578
+ generate_button,
579
+ load_parameter_button
580
+ ] + lora_ctrls, queue=False, show_progress=False)
581
+
582
+ generate_button.click(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), [], True),
583
+ outputs=[stop_button, skip_button, generate_button, gallery, state_is_generating]) \
584
+ .then(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed) \
585
+ .then(advanced_parameters.set_all_advanced_parameters, inputs=adps) \
586
+ .then(fn=generate_clicked, inputs=ctrls, outputs=[progress_html, progress_window, progress_gallery, gallery]) \
587
+ .then(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), gr.update(visible=False, interactive=False), False),
588
+ outputs=[generate_button, stop_button, skip_button, state_is_generating]) \
589
+ .then(fn=lambda: None, _js='playNotification').then(fn=lambda: None, _js='refresh_grid_delayed')
590
+
591
+ for notification_file in ['notification.ogg', 'notification.mp3']:
592
+ if os.path.exists(notification_file):
593
+ gr.Audio(interactive=False, value=notification_file, elem_id='audio_notification', visible=False)
594
+ break
595
+
596
+ def trigger_describe(mode, img):
597
+ if mode == flags.desc_type_photo:
598
+ from extras.interrogate import default_interrogator as default_interrogator_photo
599
+ return default_interrogator_photo(img), ["Fooocus V2", "Fooocus Enhance", "Fooocus Sharp"]
600
+ if mode == flags.desc_type_anime:
601
+ from extras.wd14tagger import default_interrogator as default_interrogator_anime
602
+ return default_interrogator_anime(img), ["Fooocus V2", "Fooocus Masterpiece"]
603
+ return mode, ["Fooocus V2"]
604
+
605
+ desc_btn.click(trigger_describe, inputs=[desc_method, desc_input_image],
606
+ outputs=[prompt, style_selections], show_progress=True, queue=True)
607
+
608
+
609
+ def dump_default_english_config():
610
+ from modules.localization import dump_english_config
611
+ dump_english_config(grh.all_components)
612
+
613
+
614
+ # dump_default_english_config()
615
+
616
+ shared.gradio_root.launch(
617
+ inbrowser=args_manager.args.in_browser,
618
+ server_name=args_manager.args.listen,
619
+ server_port=args_manager.args.port,
620
+ share=args_manager.args.share,
621
+ auth=check_auth if args_manager.args.share and auth_enabled else None,
622
+ blocked_paths=[constants.AUTH_FILENAME]
623
+ )