poor7 commited on
Commit
152cff5
·
verified ·
1 Parent(s): 5b31eb5

Upload webui.py

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