Spaces:
Runtime error
Runtime error
Update webui.py
Browse files
webui.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import random
|
3 |
import os
|
4 |
-
|
5 |
import time
|
6 |
import shared
|
7 |
import modules.config
|
@@ -20,7 +20,7 @@ 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 |
-
|
24 |
|
25 |
def get_task(*args):
|
26 |
args = list(args)
|
@@ -86,7 +86,7 @@ def generate_clicked(task):
|
|
86 |
|
87 |
reload_javascript()
|
88 |
|
89 |
-
title = 'AI
|
90 |
|
91 |
if isinstance(args_manager.args.preset, str):
|
92 |
title += ' ' + args_manager.args.preset
|
@@ -99,157 +99,157 @@ with shared.gradio_root:
|
|
99 |
currentTask = gr.State(worker.AsyncTask(args=[]))
|
100 |
with gr.Row():
|
101 |
with gr.Column(scale=2):
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
with gr.Row(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
113 |
with gr.Tabs():
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
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.Column(scale=17):
|
183 |
-
prompt = gr.Textbox(label="Output", show_label=True, placeholder="", elem_id='positive_prompt',
|
184 |
-
container=True, autofocus=True, elem_classes='type_row', lines=1024, show_copy_button=True)
|
185 |
-
|
186 |
-
default_prompt = modules.config.default_prompt
|
187 |
-
if isinstance(default_prompt, str) and default_prompt != '':
|
188 |
-
shared.gradio_root.load(lambda: default_prompt, outputs=prompt)
|
189 |
-
|
190 |
-
# with gr.Column(scale=3, min_width=0):
|
191 |
-
# generate_button = gr.Button(label="Generate", value="Generate", elem_classes='type_row', elem_id='generate_button', visible=True)
|
192 |
-
# load_parameter_button = gr.Button(label="Load Parameters", value="Load Parameters", elem_classes='type_row', elem_id='load_parameter_button', visible=False)
|
193 |
-
# skip_button = gr.Button(label="Skip", value="Skip", elem_classes='type_row_half', visible=False)
|
194 |
-
# stop_button = gr.Button(label="Stop", value="Stop", elem_classes='type_row_half', elem_id='stop_button', visible=False)
|
195 |
-
|
196 |
-
# def stop_clicked(currentTask):
|
197 |
-
# import ldm_patched.modules.model_management as model_management
|
198 |
-
# currentTask.last_stop = 'stop'
|
199 |
-
# if (currentTask.processing):
|
200 |
-
# model_management.interrupt_current_processing()
|
201 |
-
# return currentTask
|
202 |
-
|
203 |
-
# def skip_clicked(currentTask):
|
204 |
-
# import ldm_patched.modules.model_management as model_management
|
205 |
-
# currentTask.last_stop = 'skip'
|
206 |
-
# if (currentTask.processing):
|
207 |
-
# model_management.interrupt_current_processing()
|
208 |
-
# return currentTask
|
209 |
-
|
210 |
-
# stop_button.click(stop_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False, _js='cancelGenerateForever')
|
211 |
-
# skip_button.click(skip_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False)
|
212 |
-
with gr.Row(elem_classes='advanced_check_row'):
|
213 |
-
# input_image_checkbox = gr.Checkbox(label='Input Image', value=False, container=False, elem_classes='min_check')
|
214 |
-
advanced_checkbox = gr.Checkbox(label='Advanced', value=modules.config.default_advanced_checkbox, container=False, elem_classes='min_check')
|
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 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
|
227 |
-
|
228 |
-
|
229 |
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
|
234 |
-
|
235 |
-
|
236 |
|
237 |
-
|
238 |
|
239 |
-
|
240 |
-
|
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 |
-
|
246 |
-
|
247 |
-
|
248 |
|
249 |
-
current_tab = gr.Textbox(value='
|
250 |
-
|
251 |
-
|
252 |
-
|
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:
|
@@ -374,7 +374,7 @@ with shared.gradio_root:
|
|
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:
|
@@ -435,71 +435,71 @@ with shared.gradio_root:
|
|
435 |
info='Disable automatic seed increment when image number is > 1.',
|
436 |
value=False)
|
437 |
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
|
504 |
with gr.Tab(label='FreeU'):
|
505 |
freeu_enabled = gr.Checkbox(label='Enabled', value=False)
|
@@ -543,38 +543,38 @@ with shared.gradio_root:
|
|
543 |
queue=False, show_progress=False) \
|
544 |
.then(fn=lambda: None, _js='refresh_grid_delayed', queue=False, show_progress=False)
|
545 |
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
|
579 |
ctrls = [currentTask, generate_image_grid]
|
580 |
ctrls += [
|
@@ -583,74 +583,74 @@ with shared.gradio_root:
|
|
583 |
]
|
584 |
|
585 |
ctrls += [base_model, refiner_model, refiner_switch] + lora_ctrls
|
586 |
-
|
587 |
-
|
588 |
-
|
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 |
-
|
594 |
-
|
595 |
-
|
596 |
ctrls += freeu_ctrls
|
597 |
-
|
598 |
|
599 |
-
|
600 |
-
|
601 |
|
602 |
-
|
603 |
|
604 |
-
|
605 |
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
|
617 |
-
|
618 |
|
619 |
-
|
620 |
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
626 |
-
|
627 |
|
628 |
-
|
629 |
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
|
639 |
-
|
640 |
|
641 |
|
642 |
-
|
643 |
-
|
644 |
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
|
655 |
for notification_file in ['notification.ogg', 'notification.mp3']:
|
656 |
if os.path.exists(notification_file):
|
|
|
1 |
import gradio as gr
|
2 |
import random
|
3 |
import os
|
4 |
+
import json
|
5 |
import time
|
6 |
import shared
|
7 |
import modules.config
|
|
|
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)
|
|
|
86 |
|
87 |
reload_javascript()
|
88 |
|
89 |
+
title = 'AI Image'
|
90 |
|
91 |
if isinstance(args_manager.args.preset, str):
|
92 |
title += ' ' + args_manager.args.preset
|
|
|
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(elem_classes='type_row'):
|
113 |
+
with gr.Column(scale=17):
|
114 |
+
prompt = gr.Textbox(show_label=False, placeholder="Type prompt here or paste parameters.", elem_id='positive_prompt',
|
115 |
+
container=False, autofocus=True, elem_classes='type_row', lines=1024, , show_copy_button=True)
|
116 |
+
|
117 |
+
default_prompt = modules.config.default_prompt
|
118 |
+
if isinstance(default_prompt, str) and default_prompt != '':
|
119 |
+
shared.gradio_root.load(lambda: default_prompt, outputs=prompt)
|
120 |
+
|
121 |
+
with gr.Column(scale=3, min_width=0):
|
122 |
+
generate_button = gr.Button(label="Generate", value="Generate", elem_classes='type_row', elem_id='generate_button', visible=True)
|
123 |
+
load_parameter_button = gr.Button(label="Load Parameters", value="Load Parameters", elem_classes='type_row', elem_id='load_parameter_button', visible=False)
|
124 |
+
skip_button = gr.Button(label="Skip", value="Skip", elem_classes='type_row_half', visible=False)
|
125 |
+
stop_button = gr.Button(label="Stop", value="Stop", elem_classes='type_row_half', elem_id='stop_button', visible=False)
|
126 |
+
|
127 |
+
def stop_clicked(currentTask):
|
128 |
+
import ldm_patched.modules.model_management as model_management
|
129 |
+
currentTask.last_stop = 'stop'
|
130 |
+
if (currentTask.processing):
|
131 |
+
model_management.interrupt_current_processing()
|
132 |
+
return currentTask
|
133 |
+
|
134 |
+
def skip_clicked(currentTask):
|
135 |
+
import ldm_patched.modules.model_management as model_management
|
136 |
+
currentTask.last_stop = 'skip'
|
137 |
+
if (currentTask.processing):
|
138 |
+
model_management.interrupt_current_processing()
|
139 |
+
return currentTask
|
140 |
+
|
141 |
+
stop_button.click(stop_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False, _js='cancelGenerateForever')
|
142 |
+
skip_button.click(skip_clicked, inputs=currentTask, outputs=currentTask, queue=False, show_progress=False)
|
143 |
+
with gr.Row(elem_classes='advanced_check_row'):
|
144 |
+
input_image_checkbox = gr.Checkbox(label='Input Image', value=False, container=False, elem_classes='min_check')
|
145 |
+
advanced_checkbox = gr.Checkbox(label='Advanced', value=modules.config.default_advanced_checkbox, container=False, elem_classes='min_check')
|
146 |
+
with gr.Row(visible=False) as image_input_panel:
|
147 |
with gr.Tabs():
|
148 |
+
with gr.TabItem(label='Upscale or Variation') as uov_tab:
|
149 |
+
with gr.Row():
|
150 |
+
with gr.Column():
|
151 |
+
uov_input_image = grh.Image(label='Drag above image to here', source='upload', type='numpy')
|
152 |
+
with gr.Column():
|
153 |
+
uov_method = gr.Radio(label='Upscale or Variation:', choices=flags.uov_list, value=flags.disabled)
|
154 |
+
# gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/390" target="_blank">\U0001F4D4 Document</a>')
|
155 |
+
with gr.TabItem(label='Image Prompt') as ip_tab:
|
156 |
+
with gr.Row():
|
157 |
+
ip_images = []
|
158 |
+
ip_types = []
|
159 |
+
ip_stops = []
|
160 |
+
ip_weights = []
|
161 |
+
ip_ctrls = []
|
162 |
+
ip_ad_cols = []
|
163 |
+
for _ in range(flags.controlnet_image_count):
|
164 |
+
with gr.Column():
|
165 |
+
ip_image = grh.Image(label='Image', source='upload', type='numpy', show_label=False, height=300)
|
166 |
+
ip_images.append(ip_image)
|
167 |
+
ip_ctrls.append(ip_image)
|
168 |
+
with gr.Column(visible=False) as ad_col:
|
169 |
+
with gr.Row():
|
170 |
+
default_end, default_weight = flags.default_parameters[flags.default_ip]
|
171 |
+
|
172 |
+
ip_stop = gr.Slider(label='Stop At', minimum=0.0, maximum=1.0, step=0.001, value=default_end)
|
173 |
+
ip_stops.append(ip_stop)
|
174 |
+
ip_ctrls.append(ip_stop)
|
175 |
+
|
176 |
+
ip_weight = gr.Slider(label='Weight', minimum=0.0, maximum=2.0, step=0.001, value=default_weight)
|
177 |
+
ip_weights.append(ip_weight)
|
178 |
+
ip_ctrls.append(ip_weight)
|
179 |
+
|
180 |
+
ip_type = gr.Radio(label='Type', choices=flags.ip_list, value=flags.default_ip, container=False)
|
181 |
+
ip_types.append(ip_type)
|
182 |
+
ip_ctrls.append(ip_type)
|
183 |
+
|
184 |
+
ip_type.change(lambda x: flags.default_parameters[x], inputs=[ip_type], outputs=[ip_stop, ip_weight], queue=False, show_progress=False)
|
185 |
+
ip_ad_cols.append(ad_col)
|
186 |
+
ip_advanced = gr.Checkbox(label='Advanced', value=False, container=False)
|
187 |
+
# 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>')
|
188 |
+
|
189 |
+
def ip_advance_checked(x):
|
190 |
+
return [gr.update(visible=x)] * len(ip_ad_cols) + \
|
191 |
+
[flags.default_ip] * len(ip_types) + \
|
192 |
+
[flags.default_parameters[flags.default_ip][0]] * len(ip_stops) + \
|
193 |
+
[flags.default_parameters[flags.default_ip][1]] * len(ip_weights)
|
194 |
+
|
195 |
+
ip_advanced.change(ip_advance_checked, inputs=ip_advanced,
|
196 |
+
outputs=ip_ad_cols + ip_types + ip_stops + ip_weights,
|
197 |
+
queue=False, show_progress=False)
|
198 |
+
with gr.TabItem(label='Inpaint or Outpaint') as inpaint_tab:
|
199 |
+
with gr.Row():
|
200 |
+
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')
|
201 |
+
inpaint_mask_image = grh.Image(label='Mask Upload', source='upload', type='numpy', height=500, visible=False)
|
202 |
+
|
203 |
+
with gr.Row():
|
204 |
+
inpaint_additional_prompt = gr.Textbox(placeholder="Describe what you want to inpaint.", elem_id='inpaint_additional_prompt', label='Inpaint Additional Prompt', visible=False)
|
205 |
+
outpaint_selections = gr.CheckboxGroup(choices=['Left', 'Right', 'Top', 'Bottom'], value=[], label='Outpaint Direction')
|
206 |
+
inpaint_mode = gr.Dropdown(choices=modules.flags.inpaint_options, value=modules.flags.inpaint_option_default, label='Method')
|
207 |
+
example_inpaint_prompts = gr.Dataset(samples=modules.config.example_inpaint_prompts, label='Additional Prompt Quick List', components=[inpaint_additional_prompt], visible=False)
|
208 |
+
# gr.HTML('* Powered by Fooocus Inpaint Engine <a href="https://github.com/lllyasviel/Fooocus/discussions/414" target="_blank">\U0001F4D4 Document</a>')
|
209 |
+
example_inpaint_prompts.click(lambda x: x[0], inputs=example_inpaint_prompts, outputs=inpaint_additional_prompt, show_progress=False, queue=False)
|
210 |
with gr.TabItem(label='Describe') as desc_tab:
|
211 |
with gr.Row():
|
212 |
with gr.Column():
|
213 |
desc_input_image = grh.Image(label='Drag any image to here', source='upload', type='numpy')
|
214 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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='uov', 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:
|
|
|
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:
|
|
|
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)
|
|
|
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 += [
|
|
|
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):
|