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 Mar 1, 2024
2 parents 8f01dfd + 302540d commit 3f1d1b9
Show file tree
Hide file tree
Showing 21 changed files with 410 additions and 78 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Lint

on:
pull_request:
paths:
- "**.py"

jobs:
lint:
runs-on: ubuntu-latest
if: github.repository == 'Bing-su/adetailer' || github.repository == ''

steps:
- uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install python packages
run: pip install black ruff pre-commit-hooks

- name: Run pre-commit-hooks
run: |
check-ast
trailing-whitespace-fixer --markdown-linebreak-ext=md
end-of-file-fixer
mixed-line-ending
- name: Run black
run: black --check .

- name: Run ruff
run: ruff check .
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v8
- uses: actions/stale@v9
with:
days-before-stale: 23
days-before-close: 3
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ repos:
- id: mixed-line-ending

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.14
rev: v0.2.2
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.1
rev: 24.2.0
hooks:
- id: black
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 2024-03-01

- v24.3.0
- YOLO World 모델 추가: 가장 큰 yolov8x-world.pt 모델만 기본적으로 선택할 수 있게 함.
- lllyasviel/stable-diffusion-webui-forge에서 컨트롤넷을 사용가능하게 함 (PR #517)
- 기본 스크립트 목록에 soft_inpainting 추가 (https://github.com/AUTOMATIC1111/stable-diffusion-webui/pull/14208)
- 기존에 설치한 사람에게 소급적용되지는 않음

- 감지모델에 대한 간단한 pytest 추가함
- xyz grid 컨트롤넷 모델 옵션에 `Passthrough` 추가함

## 2024-01-23

- v24.1.2
Expand Down
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ You can now install it directly from the Extensions tab.

![image](https://i.imgur.com/g6GdRBT.png)

You **DON'T** need to download any model from huggingface.
You **DON'T** need to download any base model from huggingface.

## Options

| Model, Prompts | | |
| --------------------------------- | --------------------------------------------------------------------------------- | ------------------------------------------------- |
| ADetailer model | Determine what to detect. | `None` = disable |
| ADetailer prompt, negative prompt | Prompts and negative prompts to apply | If left blank, it will use the same as the input. |
| Skip img2img | Skip img2img. In practice, this works by changing the step count of img2img to 1. | img2img only |
| Model, Prompts | | |
| --------------------------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| ADetailer model | Determine what to detect. | `None` = disable |
| ADetailer model classes | Comma separated class names to detect. only available when using YOLO World models | If blank, use default values.<br/>default = [COCO 80 classes](https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/datasets/coco.yaml) |
| ADetailer prompt, negative prompt | Prompts and negative prompts to apply | If left blank, it will use the same as the input. |
| Skip img2img | Skip img2img. In practice, this works by changing the step count of img2img to 1. | img2img only |

| Detection | | |
| ------------------------------------ | -------------------------------------------------------------------------------------------- | ------------ |
Expand All @@ -52,7 +53,9 @@ Each option corresponds to a corresponding option on the inpaint tab. Therefore,

You can use the ControlNet extension if you have ControlNet installed and ControlNet models.

Support `inpaint, scribble, lineart, openpose, tile` controlnet models. Once you choose a model, the preprocessor is set automatically. It works separately from the model set by the Controlnet extension.
Support `inpaint, scribble, lineart, openpose, tile, depth` controlnet models. Once you choose a model, the preprocessor is set automatically. It works separately from the model set by the Controlnet extension.

If you select `Passthrough`, the controlnet settings you set outside of ADetailer will be used.

## Advanced Options

Expand Down Expand Up @@ -80,11 +83,15 @@ API request example: [wiki/API](https://github.com/Bing-su/adetailer/wiki/API)
| mediapipe_face_short | realistic face | - | - |
| mediapipe_face_mesh | realistic face | - | - |

The yolo models can be found on huggingface [Bingsu/adetailer](https://huggingface.co/Bingsu/adetailer).
The YOLO models can be found on huggingface [Bingsu/adetailer](https://huggingface.co/Bingsu/adetailer).

For a detailed description of the YOLO8 model, see: https://docs.ultralytics.com/models/yolov8/#overview

YOLO World model: https://docs.ultralytics.com/models/yolo-world/

### Additional Model

Put your [ultralytics](https://github.com/ultralytics/ultralytics) yolo model in `webui/models/adetailer`. The model name should end with `.pt` or `.pth`.
Put your [ultralytics](https://github.com/ultralytics/ultralytics) yolo model in `webui/models/adetailer`. The model name should end with `.pt`.

It must be a bbox detection or segment model and use all label.

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.1.2"
__version__ = "24.3.0"
9 changes: 5 additions & 4 deletions adetailer/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from functools import cached_property, partial
from typing import Any, Literal, NamedTuple, Optional

import pydantic
from pydantic import (
BaseModel,
Extra,
Expand All @@ -14,7 +13,6 @@
PositiveInt,
confloat,
conint,
constr,
validator,
)

Expand All @@ -34,16 +32,17 @@ class Arg(NamedTuple):

class ArgsList(UserList):
@cached_property
def attrs(self) -> tuple[str]:
def attrs(self) -> tuple[str, ...]:
return tuple(attr for attr, _ in self)

@cached_property
def names(self) -> tuple[str]:
def names(self) -> tuple[str, ...]:
return tuple(name for _, name in self)


class ADetailerArgs(BaseModel, extra=Extra.forbid):
ad_model: str = "None"
ad_model_classes: str = ""
ad_prompt: str = ""
ad_negative_prompt: str = ""
ad_confidence: confloat(ge=0.0, le=1.0) = 0.3
Expand Down Expand Up @@ -113,6 +112,7 @@ def extra_params(self, suffix: str = "") -> dict[str, Any]:
p = {name: getattr(self, attr) for attr, name in ALL_ARGS}
ppop = partial(self.ppop, p)

ppop("ADetailer model classes")
ppop("ADetailer prompt")
ppop("ADetailer negative prompt")
ppop("ADetailer mask only top k largest", cond=0)
Expand Down Expand Up @@ -185,6 +185,7 @@ def extra_params(self, suffix: str = "") -> dict[str, Any]:

_all_args = [
("ad_model", "ADetailer model"),
("ad_model_classes", "ADetailer model classes"),
("ad_prompt", "ADetailer prompt"),
("ad_negative_prompt", "ADetailer negative prompt"),
("ad_confidence", "ADetailer confidence"),
Expand Down
9 changes: 6 additions & 3 deletions adetailer/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
from collections import OrderedDict
from dataclasses import dataclass, field
from pathlib import Path
from typing import Optional, Union
from typing import Optional

from huggingface_hub import hf_hub_download
from PIL import Image, ImageDraw
from rich import print

repo_id = "Bingsu/adetailer"
REPO_ID = "Bingsu/adetailer"
_download_failed = False


Expand All @@ -20,7 +20,7 @@ class PredictOutput:
preview: Optional[Image.Image] = None


def hf_download(file: str):
def hf_download(file: str, repo_id: str = REPO_ID) -> str | None:
global _download_failed

if _download_failed:
Expand Down Expand Up @@ -56,6 +56,9 @@ def get_models(
"hand_yolov8n.pt": hf_download("hand_yolov8n.pt"),
"person_yolov8n-seg.pt": hf_download("person_yolov8n-seg.pt"),
"person_yolov8s-seg.pt": hf_download("person_yolov8s-seg.pt"),
"yolov8x-world.pt": hf_download(
"yolov8x-world.pt", repo_id="Bingsu/yolo-world-mirror"
),
}
)
models.update(
Expand Down
105 changes: 72 additions & 33 deletions adetailer/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,37 @@

from adetailer import AFTER_DETAILER, __version__
from adetailer.args import ALL_ARGS, MASK_MERGE_INVERT
from controlnet_ext import controlnet_exists, get_cn_models

cn_module_choices = {
"inpaint": [
"inpaint_global_harmonious",
"inpaint_only",
"inpaint_only+lama",
],
"lineart": [
"lineart_coarse",
"lineart_realistic",
"lineart_anime",
"lineart_anime_denoise",
],
"openpose": ["openpose_full", "dw_openpose_full"],
"tile": ["tile_resample", "tile_colorfix", "tile_colorfix+sharp"],
"scribble": ["t2ia_sketch_pidi"],
"depth": ["depth_midas", "depth_hand_refiner"],
}
from controlnet_ext import controlnet_exists, controlnet_type, get_cn_models

if controlnet_type == "forge":
from lib_controlnet import global_state

cn_module_choices = {
"inpaint": list(global_state.get_filtered_preprocessors("Inpaint")),
"lineart": list(global_state.get_filtered_preprocessors("Lineart")),
"openpose": list(global_state.get_filtered_preprocessors("OpenPose")),
"tile": list(global_state.get_filtered_preprocessors("Tile")),
"scribble": list(global_state.get_filtered_preprocessors("Scribble")),
"depth": list(global_state.get_filtered_preprocessors("Depth")),
}
else:
cn_module_choices = {
"inpaint": [
"inpaint_global_harmonious",
"inpaint_only",
"inpaint_only+lama",
],
"lineart": [
"lineart_coarse",
"lineart_realistic",
"lineart_anime",
"lineart_anime_denoise",
],
"openpose": ["openpose_full", "dw_openpose_full"],
"tile": ["tile_resample", "tile_colorfix", "tile_colorfix+sharp"],
"scribble": ["t2ia_sketch_pidi"],
"depth": ["depth_midas", "depth_hand_refiner"],
}


class Widgets(SimpleNamespace):
Expand Down Expand Up @@ -73,6 +85,15 @@ def on_generate_click(state: dict, *values: Any):
return state


def on_ad_model_update(model: str):
if "-world" in model:
return gr.update(
visible=True,
placeholder="Comma separated class names to detect, ex: 'person,cat'. default: COCO 80 classes",
)
return gr.update(visible=False, placeholder="")


def on_cn_model_update(cn_model_name: str):
cn_model_name = cn_model_name.replace("inpaint_depth", "depth")
for t in cn_module_choices:
Expand Down Expand Up @@ -149,21 +170,39 @@ def one_ui_group(n: int, is_img2img: bool, webui_info: WebuiInfo):
w = Widgets()
eid = partial(elem_id, n=n, is_img2img=is_img2img)

with gr.Row():
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]
)

w.ad_model = gr.Dropdown(
label="ADetailer model" + suffix(n),
choices=model_choices,
value=model_choices[0],
visible=True,
type="value",
elem_id=eid("ad_model"),
)
w.ad_model = gr.Dropdown(
label="ADetailer model" + suffix(n),
choices=model_choices,
value=model_choices[0],
visible=True,
type="value",
elem_id=eid("ad_model"),
)

with gr.Row():
w.ad_model_classes = gr.Textbox(
label="ADetailer model classes" + suffix(n),
value="",
visible=False,
elem_id=eid("ad_classes"),
)

w.ad_model.change(
on_ad_model_update,
inputs=w.ad_model,
outputs=w.ad_model_classes,
queue=False,
)

gr.HTML("<br>")

with gr.Group():
with gr.Row(elem_id=eid("ad_toprow_prompt")):
Expand Down
Loading

0 comments on commit 3f1d1b9

Please sign in to comment.