mirror of
https://github.com/thomasasfk/sd-webui-aspect-ratio-helper.git
synced 2026-01-26 19:19:58 +00:00
Run pre-commit on entire project
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1 +1 @@
|
||||
.idea
|
||||
.idea
|
||||
|
||||
@@ -13,7 +13,6 @@ repos:
|
||||
- id: flake8
|
||||
additional_dependencies:
|
||||
- flake8-bugbear
|
||||
- flake8-import-order
|
||||
- flake8-quotes
|
||||
- flake8-comprehensions
|
||||
- repo: https://github.com/asottile/reorder_python_imports
|
||||
@@ -23,4 +22,4 @@ repos:
|
||||
- repo: https://github.com/asottile/add-trailing-comma
|
||||
rev: v2.4.0
|
||||
hooks:
|
||||
- id: add-trailing-comma
|
||||
- id: add-trailing-comma
|
||||
@@ -2,54 +2,56 @@ import contextlib
|
||||
from functools import partial
|
||||
|
||||
import gradio as gr
|
||||
from modules import scripts, shared, script_callbacks
|
||||
from modules import script_callbacks
|
||||
from modules import scripts
|
||||
from modules import shared
|
||||
from modules.shared import opts
|
||||
|
||||
_MIN_DIMENSION = 64
|
||||
_MAX_DIMENSION = 2048
|
||||
_EXTENSION_NAME = "Aspect Ratio Helper"
|
||||
_EXTENSION_NAME = 'Aspect Ratio Helper'
|
||||
|
||||
|
||||
def on_ui_settings():
|
||||
section = "aspect_ratio_helper", _EXTENSION_NAME
|
||||
section = 'aspect_ratio_helper', _EXTENSION_NAME
|
||||
shared.opts.add_option(
|
||||
key="arh_expand_by_default",
|
||||
key='arh_expand_by_default',
|
||||
info=shared.OptionInfo(
|
||||
default=False,
|
||||
label="Expand by default",
|
||||
section=section
|
||||
label='Expand by default',
|
||||
section=section,
|
||||
),
|
||||
)
|
||||
shared.opts.add_option(
|
||||
key="arh_show_max_width_or_height",
|
||||
key='arh_show_max_width_or_height',
|
||||
info=shared.OptionInfo(
|
||||
default=True,
|
||||
label="Show maximum width or height button",
|
||||
section=section
|
||||
label='Show maximum width or height button',
|
||||
section=section,
|
||||
),
|
||||
)
|
||||
shared.opts.add_option(
|
||||
key="arh_max_width_or_height",
|
||||
key='arh_max_width_or_height',
|
||||
info=shared.OptionInfo(
|
||||
default=1024,
|
||||
label="Maximum width or height default",
|
||||
section=section
|
||||
label='Maximum width or height default',
|
||||
section=section,
|
||||
),
|
||||
)
|
||||
shared.opts.add_option(
|
||||
key="arh_show_predefined_percentages",
|
||||
key='arh_show_predefined_percentages',
|
||||
info=shared.OptionInfo(
|
||||
default=True,
|
||||
label="Show percentage buttons",
|
||||
section=section
|
||||
label='Show percentage buttons',
|
||||
section=section,
|
||||
),
|
||||
)
|
||||
shared.opts.add_option(
|
||||
key="arh_predefined_percentages",
|
||||
key='arh_predefined_percentages',
|
||||
info=shared.OptionInfo(
|
||||
default="25, 50, 75, 125, 150, 175, 200",
|
||||
label="Percentage buttons (75, 125, 150)",
|
||||
section=section
|
||||
default='25, 50, 75, 125, 150, 175, 200',
|
||||
label='Percentage buttons (75, 125, 150)',
|
||||
section=section,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -92,12 +94,17 @@ class AspectRatioStepScript(scripts.Script):
|
||||
return scripts.AlwaysVisible
|
||||
|
||||
def ui(self, is_img2img):
|
||||
if not any([opts.arh_show_max_width_or_height, opts.arh_show_predefined_percentages]):
|
||||
if not any([
|
||||
opts.arh_show_max_width_or_height,
|
||||
opts.arh_show_predefined_percentages,
|
||||
]):
|
||||
return # return early as no 'show' options enabled
|
||||
|
||||
with (gr.Group(),
|
||||
gr.Accordion(_EXTENSION_NAME, open=opts.arh_expand_by_default),
|
||||
contextlib.suppress(AttributeError)):
|
||||
with (
|
||||
gr.Group(),
|
||||
gr.Accordion(_EXTENSION_NAME, open=opts.arh_expand_by_default),
|
||||
contextlib.suppress(AttributeError),
|
||||
):
|
||||
if is_img2img:
|
||||
inputs = outputs = [self.i2i_w, self.i2i_h]
|
||||
else:
|
||||
@@ -110,9 +117,9 @@ class AspectRatioStepScript(scripts.Script):
|
||||
maximum=2048,
|
||||
step=16,
|
||||
default=opts.arh_max_width_or_height,
|
||||
label="Maximum width or height (whichever is higher)"
|
||||
label='Maximum width or height (whichever is higher)',
|
||||
)
|
||||
gr.Button(value="Scale to maximum width or height").click(
|
||||
gr.Button(value='Scale to maximum width or height').click(
|
||||
fn=_scale_dimensions_to_max_dimension,
|
||||
inputs=[*inputs, max_dimension],
|
||||
outputs=outputs,
|
||||
@@ -120,24 +127,29 @@ class AspectRatioStepScript(scripts.Script):
|
||||
|
||||
if opts.arh_show_predefined_percentages:
|
||||
with gr.Column(variant='panel'), gr.Row(variant='compact'):
|
||||
percentages = [int(x) for x in opts.arh_predefined_percentages.split(',')]
|
||||
pps = opts.arh_predefined_percentages
|
||||
percentages = [
|
||||
int(x) for x in pps.split(',')
|
||||
]
|
||||
for percentage in percentages:
|
||||
gr.Button(value=f"{str(percentage)}%").click(
|
||||
fn=partial(_scale_by_percentage, pct=percentage / 100),
|
||||
gr.Button(value=f'{str(percentage)}%').click(
|
||||
fn=partial(
|
||||
_scale_by_percentage, pct=percentage / 100,
|
||||
),
|
||||
inputs=inputs,
|
||||
outputs=outputs,
|
||||
)
|
||||
|
||||
def after_component(self, component, **kwargs):
|
||||
element_id = kwargs.get("elem_id")
|
||||
element_id = kwargs.get('elem_id')
|
||||
|
||||
if element_id == "txt2img_width":
|
||||
if element_id == 'txt2img_width':
|
||||
self.t2i_w = component
|
||||
elif element_id == "txt2img_height":
|
||||
elif element_id == 'txt2img_height':
|
||||
self.t2i_h = component
|
||||
elif element_id == "img2img_width":
|
||||
elif element_id == 'img2img_width':
|
||||
self.i2i_w = component
|
||||
elif element_id == "img2img_height":
|
||||
elif element_id == 'img2img_height':
|
||||
self.i2i_h = component
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user