Fix issues with missing __init__ in upscaler, move web/ directory to comfy/web so that the need for symbolic link support on windows is eliminated

This commit is contained in:
doctorpangloss 2024-01-03 16:35:00 -08:00
parent d31298ac60
commit 345825dfb5
50 changed files with 18 additions and 16 deletions

2
.gitignore vendored
View File

@ -35,8 +35,6 @@ dist/
downloads/ downloads/
eggs/ eggs/
.eggs/ .eggs/
lib/
lib64/
parts/ parts/
sdist/ sdist/
var/ var/

View File

@ -1 +1 @@
recursive-include web * recursive-include comfy/web *

View File

@ -105,7 +105,7 @@ class PromptServer():
self.app = web.Application(client_max_size=max_upload_size, handler_args={'max_field_size': 16380}, self.app = web.Application(client_max_size=max_upload_size, handler_args={'max_field_size': 16380},
middlewares=middlewares) middlewares=middlewares)
self.sockets = dict() self.sockets = dict()
web_root_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../../web") web_root_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../web")
if not os.path.exists(web_root_path): if not os.path.exists(web_root_path):
web_root_path = resource_filename('comfy', 'web/') web_root_path = resource_filename('comfy', 'web/')
self.web_root = web_root_path self.web_root = web_root_path

View File

@ -1 +0,0 @@
../web

View File

@ -8,8 +8,9 @@ from comfy.cmd import folder_paths
class UpscaleModelLoader: class UpscaleModelLoader:
@classmethod @classmethod
def INPUT_TYPES(s): def INPUT_TYPES(s):
return {"required": { "model_name": (folder_paths.get_filename_list("upscale_models"),), return {"required": {"model_name": (folder_paths.get_filename_list("upscale_models"),),
}} }}
RETURN_TYPES = ("UPSCALE_MODEL",) RETURN_TYPES = ("UPSCALE_MODEL",)
FUNCTION = "load_model" FUNCTION = "load_model"
@ -19,17 +20,18 @@ class UpscaleModelLoader:
model_path = folder_paths.get_full_path("upscale_models", model_name) model_path = folder_paths.get_full_path("upscale_models", model_name)
sd = utils.load_torch_file(model_path, safe_load=True) sd = utils.load_torch_file(model_path, safe_load=True)
if "module.layers.0.residual_group.blocks.0.norm1.weight" in sd: if "module.layers.0.residual_group.blocks.0.norm1.weight" in sd:
sd = utils.state_dict_prefix_replace(sd, {"module.":""}) sd = utils.state_dict_prefix_replace(sd, {"module.": ""})
out = model_loading.load_state_dict(sd).eval() out = model_loading.load_state_dict(sd).eval()
return (out, ) return (out,)
class ImageUpscaleWithModel: class ImageUpscaleWithModel:
@classmethod @classmethod
def INPUT_TYPES(s): def INPUT_TYPES(s):
return {"required": { "upscale_model": ("UPSCALE_MODEL",), return {"required": {"upscale_model": ("UPSCALE_MODEL",),
"image": ("IMAGE",), "image": ("IMAGE",),
}} }}
RETURN_TYPES = ("IMAGE",) RETURN_TYPES = ("IMAGE",)
FUNCTION = "upscale" FUNCTION = "upscale"
@ -38,7 +40,7 @@ class ImageUpscaleWithModel:
def upscale(self, upscale_model, image): def upscale(self, upscale_model, image):
device = model_management.get_torch_device() device = model_management.get_torch_device()
upscale_model.to(device) upscale_model.to(device)
in_img = image.movedim(-1,-3).to(device) in_img = image.movedim(-1, -3).to(device)
free_memory = model_management.get_free_memory(device) free_memory = model_management.get_free_memory(device)
tile = 512 tile = 512
@ -47,9 +49,11 @@ class ImageUpscaleWithModel:
oom = True oom = True
while oom: while oom:
try: try:
steps = in_img.shape[0] * utils.get_tiled_scale_steps(in_img.shape[3], in_img.shape[2], tile_x=tile, tile_y=tile, overlap=overlap) steps = in_img.shape[0] * utils.get_tiled_scale_steps(in_img.shape[3], in_img.shape[2], tile_x=tile,
tile_y=tile, overlap=overlap)
pbar = utils.ProgressBar(steps) pbar = utils.ProgressBar(steps)
s = utils.tiled_scale(in_img, lambda a: upscale_model(a), tile_x=tile, tile_y=tile, overlap=overlap, upscale_amount=upscale_model.scale, pbar=pbar) s = utils.tiled_scale(in_img, lambda a: upscale_model(a), tile_x=tile, tile_y=tile, overlap=overlap,
upscale_amount=upscale_model.scale, pbar=pbar)
oom = False oom = False
except model_management.OOM_EXCEPTION as e: except model_management.OOM_EXCEPTION as e:
tile //= 2 tile //= 2
@ -57,9 +61,10 @@ class ImageUpscaleWithModel:
raise e raise e
upscale_model.cpu() upscale_model.cpu()
s = torch.clamp(s.movedim(-3,-1), min=0, max=1.0) s = torch.clamp(s.movedim(-3, -1), min=0, max=1.0)
return (s,) return (s,)
NODE_CLASS_MAPPINGS = { NODE_CLASS_MAPPINGS = {
"UpscaleModelLoader": UpscaleModelLoader, "UpscaleModelLoader": UpscaleModelLoader,
"ImageUpscaleWithModel": ImageUpscaleWithModel "ImageUpscaleWithModel": ImageUpscaleWithModel

View File

@ -150,7 +150,7 @@ def dependencies() -> List[str]:
package_data = ['sd1_tokenizer/*', '**/*.json', '**/*.yaml'] package_data = ['sd1_tokenizer/*', '**/*.json', '**/*.yaml']
if not is_editable: if not is_editable:
package_data.append('web/**/*') package_data.append('comfy/web/**/*')
setup( setup(
name=package_name, name=package_name,
description="", description="",