feat: add checkbox and config to disable updating selected styles when describing an image (#3430)
* feat: add checkbox and config to disable updating selected styles when describing an image * i18n: add translation for checkbox label * feat: change describe content type from Radio to CheckboxGroup, add config * fix: cast set to list when styles contains elements * feat: sort styles after describe
This commit is contained in:
parent
da3d4d006f
commit
2f08cb4360
|
|
@ -17,6 +17,7 @@
|
||||||
"Content Type": "Content Type",
|
"Content Type": "Content Type",
|
||||||
"Photograph": "Photograph",
|
"Photograph": "Photograph",
|
||||||
"Art/Anime": "Art/Anime",
|
"Art/Anime": "Art/Anime",
|
||||||
|
"Appy Styles": "Appy Styles",
|
||||||
"Describe this Image into Prompt": "Describe this Image into Prompt",
|
"Describe this Image into Prompt": "Describe this Image into Prompt",
|
||||||
"Image Size and Recommended Size": "Image Size and Recommended Size",
|
"Image Size and Recommended Size": "Image Size and Recommended Size",
|
||||||
"Upscale or Variation:": "Upscale or Variation:",
|
"Upscale or Variation:": "Upscale or Variation:",
|
||||||
|
|
|
||||||
|
|
@ -702,6 +702,19 @@ default_inpaint_mask_sam_model = get_config_item_or_set_default(
|
||||||
expected_type=str
|
expected_type=str
|
||||||
)
|
)
|
||||||
|
|
||||||
|
default_describe_apply_prompts_checkbox = get_config_item_or_set_default(
|
||||||
|
key='default_describe_apply_prompts_checkbox',
|
||||||
|
default_value=True,
|
||||||
|
validator=lambda x: isinstance(x, bool),
|
||||||
|
expected_type=bool
|
||||||
|
)
|
||||||
|
default_describe_content_type = get_config_item_or_set_default(
|
||||||
|
key='default_describe_content_type',
|
||||||
|
default_value=[modules.flags.describe_type_photo],
|
||||||
|
validator=lambda x: all(k in modules.flags.describe_types for k in x),
|
||||||
|
expected_type=list
|
||||||
|
)
|
||||||
|
|
||||||
config_dict["default_loras"] = default_loras = default_loras[:default_max_lora_number] + [[True, 'None', 1.0] for _ in range(default_max_lora_number - len(default_loras))]
|
config_dict["default_loras"] = default_loras = default_loras[:default_max_lora_number] + [[True, 'None', 1.0] for _ in range(default_max_lora_number - len(default_loras))]
|
||||||
|
|
||||||
# mapping config to meta parameter
|
# mapping config to meta parameter
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,7 @@ inpaint_options = [inpaint_option_default, inpaint_option_detail, inpaint_option
|
||||||
|
|
||||||
describe_type_photo = 'Photograph'
|
describe_type_photo = 'Photograph'
|
||||||
describe_type_anime = 'Art/Anime'
|
describe_type_anime = 'Art/Anime'
|
||||||
|
describe_types = [describe_type_photo, describe_type_anime]
|
||||||
|
|
||||||
sdxl_aspect_ratios = [
|
sdxl_aspect_ratios = [
|
||||||
'704*1408', '704*1344', '768*1344', '768*1280', '832*1216', '832*1152',
|
'704*1408', '704*1344', '768*1344', '768*1280', '832*1216', '832*1152',
|
||||||
|
|
|
||||||
61
webui.py
61
webui.py
|
|
@ -337,10 +337,11 @@ with shared.gradio_root:
|
||||||
with gr.Column():
|
with gr.Column():
|
||||||
describe_input_image = grh.Image(label='Image', source='upload', type='numpy', show_label=False)
|
describe_input_image = grh.Image(label='Image', source='upload', type='numpy', show_label=False)
|
||||||
with gr.Column():
|
with gr.Column():
|
||||||
describe_method = gr.Radio(
|
describe_methods = gr.CheckboxGroup(
|
||||||
label='Content Type',
|
label='Content Type',
|
||||||
choices=[flags.describe_type_photo, flags.describe_type_anime],
|
choices=flags.describe_types,
|
||||||
value=flags.describe_type_photo)
|
value=modules.config.default_describe_content_type)
|
||||||
|
describe_apply_styles = gr.Checkbox(label='Appy Styles', value=modules.config.default_describe_apply_prompts_checkbox)
|
||||||
describe_btn = gr.Button(value='Describe this Image into Prompt')
|
describe_btn = gr.Button(value='Describe this Image into Prompt')
|
||||||
describe_image_size = gr.Textbox(label='Image Size and Recommended Size', elem_id='describe_image_size', visible=False)
|
describe_image_size = gr.Textbox(label='Image Size and Recommended Size', elem_id='describe_image_size', visible=False)
|
||||||
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/1363" target="_blank">\U0001F4D4 Documentation</a>')
|
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/1363" target="_blank">\U0001F4D4 Documentation</a>')
|
||||||
|
|
@ -1060,30 +1061,54 @@ with shared.gradio_root:
|
||||||
gr.Audio(interactive=False, value=notification_file, elem_id='audio_notification', visible=False)
|
gr.Audio(interactive=False, value=notification_file, elem_id='audio_notification', visible=False)
|
||||||
break
|
break
|
||||||
|
|
||||||
def trigger_describe(mode, img):
|
def trigger_describe(modes, img, apply_styles):
|
||||||
if mode == flags.describe_type_photo:
|
describe_prompts = []
|
||||||
from extras.interrogate import default_interrogator as default_interrogator_photo
|
styles = set()
|
||||||
return default_interrogator_photo(img), ["Fooocus V2", "Fooocus Enhance", "Fooocus Sharp"]
|
|
||||||
if mode == flags.describe_type_anime:
|
|
||||||
from extras.wd14tagger import default_interrogator as default_interrogator_anime
|
|
||||||
return default_interrogator_anime(img), ["Fooocus V2", "Fooocus Masterpiece"]
|
|
||||||
return mode, ["Fooocus V2"]
|
|
||||||
|
|
||||||
describe_btn.click(trigger_describe, inputs=[describe_method, describe_input_image],
|
if flags.describe_type_photo in modes:
|
||||||
outputs=[prompt, style_selections], show_progress=True, queue=True)
|
from extras.interrogate import default_interrogator as default_interrogator_photo
|
||||||
|
describe_prompts.append(default_interrogator_photo(img))
|
||||||
|
styles.update(["Fooocus V2", "Fooocus Enhance", "Fooocus Sharp"])
|
||||||
|
|
||||||
|
if flags.describe_type_anime in modes:
|
||||||
|
from extras.wd14tagger import default_interrogator as default_interrogator_anime
|
||||||
|
describe_prompts.append(default_interrogator_anime(img))
|
||||||
|
styles.update(["Fooocus V2", "Fooocus Masterpiece"])
|
||||||
|
|
||||||
|
if len(styles) == 0 or not apply_styles:
|
||||||
|
styles = gr.update()
|
||||||
|
else:
|
||||||
|
styles = list(styles)
|
||||||
|
|
||||||
|
if len(describe_prompts) == 0:
|
||||||
|
describe_prompt = gr.update()
|
||||||
|
else:
|
||||||
|
describe_prompt = ', '.join(describe_prompts)
|
||||||
|
|
||||||
|
return describe_prompt, styles
|
||||||
|
|
||||||
|
describe_btn.click(trigger_describe, inputs=[describe_methods, describe_input_image, describe_apply_styles],
|
||||||
|
outputs=[prompt, style_selections], show_progress=True, queue=True) \
|
||||||
|
.then(fn=style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False) \
|
||||||
|
.then(lambda: None, _js='()=>{refresh_style_localization();}')
|
||||||
|
|
||||||
if args_manager.args.enable_auto_describe_image:
|
if args_manager.args.enable_auto_describe_image:
|
||||||
def trigger_auto_describe(mode, img, prompt):
|
def trigger_auto_describe(mode, img, prompt, apply_styles):
|
||||||
# keep prompt if not empty
|
# keep prompt if not empty
|
||||||
if prompt == '':
|
if prompt == '':
|
||||||
return trigger_describe(mode, img)
|
return trigger_describe(mode, img, apply_styles)
|
||||||
return gr.update(), gr.update()
|
return gr.update(), gr.update()
|
||||||
|
|
||||||
uov_input_image.upload(trigger_auto_describe, inputs=[describe_method, uov_input_image, prompt],
|
uov_input_image.upload(trigger_auto_describe, inputs=[describe_methods, uov_input_image, prompt, describe_apply_styles],
|
||||||
outputs=[prompt, style_selections], show_progress=True, queue=True)
|
outputs=[prompt, style_selections], show_progress=True, queue=True) \
|
||||||
|
.then(fn=style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False) \
|
||||||
|
.then(lambda: None, _js='()=>{refresh_style_localization();}')
|
||||||
|
|
||||||
enhance_input_image.upload(lambda: gr.update(value=True), outputs=enhance_checkbox, queue=False, show_progress=False) \
|
enhance_input_image.upload(lambda: gr.update(value=True), outputs=enhance_checkbox, queue=False, show_progress=False) \
|
||||||
.then(trigger_auto_describe, inputs=[describe_method, enhance_input_image, prompt], outputs=[prompt, style_selections], show_progress=True, queue=True)
|
.then(trigger_auto_describe, inputs=[describe_methods, enhance_input_image, prompt, describe_apply_styles],
|
||||||
|
outputs=[prompt, style_selections], show_progress=True, queue=True) \
|
||||||
|
.then(fn=style_sorter.sort_styles, inputs=style_selections, outputs=style_selections, queue=False, show_progress=False) \
|
||||||
|
.then(lambda: None, _js='()=>{refresh_style_localization();}')
|
||||||
|
|
||||||
def dump_default_english_config():
|
def dump_default_english_config():
|
||||||
from modules.localization import dump_english_config
|
from modules.localization import dump_english_config
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue