Skip to content

Commit

Permalink
feat: extend config settings for image input (#3382)
Browse files Browse the repository at this point in the history
* docs: update numbering of basic debug procedure in issue template

* feat: add config default_image_prompt_checkbox

* feat: add config for default_image_prompt_advanced_checkbox

* feat: add config for default_inpaint_advanced_masking_checkbox

* feat: add config for default_invert_mask_checkbox

* feat: add config for default_developer_debug_mode_checkbox

* refactor: regroup checkbox configs

* feat: add config for default_uov_method

* feat: add configs for controlnet

default_controlnet_image_count, ip_images, ip_stop_ats, ip_weights and ip_types

* feat: add config for selected tab, rename desc to describe
  • Loading branch information
mashb1t authored Jul 27, 2024
1 parent e36fa0b commit 3f25b88
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 53 deletions.
4 changes: 2 additions & 2 deletions modules/async_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class AsyncTask:
def __init__(self, args):
from modules.flags import Performance, MetadataScheme, ip_list, controlnet_image_count, disabled
from modules.flags import Performance, MetadataScheme, ip_list, disabled
from modules.util import get_enabled_loras
from modules.config import default_max_lora_number
import args_manager
Expand Down Expand Up @@ -101,7 +101,7 @@ def __init__(self, args):
args.pop()) if not args_manager.args.disable_metadata else MetadataScheme.FOOOCUS

self.cn_tasks = {x: [] for x in ip_list}
for _ in range(controlnet_image_count):
for _ in range(modules.config.default_controlnet_image_count):
cn_img = args.pop()
cn_stop = args.pop()
cn_weight = args.pop()
Expand Down
95 changes: 89 additions & 6 deletions modules/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,12 +403,36 @@ def init_temp_path(path: str | None, default_path: str) -> str:
validator=lambda x: x in Performance.values(),
expected_type=str
)
default_image_prompt_checkbox = get_config_item_or_set_default(
key='default_image_prompt_checkbox',
default_value=False,
validator=lambda x: isinstance(x, bool),
expected_type=bool
)
default_enhance_checkbox = get_config_item_or_set_default(
key='default_enhance_checkbox',
default_value=False,
validator=lambda x: isinstance(x, bool),
expected_type=bool
)
default_advanced_checkbox = get_config_item_or_set_default(
key='default_advanced_checkbox',
default_value=False,
validator=lambda x: isinstance(x, bool),
expected_type=bool
)
default_developer_debug_mode_checkbox = get_config_item_or_set_default(
key='default_developer_debug_mode_checkbox',
default_value=False,
validator=lambda x: isinstance(x, bool),
expected_type=bool
)
default_image_prompt_advanced_checkbox = get_config_item_or_set_default(
key='default_image_prompt_advanced_checkbox',
default_value=False,
validator=lambda x: isinstance(x, bool),
expected_type=bool
)
default_max_image_number = get_config_item_or_set_default(
key='default_max_image_number',
default_value=32,
Expand Down Expand Up @@ -469,6 +493,64 @@ def init_temp_path(path: str | None, default_path: str) -> str:
validator=lambda x: x in modules.flags.inpaint_engine_versions,
expected_type=str
)
default_selected_image_input_tab_id = get_config_item_or_set_default(
key='default_selected_image_input_tab_id',
default_value=modules.flags.default_input_image_tab,
validator=lambda x: x in modules.flags.input_image_tab_ids,
expected_type=str
)
default_uov_method = get_config_item_or_set_default(
key='default_uov_method',
default_value=modules.flags.disabled,
validator=lambda x: x in modules.flags.uov_list,
expected_type=str
)
default_controlnet_image_count = get_config_item_or_set_default(
key='default_controlnet_image_count',
default_value=4,
validator=lambda x: isinstance(x, int) and x > 0,
expected_type=int
)
default_ip_images = {}
default_ip_stop_ats = {}
default_ip_weights = {}
default_ip_types = {}

for image_count in range(default_controlnet_image_count):
default_ip_images[image_count] = get_config_item_or_set_default(
key=f'default_ip_image_{image_count}',
default_value=None,
validator=lambda x: x is None or isinstance(x, str) and os.path.exists(x),
expected_type=str
)
default_ip_types[image_count] = get_config_item_or_set_default(
key=f'default_ip_type_{image_count}',
default_value=modules.flags.default_ip,
validator=lambda x: x in modules.flags.ip_list,
expected_type=str
)

default_end, default_weight = modules.flags.default_parameters[default_ip_types[image_count]]

default_ip_stop_ats[image_count] = get_config_item_or_set_default(
key=f'default_ip_stop_at_{image_count}',
default_value=default_end,
validator=lambda x: isinstance(x, float) and 0 <= x <= 1,
expected_type=float
)
default_ip_weights[image_count] = get_config_item_or_set_default(
key=f'default_ip_weight_{image_count}',
default_value=default_weight,
validator=lambda x: isinstance(x, float) and 0 <= x <= 2,
expected_type=float
)

default_inpaint_advanced_masking_checkbox = get_config_item_or_set_default(
key='default_inpaint_advanced_masking_checkbox',
default_value=False,
validator=lambda x: isinstance(x, bool),
expected_type=bool
)
default_inpaint_method = get_config_item_or_set_default(
key='default_inpaint_method',
default_value=modules.flags.inpaint_option_default,
Expand Down Expand Up @@ -526,12 +608,6 @@ def init_temp_path(path: str | None, default_path: str) -> str:
validator=lambda x: isinstance(x, int) and 1 <= x <= 5,
expected_type=int
)
default_enhance_checkbox = get_config_item_or_set_default(
key='default_enhance_checkbox',
default_value=False,
validator=lambda x: isinstance(x, bool),
expected_type=bool
)
default_enhance_uov_method = get_config_item_or_set_default(
key='default_enhance_uov_method',
default_value=modules.flags.disabled,
Expand Down Expand Up @@ -590,6 +666,13 @@ def init_temp_path(path: str | None, default_path: str) -> str:
example_inpaint_prompts = [[x] for x in example_inpaint_prompts]
example_enhance_detection_prompts = [[x] for x in example_enhance_detection_prompts]

default_invert_mask_checkbox = get_config_item_or_set_default(
key='default_invert_mask_checkbox',
default_value=False,
validator=lambda x: isinstance(x, bool),
expected_type=bool
)

default_inpaint_mask_model = get_config_item_or_set_default(
key='default_inpaint_mask_model',
default_value='isnet-general-use',
Expand Down
9 changes: 5 additions & 4 deletions modules/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@

refiner_swap_method = 'joint'

default_input_image_tab = 'uov_tab'
input_image_tab_ids = ['uov_tab', 'ip_tab', 'inpaint_tab', 'describe_tab', 'enhance_tab', 'metadata_tab']

cn_ip = "ImagePrompt"
cn_ip_face = "FaceSwap"
cn_canny = "PyraCanny"
Expand All @@ -91,8 +94,8 @@
inpaint_option_modify = 'Modify Content (add objects, change background, etc.)'
inpaint_options = [inpaint_option_default, inpaint_option_detail, inpaint_option_modify]

desc_type_photo = 'Photograph'
desc_type_anime = 'Art/Anime'
describe_type_photo = 'Photograph'
describe_type_anime = 'Art/Anime'

sdxl_aspect_ratios = [
'704*1408', '704*1344', '768*1344', '768*1280', '832*1216', '832*1152',
Expand All @@ -113,8 +116,6 @@ class MetadataScheme(Enum):
(f'{MetadataScheme.A1111.value} (plain text)', MetadataScheme.A1111.value),
]

controlnet_image_count = 4


class OutputFormat(Enum):
PNG = 'png'
Expand Down
Loading

0 comments on commit 3f25b88

Please sign in to comment.