refactor: extract sdxl aspect ratios to flags, use in describe
as discussed in https://github.com/lllyasviel/Fooocus/pull/2971#discussion_r1608493765 https://github.com/lllyasviel/Fooocus/pull/2971#issuecomment-2123620595
This commit is contained in:
parent
311c445090
commit
751e867b37
|
|
@ -409,13 +409,7 @@ embeddings_downloads = get_config_item_or_set_default(
|
||||||
)
|
)
|
||||||
available_aspect_ratios = get_config_item_or_set_default(
|
available_aspect_ratios = get_config_item_or_set_default(
|
||||||
key='available_aspect_ratios',
|
key='available_aspect_ratios',
|
||||||
default_value=[
|
default_value=modules.flags.sdxl_aspect_ratios,
|
||||||
'704*1408', '704*1344', '768*1344', '768*1280', '832*1216', '832*1152',
|
|
||||||
'896*1152', '896*1088', '960*1088', '960*1024', '1024*1024', '1024*960',
|
|
||||||
'1088*960', '1088*896', '1152*896', '1152*832', '1216*832', '1280*768',
|
|
||||||
'1344*768', '1344*704', '1408*704', '1472*704', '1536*640', '1600*640',
|
|
||||||
'1664*576', '1728*576'
|
|
||||||
],
|
|
||||||
validator=lambda x: isinstance(x, list) and all('*' in v for v in x) and len(x) > 1
|
validator=lambda x: isinstance(x, list) and all('*' in v for v in x) and len(x) > 1
|
||||||
)
|
)
|
||||||
default_aspect_ratio = get_config_item_or_set_default(
|
default_aspect_ratio = get_config_item_or_set_default(
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,13 @@ inpaint_options = [inpaint_option_default, inpaint_option_detail, inpaint_option
|
||||||
desc_type_photo = 'Photograph'
|
desc_type_photo = 'Photograph'
|
||||||
desc_type_anime = 'Art/Anime'
|
desc_type_anime = 'Art/Anime'
|
||||||
|
|
||||||
|
sdxl_aspect_ratios = [
|
||||||
|
'704*1408', '704*1344', '768*1344', '768*1280', '832*1216', '832*1152',
|
||||||
|
'896*1152', '896*1088', '960*1088', '960*1024', '1024*1024', '1024*960',
|
||||||
|
'1088*960', '1088*896', '1152*896', '1152*832', '1216*832', '1280*768',
|
||||||
|
'1344*768', '1344*704', '1408*704', '1472*704', '1536*640', '1600*640',
|
||||||
|
'1664*576', '1728*576'
|
||||||
|
]
|
||||||
|
|
||||||
class MetadataScheme(Enum):
|
class MetadataScheme(Enum):
|
||||||
FOOOCUS = 'fooocus'
|
FOOOCUS = 'fooocus'
|
||||||
|
|
|
||||||
|
|
@ -394,7 +394,7 @@ def get_enabled_loras(loras: list) -> list:
|
||||||
return [[lora[1], lora[2]] for lora in loras if lora[0]]
|
return [[lora[1], lora[2]] for lora in loras if lora[0]]
|
||||||
|
|
||||||
|
|
||||||
def get_image_size_info(image: np.ndarray, available_aspect_ratios: list) -> str:
|
def get_image_size_info(image: np.ndarray, aspect_ratios: list) -> str:
|
||||||
try:
|
try:
|
||||||
image = Image.fromarray(np.uint8(image))
|
image = Image.fromarray(np.uint8(image))
|
||||||
width, height = image.size
|
width, height = image.size
|
||||||
|
|
@ -403,7 +403,7 @@ def get_image_size_info(image: np.ndarray, available_aspect_ratios: list) -> str
|
||||||
lcm_ratio = f'{width // gcd}:{height // gcd}'
|
lcm_ratio = f'{width // gcd}:{height // gcd}'
|
||||||
size_info = f'Image Size: {width} x {height}, Ratio: {ratio}, {lcm_ratio}'
|
size_info = f'Image Size: {width} x {height}, Ratio: {ratio}, {lcm_ratio}'
|
||||||
|
|
||||||
closest_ratio = min(available_aspect_ratios, key=lambda x: abs(ratio - float(x.split('*')[0]) / float(x.split('*')[1])))
|
closest_ratio = min(aspect_ratios, key=lambda x: abs(ratio - float(x.split('*')[0]) / float(x.split('*')[1])))
|
||||||
recommended_width, recommended_height = map(int, closest_ratio.split('*'))
|
recommended_width, recommended_height = map(int, closest_ratio.split('*'))
|
||||||
recommended_ratio = round(recommended_width / recommended_height, 2)
|
recommended_ratio = round(recommended_width / recommended_height, 2)
|
||||||
recommended_gcd = math.gcd(recommended_width, recommended_height)
|
recommended_gcd = math.gcd(recommended_width, recommended_height)
|
||||||
|
|
|
||||||
2
webui.py
2
webui.py
|
|
@ -224,7 +224,7 @@ with shared.gradio_root:
|
||||||
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/1363" target="_blank">\U0001F4D4 Document</a>')
|
gr.HTML('<a href="https://github.com/lllyasviel/Fooocus/discussions/1363" target="_blank">\U0001F4D4 Document</a>')
|
||||||
|
|
||||||
def trigger_show_image_properties(image):
|
def trigger_show_image_properties(image):
|
||||||
value = modules.util.get_image_size_info(image, modules.config.available_aspect_ratios)
|
value = modules.util.get_image_size_info(image, modules.flags.sdxl_aspect_ratios)
|
||||||
return gr.update(value=value, visible=True)
|
return gr.update(value=value, visible=True)
|
||||||
|
|
||||||
desc_input_image.upload(trigger_show_image_properties, inputs=desc_input_image,
|
desc_input_image.upload(trigger_show_image_properties, inputs=desc_input_image,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue