From 2f08cb4360238ea65ef1e9772ba25dcfd29378ac Mon Sep 17 00:00:00 2001
From: Manuel Schmid <9307310+mashb1t@users.noreply.github.com>
Date: Sat, 3 Aug 2024 14:46:31 +0200
Subject: [PATCH 1/4] 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
---
language/en.json | 1 +
modules/config.py | 13 +++++++++++
modules/flags.py | 1 +
webui.py | 57 ++++++++++++++++++++++++++++++++++-------------
4 files changed, 56 insertions(+), 16 deletions(-)
diff --git a/language/en.json b/language/en.json
index a0935643a..108adad66 100644
--- a/language/en.json
+++ b/language/en.json
@@ -17,6 +17,7 @@
"Content Type": "Content Type",
"Photograph": "Photograph",
"Art/Anime": "Art/Anime",
+ "Appy Styles": "Appy Styles",
"Describe this Image into Prompt": "Describe this Image into Prompt",
"Image Size and Recommended Size": "Image Size and Recommended Size",
"Upscale or Variation:": "Upscale or Variation:",
diff --git a/modules/config.py b/modules/config.py
index 0f2038b61..001cf949d 100644
--- a/modules/config.py
+++ b/modules/config.py
@@ -702,6 +702,19 @@ def init_temp_path(path: str | None, default_path: str) -> 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))]
# mapping config to meta parameter
diff --git a/modules/flags.py b/modules/flags.py
index 4357cdf11..05c29a232 100644
--- a/modules/flags.py
+++ b/modules/flags.py
@@ -96,6 +96,7 @@
describe_type_photo = 'Photograph'
describe_type_anime = 'Art/Anime'
+describe_types = [describe_type_photo, describe_type_anime]
sdxl_aspect_ratios = [
'704*1408', '704*1344', '768*1344', '768*1280', '832*1216', '832*1152',
diff --git a/webui.py b/webui.py
index 1a4fb6cf7..0ca6bdec7 100644
--- a/webui.py
+++ b/webui.py
@@ -337,10 +337,11 @@ def generate_mask(image, mask_model, cloth_category, dino_prompt_text, sam_model
with gr.Column():
describe_input_image = grh.Image(label='Image', source='upload', type='numpy', show_label=False)
with gr.Column():
- describe_method = gr.Radio(
+ describe_methods = gr.CheckboxGroup(
label='Content Type',
- choices=[flags.describe_type_photo, flags.describe_type_anime],
- value=flags.describe_type_photo)
+ choices=flags.describe_types,
+ 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_image_size = gr.Textbox(label='Image Size and Recommended Size', elem_id='describe_image_size', visible=False)
gr.HTML('\U0001F4D4 Documentation')
@@ -1060,30 +1061,54 @@ def trigger_metadata_import(file, state_is_generating):
gr.Audio(interactive=False, value=notification_file, elem_id='audio_notification', visible=False)
break
- def trigger_describe(mode, img):
- if mode == flags.describe_type_photo:
+ def trigger_describe(modes, img, apply_styles):
+ describe_prompts = []
+ styles = set()
+
+ if flags.describe_type_photo in modes:
from extras.interrogate import default_interrogator as default_interrogator_photo
- return default_interrogator_photo(img), ["Fooocus V2", "Fooocus Enhance", "Fooocus Sharp"]
- if mode == flags.describe_type_anime:
+ 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
- return default_interrogator_anime(img), ["Fooocus V2", "Fooocus Masterpiece"]
- return mode, ["Fooocus V2"]
+ describe_prompts.append(default_interrogator_anime(img))
+ styles.update(["Fooocus V2", "Fooocus Masterpiece"])
- describe_btn.click(trigger_describe, inputs=[describe_method, describe_input_image],
- outputs=[prompt, style_selections], show_progress=True, queue=True)
+ 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:
- def trigger_auto_describe(mode, img, prompt):
+ def trigger_auto_describe(mode, img, prompt, apply_styles):
# keep prompt if not empty
if prompt == '':
- return trigger_describe(mode, img)
+ return trigger_describe(mode, img, apply_styles)
return gr.update(), gr.update()
- uov_input_image.upload(trigger_auto_describe, inputs=[describe_method, uov_input_image, prompt],
- outputs=[prompt, style_selections], show_progress=True, queue=True)
+ 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) \
+ .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) \
- .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():
from modules.localization import dump_english_config
From c4d5b160bec6fcfe4a2f5459dc286a045f3b75b7 Mon Sep 17 00:00:00 2001
From: Manuel Schmid
Date: Sat, 3 Aug 2024 15:07:14 +0200
Subject: [PATCH 2/4] release: bump version to 2.5.3, update changelog
---
fooocus_version.py | 2 +-
update_log.md | 7 +++++++
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/fooocus_version.py b/fooocus_version.py
index ca4825b5b..326513ef1 100644
--- a/fooocus_version.py
+++ b/fooocus_version.py
@@ -1 +1 @@
-version = '2.5.2'
+version = '2.5.3'
diff --git a/update_log.md b/update_log.md
index e3a5e273d..fc4b27aad 100644
--- a/update_log.md
+++ b/update_log.md
@@ -1,3 +1,10 @@
+# [2.5.3](https://github.com/lllyasviel/Fooocus/releases/tag/v2.5.3)
+
+* Fix prompt bug when only negative styles are selected
+* Add various config settings for image input, see list in [PR](https://github.com/lllyasviel/Fooocus/pull/3382)
+* Only load weights from non-safetensors files, preventing harmful code injection
+* Add checkbox for applying/resetting styles when describing images, also allowing multiple describe content types
+
# [2.5.2](https://github.com/lllyasviel/Fooocus/releases/tag/v2.5.2)
* Fix not adding positive prompt when styles didn't have a {prompt} placeholder in the positive prompt
From 39d07bf0f3945b4144a5df25f1a1be2d8b1b3f56 Mon Sep 17 00:00:00 2001
From: Manuel Schmid
Date: Sat, 3 Aug 2024 15:10:27 +0200
Subject: [PATCH 3/4] release: fix changelog
---
update_log.md | 2 --
1 file changed, 2 deletions(-)
diff --git a/update_log.md b/update_log.md
index fc4b27aad..8dbd653e6 100644
--- a/update_log.md
+++ b/update_log.md
@@ -1,7 +1,5 @@
# [2.5.3](https://github.com/lllyasviel/Fooocus/releases/tag/v2.5.3)
-* Fix prompt bug when only negative styles are selected
-* Add various config settings for image input, see list in [PR](https://github.com/lllyasviel/Fooocus/pull/3382)
* Only load weights from non-safetensors files, preventing harmful code injection
* Add checkbox for applying/resetting styles when describing images, also allowing multiple describe content types
From ef0acca9f9bbbc9e1e5481b3c31bde88f3748597 Mon Sep 17 00:00:00 2001
From: Manuel Schmid
Date: Sat, 3 Aug 2024 15:16:18 +0200
Subject: [PATCH 4/4] fix: change wrong label for in describe apply styles
checkbox
---
language/en.json | 2 +-
webui.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/language/en.json b/language/en.json
index 108adad66..7e8b27daa 100644
--- a/language/en.json
+++ b/language/en.json
@@ -17,7 +17,7 @@
"Content Type": "Content Type",
"Photograph": "Photograph",
"Art/Anime": "Art/Anime",
- "Appy Styles": "Appy Styles",
+ "Apply Styles": "Apply Styles",
"Describe this Image into Prompt": "Describe this Image into Prompt",
"Image Size and Recommended Size": "Image Size and Recommended Size",
"Upscale or Variation:": "Upscale or Variation:",
diff --git a/webui.py b/webui.py
index 0ca6bdec7..b8159d855 100644
--- a/webui.py
+++ b/webui.py
@@ -341,7 +341,7 @@ def generate_mask(image, mask_model, cloth_category, dino_prompt_text, sam_model
label='Content Type',
choices=flags.describe_types,
value=modules.config.default_describe_content_type)
- describe_apply_styles = gr.Checkbox(label='Appy Styles', value=modules.config.default_describe_apply_prompts_checkbox)
+ describe_apply_styles = gr.Checkbox(label='Apply Styles', value=modules.config.default_describe_apply_prompts_checkbox)
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)
gr.HTML('\U0001F4D4 Documentation')