Adityadn commited on
Commit
874bec4
·
verified ·
1 Parent(s): af67cb4

Delete aiDescUI.py

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