Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Bing-su committed May 19, 2024
2 parents 1edd588 + fd6cab8 commit 0187228
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 49 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lint.yml → .github/workflows/lgtm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
jobs:
lint:
permissions:
issues: write
pull-requests: write
runs-on: ubuntu-latest

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,4 @@ pyrightconfig.json

# End of https://www.toptal.com/developers/gitignore/api/python,visualstudiocode
*.ipynb
node_modules
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ repos:
- id: end-of-file-fixer
- id: mixed-line-ending

- repo: https://github.com/pre-commit/mirrors-prettier
rev: "v4.0.0-alpha.8"
- repo: https://github.com/rbubley/mirrors-prettier
rev: v3.2.5
hooks:
- id: prettier

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.7
rev: v0.4.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 2024-05-19

- v24.5.0
- 개별 탭 활성화/비활성화 체크박스 추가
- ad_extra_model_dir 옵션에 |로 구분된 여러 디렉토리를 추가할 수 있게 함 (PR #596)
- `hypertile` 빌트인 확장이 지원되도록 함
- 항상 cond 캐시를 비움
- 설치 스크립트에 uv를 사용함
- mediapipe 최소 버전을 올려 protobuf 버전 4를 사용하게 함

## 2024-04-17

- v24.4.2
Expand Down
5 changes: 3 additions & 2 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ tasks:
cmds:
- echo "$PYTHON"
- echo "$WEBUI"
- echo "$UV_PYTHON"
silent: true

launch:
Expand All @@ -24,8 +25,8 @@ tasks:

update:
cmds:
- "{{.PYTHON}} -m pip install -U ultralytics mediapipe ruff pre-commit black devtools pytest"
- "{{.PYTHON}} -m uv pip install -U ultralytics mediapipe ruff pre-commit black devtools pytest"

update-torch:
cmds:
- "{{.PYTHON}} -m pip install -U torch torchvision torchaudio -f https://download.pytorch.org/whl/torch_stable.html"
- "{{.PYTHON}} -m uv pip install -U torch torchvision torchaudio -f https://download.pytorch.org/whl/torch_stable.html"
4 changes: 4 additions & 0 deletions aaaaaa/p_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ def get_i(p) -> int:
bs = p.batch_size
i = p.batch_index
return it * bs + i


def is_skip_img2img(p) -> bool:
return getattr(p, "_ad_skip_img2img", False)
30 changes: 19 additions & 11 deletions adetailer/traceback.py → aaaaaa/traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from rich.traceback import Traceback

from adetailer.__version__ import __version__
from adetailer.args import ADetailerArgs


def processing(*args: Any) -> dict[str, Any]:
Expand Down Expand Up @@ -66,23 +67,30 @@ def sd_models() -> dict[str, str]:


def ad_args(*args: Any) -> dict[str, Any]:
ad_args = [
arg
for arg in args
if isinstance(arg, dict) and arg.get("ad_model", "None") != "None"
]
ad_args = []
for arg in args:
if not isinstance(arg, dict):
continue

try:
a = ADetailerArgs(**arg)
except ValueError:
continue

if not a.need_skip():
ad_args.append(a)

if not ad_args:
return {}

arg0 = ad_args[0]
is_api = arg0.get("is_api", True)
return {
"version": __version__,
"ad_model": arg0["ad_model"],
"ad_prompt": arg0.get("ad_prompt", ""),
"ad_negative_prompt": arg0.get("ad_negative_prompt", ""),
"ad_controlnet_model": arg0.get("ad_controlnet_model", "None"),
"is_api": type(is_api) is not tuple,
"ad_model": arg0.ad_model,
"ad_prompt": arg0.ad_prompt,
"ad_negative_prompt": arg0.ad_negative_prompt,
"ad_controlnet_model": arg0.ad_controlnet_model,
"is_api": arg0.is_api,
}


Expand Down
26 changes: 18 additions & 8 deletions adetailer/ui.py → aaaaaa/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def adui(
states.append(state)
infotext_fields.extend(infofields)

# components: [bool, dict, dict, ...]
# components: [bool, bool, dict, dict, ...]
components = [ad_enable, ad_skip_img2img, *states]
return components, infotext_fields

Expand All @@ -171,26 +171,35 @@ def one_ui_group(n: int, is_img2img: bool, webui_info: WebuiInfo):
w = Widgets()
eid = partial(elem_id, n=n, is_img2img=is_img2img)

model_choices = (
[*webui_info.ad_model_list, "None"]
if n == 0
else ["None", *webui_info.ad_model_list]
)

with gr.Group():
with gr.Row():
model_choices = (
[*webui_info.ad_model_list, "None"]
if n == 0
else ["None", *webui_info.ad_model_list]
with gr.Row(variant="compact"):
w.ad_tap_enable = gr.Checkbox(
label=f"Enable this tap ({ordinal(n + 1)})",
value=True,
visible=True,
elem_id=eid("ad_tap_enable"),
)

with gr.Row():
w.ad_model = gr.Dropdown(
label="ADetailer model" + suffix(n),
label="ADetailer detector" + suffix(n),
choices=model_choices,
value=model_choices[0],
visible=True,
type="value",
elem_id=eid("ad_model"),
info="Select a model to use for detection.",
)

with gr.Row():
w.ad_model_classes = gr.Textbox(
label="ADetailer model classes" + suffix(n),
label="ADetailer detector classes" + suffix(n),
value="",
visible=False,
elem_id=eid("ad_classes"),
Expand Down Expand Up @@ -354,6 +363,7 @@ def mask_preprocessing(w: Widgets, n: int, is_img2img: bool):
choices=MASK_MERGE_INVERT,
value="None",
elem_id=eid("ad_mask_merge_invert"),
info="None: do nothing, Merge: merge masks, Merge and Invert: merge all masks and invert",
)


Expand Down
2 changes: 1 addition & 1 deletion adetailer/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "24.4.2"
__version__ = "24.5.0"
15 changes: 13 additions & 2 deletions adetailer/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def names(self) -> tuple[str, ...]:
class ADetailerArgs(BaseModel, extra=Extra.forbid):
ad_model: str = "None"
ad_model_classes: str = ""
ad_tap_enable: bool = True
ad_prompt: str = ""
ad_negative_prompt: str = ""
ad_confidence: confloat(ge=0.0, le=1.0) = 0.3
Expand Down Expand Up @@ -119,7 +120,7 @@ def ppop(
p.pop(k, None)

def extra_params(self, suffix: str = "") -> dict[str, Any]:
if self.ad_model == "None":
if self.need_skip():
return {}

p = {name: getattr(self, attr) for attr, name in ALL_ARGS}
Expand All @@ -128,6 +129,7 @@ def extra_params(self, suffix: str = "") -> dict[str, Any]:
ppop("ADetailer model classes")
ppop("ADetailer prompt")
ppop("ADetailer negative prompt")
p.pop("ADetailer tap enable", None) # always pop
ppop("ADetailer mask only top k largest", cond=0)
ppop("ADetailer mask min ratio", cond=0.0)
ppop("ADetailer mask max ratio", cond=1.0)
Expand Down Expand Up @@ -200,10 +202,17 @@ def extra_params(self, suffix: str = "") -> dict[str, Any]:

return p

def is_mediapipe(self) -> bool:
return self.ad_model.lower().startswith("mediapipe")

def need_skip(self) -> bool:
return self.ad_model == "None" or self.ad_tap_enable is False


_all_args = [
("ad_model", "ADetailer model"),
("ad_model_classes", "ADetailer model classes"),
("ad_tap_enable", "ADetailer tap enable"),
("ad_prompt", "ADetailer prompt"),
("ad_negative_prompt", "ADetailer negative prompt"),
("ad_confidence", "ADetailer confidence"),
Expand Down Expand Up @@ -262,6 +271,8 @@ def extra_params(self, suffix: str = "") -> dict[str, Any]:
"wildcards",
"lora_block_weight",
"negpip",
"soft_inpainting",
)
SCRIPT_DEFAULT = ",".join(sorted(_script_default))

_builtin_script = ("soft_inpainting", "hypertile_script")
BUILTIN_SCRIPT = ",".join(sorted(_builtin_script))
22 changes: 17 additions & 5 deletions install.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import importlib.util
import os
import subprocess
import sys
from importlib.metadata import version # python >= 3.8
Expand Down Expand Up @@ -38,19 +39,29 @@ def is_installed(


def run_pip(*args):
subprocess.run([sys.executable, "-m", "pip", "install", *args])
subprocess.run([sys.executable, "-m", "pip", "install", *args], check=False)


def run_uv_pip(*args):
subprocess.run([sys.executable, "-m", "uv", "pip", "install", *args], check=False)


def install():
deps = [
# requirements
("ultralytics", "8.1.29", None),
("mediapipe", "0.10.9", None),
("ultralytics", "8.2.0", None),
("mediapipe", "0.10.13", None),
("rich", "13.0.0", None),
# mediapipe
("protobuf", "3.20", "3.9999"),
("protobuf", "4.25.3", "4.9999"),
]

if not is_installed("uv", "0.1.44", None):
run_pip("uv>=0.1.44")

os.environ["UV_PYTHON"] = sys.executable

pkgs = []
for pkg, low, high in deps:
if not is_installed(pkg, low, high):
if low and high:
Expand All @@ -61,8 +72,9 @@ def install():
cmd = f"{pkg}<={high}"
else:
cmd = pkg
pkgs.append(cmd)

run_pip("-U", cmd)
run_uv_pip(*pkgs)


try:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
name = "adetailer"
description = "An object detection and auto-mask extension for stable diffusion webui."
authors = [{ name = "dowon", email = "[email protected]" }]
requires-python = ">=3.8,<3.13"
requires-python = ">=3.8"
readme = "README.md"
license = { text = "AGPL-3.0" }
dependencies = [
"ultralytics>=8.1",
"ultralytics>=8.2",
"mediapipe>=0.10",
"pydantic<3",
"rich>=13",
Expand Down
Loading

0 comments on commit 0187228

Please sign in to comment.