This commit is contained in:
abyz22
2024-05-13 14:49:37 +09:00
parent 4ad10c8e78
commit 2eecf642f4
3 changed files with 32 additions and 20 deletions
+13 -10
View File
@@ -9,6 +9,7 @@ import urllib.request
from einops import rearrange
import os
percorso_radice_progetto = os.path.abspath(os.path.dirname(__file__))
from .saicinpainting.training.trainers import load_checkpoint
@@ -16,10 +17,11 @@ from .saicinpainting.training.trainers import load_checkpoint
sys.path.append(percorso_radice_progetto)
devices = 'cuda' if torch.cuda.is_available() else 'cpu'
models_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'models','lama')
devices = "cuda" if torch.cuda.is_available() else "cpu"
models_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "models", "lama")
os.makedirs(models_path, exist_ok=True)
class LamaInpainting:
def __init__(self):
self.model = None
@@ -29,18 +31,18 @@ class LamaInpainting:
os.makedirs(os.path.dirname(model_dir), exist_ok=True)
# urllib.request.urlretrieve(model_path, os.path.join(model_dir, model_path.split("/")[-1]))
urllib.request.urlretrieve(model_path, model_dir)
def load_model(self):
remote_model_path = "https://huggingface.co/lllyasviel/Annotators/resolve/main/ControlNetLama.pth"
modelpath = os.path.join('./custom_nodes/comfyUI_abyz22/annotator/lama/models', "ControlNetLama.pth")
modelpath = os.path.join("./custom_nodes/image_control/annotator/lama/models", "ControlNetLama.pth")
if not os.path.exists(modelpath):
self._load_file_from_url(remote_model_path, model_dir=modelpath)
config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.yaml')
cfg = yaml.safe_load(open(config_path, 'rt'))
config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "config.yaml")
cfg = yaml.safe_load(open(config_path, "rt"))
cfg = OmegaConf.create(cfg)
cfg.training_model.predict_only = True
cfg.visualizer.kind = 'noop'
self.model = load_checkpoint(cfg, os.path.abspath(modelpath), strict=False, map_location='cpu')
cfg.visualizer.kind = "noop"
self.model = load_checkpoint(cfg, os.path.abspath(modelpath), strict=False, map_location="cpu")
self.model = self.model.to(self.device)
self.model.eval()
@@ -50,6 +52,7 @@ class LamaInpainting:
def __call__(self, input_image):
from PIL import Image
if self.model is None:
self.load_model()
self.model.to(self.device)
@@ -64,11 +67,11 @@ class LamaInpainting:
color = color * (1 - mask)
image_feed = torch.cat([color, mask], dim=2)
image_feed = rearrange(image_feed, 'h w c -> 1 c h w')
image_feed = rearrange(image_feed, "h w c -> 1 c h w")
# print('before : ',image_feed.shape)
result = self.model(image_feed)[0]
# print('after : ', result.shape)
result = rearrange(result, 'c h w -> h w c')
result = rearrange(result, "c h w -> h w c")
result = result * mask + color * (1 - mask)
result *= 255.0
return result.detach().cpu().numpy().clip(0, 255).astype(np.uint8)
+2 -1
View File
@@ -193,9 +193,10 @@ class abyz22_AddPrompt:
{
"multiline": True,
"dynamicPrompts": True,
"default": "red light/blue light/yellow light/sun light/pink light/blue light/green light/purple light/gray light/warm atmosphere/sunshine from window/sunshine, outdoor, warm atmosphere/shadow from window/sunset over sea/neon light, city,cyberpunk/light and shadow/natural lighting/sunset/black and white/",
"default": "red light/blue light/yellow light/sun light/pink light/blue light/green light/purple light/gray light/warm atmosphere/sunshine from window/sunshine, outdoor, warm atmosphere/shadow from window/sunset over sea/neon light, cyberpunk/light and shadow/natural lighting/sunset/black and white/daylight/beige light/jade light/emerald light/lime light/aqua light/peach light/coral light/brown light/cream light/khaki light/olive light/frost light/navy light/cyan light/sunny day/",
},
),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xFFFFFFFFFFFFFFFF}),
},
}
+17 -9
View File
@@ -6,7 +6,7 @@ from .utils import any_typ
from server import PromptServer
from . import utils
if os.path.isfile("./custom_nodes/comfyUI_abyz22/prompts_maker.py"):
if os.path.isfile("./custom_nodes/image_control/prompts_maker.py"):
from . import prompts_maker
from openpyxl import load_workbook
from openpyxl.styles import Alignment
@@ -140,11 +140,11 @@ class abyz22_SetQueue:
new_path = "no-data"
if kwargs["Num_of_Prompts"] != 0: # 폴더생성 1 이상이면
if self.highest_num == 0:
if self.highest_num == 0: # 최고폴더 번호 기본값=0 으로 되있으면, 최고폴더 찾기
if kwargs["mode_type"] == "ab":
self.base_folder_path = "E:/stable-diffusion-webui/outputs/1submit/"
self.base_folder_path = "E:/ComfyUI/output/1submit/"
elif kwargs["mode_type"] == "d":
self.base_folder_path = "E:/stable-diffusion-webui/outputs/3submit/"
self.base_folder_path = "E:/ComfyUI/output/3submit/"
file_list = os.listdir(self.base_folder_path)
file_list = [f for f in file_list if len(f.split(".")) == 1]
file_list = [int(f.split(" ")[0]) for f in file_list]
@@ -155,9 +155,11 @@ class abyz22_SetQueue:
if (kwargs["Num_of_Prompts"] == 1) and (kwargs["prompt"] != ""): # 폴더1개만이고 프롬프트 있으면,
self.prompt = kwargs["prompt"]
else:
self.prompt = prompts_maker.make_prompt(mode=kwargs["mode_type"], etc=self.highest_num+1+self.cur_prompts, seed=kwargs["seed"])
self.prompt = prompts_maker.make_prompt(
mode=kwargs["mode_type"], etc=self.highest_num + 1 + self.cur_prompts, seed=kwargs["seed"]
)
epath = "E:/stable-diffusion-webui/outputs/history.xlsx"
epath = "E:/ComfyUI/output/history.xlsx"
T_workbook = load_workbook(epath, data_only=True)
if kwargs["mode_type"] == "ab":
T_worksheet = T_workbook["Sheet1,2"]
@@ -282,7 +284,9 @@ class abyz22_bypass:
if behavior: # mute
should_be_mute_nodes = active_nodes + bypass_nodes
if len(should_be_mute_nodes) > 0:
PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, "mutes": list(should_be_mute_nodes)})
PromptServer.instance.send_sync(
"impact-bridge-continue", {"node_id": unique_id, "mutes": list(should_be_mute_nodes)}
)
error_skip_flag = True
raise Exception(
"IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE\nIf you see this message, your ComfyUI-Manager is outdated. Please update it."
@@ -290,7 +294,9 @@ class abyz22_bypass:
else: # bypass
should_be_bypass_nodes = active_nodes + mute_nodes
if len(should_be_bypass_nodes) > 0:
PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, "bypasses": list(should_be_bypass_nodes)})
PromptServer.instance.send_sync(
"impact-bridge-continue", {"node_id": unique_id, "bypasses": list(should_be_bypass_nodes)}
)
error_skip_flag = True
raise Exception(
"IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE\nIf you see this message, your ComfyUI-Manager is outdated. Please update it."
@@ -299,7 +305,9 @@ class abyz22_bypass:
# active
should_be_active_nodes = mute_nodes + bypass_nodes
if len(should_be_active_nodes) > 0:
PromptServer.instance.send_sync("impact-bridge-continue", {"node_id": unique_id, "actives": list(should_be_active_nodes)})
PromptServer.instance.send_sync(
"impact-bridge-continue", {"node_id": unique_id, "actives": list(should_be_active_nodes)}
)
error_skip_flag = True
raise Exception(
"IMPACT-PACK-SIGNAL: STOP CONTROL BRIDGE\nIf you see this message, your ComfyUI-Manager is outdated. Please update it."