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/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
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},
middlewares=middlewares)
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):
web_root_path = resource_filename('comfy', 'web/')
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:
@classmethod
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",)
FUNCTION = "load_model"
@ -19,17 +20,18 @@ class UpscaleModelLoader:
model_path = folder_paths.get_full_path("upscale_models", model_name)
sd = utils.load_torch_file(model_path, safe_load=True)
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()
return (out, )
return (out,)
class ImageUpscaleWithModel:
@classmethod
def INPUT_TYPES(s):
return {"required": { "upscale_model": ("UPSCALE_MODEL",),
"image": ("IMAGE",),
}}
return {"required": {"upscale_model": ("UPSCALE_MODEL",),
"image": ("IMAGE",),
}}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "upscale"
@ -38,7 +40,7 @@ class ImageUpscaleWithModel:
def upscale(self, upscale_model, image):
device = model_management.get_torch_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)
tile = 512
@ -47,9 +49,11 @@ class ImageUpscaleWithModel:
oom = True
while oom:
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)
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
except model_management.OOM_EXCEPTION as e:
tile //= 2
@ -57,9 +61,10 @@ class ImageUpscaleWithModel:
raise e
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,)
NODE_CLASS_MAPPINGS = {
"UpscaleModelLoader": UpscaleModelLoader,
"ImageUpscaleWithModel": ImageUpscaleWithModel

View File

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