diff --git a/adv_encode.py b/adv_encode.py index 2156601..6c8537d 100644 --- a/adv_encode.py +++ b/adv_encode.py @@ -212,7 +212,7 @@ def advanced_encode_from_tokens(tokenized, token_normalization, weight_interpret return weighted_emb, pooled else: return weighted_emb, pooled_base - return [[weighted_emb,{}]], None + return weighted_emb, None def encode_token_weights_g(model, token_weight_pairs): return model.clip_g.encode_token_weights(token_weight_pairs) @@ -287,4 +287,4 @@ def advanced_encode_XL(clip, text1, text2, token_normalization, weight_interpret repeat_l = int((embs_g.shape[1] / gcd_num) * embs_l.shape[1]) repeat_g = int((embs_l.shape[1] / gcd_num) * embs_g.shape[1]) - return prepareXL(embs_l.expand((-1,repeat_l,-1)), embs_g.expand((-1,repeat_g,-1)), pooled, clip_balance) \ No newline at end of file + return prepareXL(embs_l.expand((-1,repeat_l,-1)), embs_g.expand((-1,repeat_g,-1)), pooled, clip_balance) diff --git a/js/ttNinterface.js b/js/ttNinterface.js index 7090965..5e1148a 100644 --- a/js/ttNinterface.js +++ b/js/ttNinterface.js @@ -281,6 +281,44 @@ app.registerExtension({ return false; }; + LGraphCanvas.ttNlinkStyleBorder = function(value, options, e, menu, node) { + new LiteGraph.ContextMenu( + [false, true], + { event: e, callback: inner_clicked, parentMenu: menu, node: node } + ); + + function inner_clicked(v) { + if (!node) { + return; + } + + localStorage.setItem('Comfy.Settings.ttN.links_render_border', JSON.stringify(v)); + + app.canvas.render_connections_border = v; + } + + return false; + }; + + LGraphCanvas.ttNlinkStyleShadow = function(value, options, e, menu, node) { + new LiteGraph.ContextMenu( + [false, true], + { event: e, callback: inner_clicked, parentMenu: menu, node: node } + ); + + function inner_clicked(v) { + if (!node) { + return; + } + + localStorage.setItem('Comfy.Settings.ttN.links_render_shadow', JSON.stringify(v)); + + app.canvas.render_connections_shadows = v; + } + + return false; + }; + LGraphCanvas.ttNsetDefaultBGColor = function(value, options, e, menu, node) { if (!node) { throw "no node for color"; @@ -353,6 +391,22 @@ app.registerExtension({ ); return options; }; + + LGraphCanvas.prototype.ttNupdateRenderSettings = function (app) { + console.log('i made it') + let customLinkType = Number(localStorage.getItem('Comfy.Settings.ttN.links_render_mode')); + if (customLinkType !== undefined) {app.canvas.links_render_mode = customLinkType} + + let showLinkBorder = Number(localStorage.getItem('Comfy.Settings.ttN.links_render_border')); + if (showLinkBorder !== undefined) {app.canvas.render_connections_border = showLinkBorder} + + let showLinkShadow = Number(localStorage.getItem('Comfy.Settings.ttN.links_render_shadow')); + if (showLinkShadow) {app.canvas.render_connections_shadows = showLinkShadow} + + var customLinkColors = JSON.parse(localStorage.getItem('Comfy.Settings.ttN.customLinkColors')) || {}; + Object.assign(app.canvas.default_connection_color_byType, customLinkColors); + Object.assign(LGraphCanvas.link_type_colors, customLinkColors); + } }, beforeRegisterNodeDef(nodeType, nodeData, app) { @@ -379,6 +433,8 @@ app.registerExtension({ } menu_info.push({ content: "Slot Type Color (ttN)", slot: slot, callback: () => { LGraphCanvas.prototype.ttNsetSlotTypeColor(slot) } }); + menu_info.push({ content: "Show Link Border (ttN)", has_submenu: true, slot: slot, callback: LGraphCanvas.ttNlinkStyleBorder }); + menu_info.push({ content: "Show Link Shadow (ttN)", has_submenu: true, slot: slot, callback: LGraphCanvas.ttNlinkStyleShadow }); menu_info.push({ content: "Link Style (ttN)", has_submenu: true, slot: slot, callback: LGraphCanvas.ttNonShowLinkStyles }); return menu_info; @@ -386,19 +442,15 @@ app.registerExtension({ }, setup() { - let customLinkType = Number(localStorage.getItem('Comfy.Settings.ttN.links_render_mode')); - if (customLinkType) {app.canvas.links_render_mode = customLinkType} - - var customLinkColors = JSON.parse(localStorage.getItem('Comfy.Settings.ttN.customLinkColors')) || {}; - Object.assign(app.canvas.default_connection_color_byType, customLinkColors); - Object.assign(LGraphCanvas.link_type_colors, customLinkColors); - + LGraphCanvas.prototype.ttNupdateRenderSettings(app); }, nodeCreated(node) { let defaultBGColor = JSON.parse(localStorage.getItem('Comfy.Settings.ttN.defaultBGColor')); if (defaultBGColor) {LGraphCanvas.prototype.ttNdefaultBGcolor(node, defaultBGColor)}; }, loadedGraphNode(node, app) { + LGraphCanvas.prototype.ttNupdateRenderSettings(app); + let defaultBGColor = JSON.parse(localStorage.getItem('Comfy.Settings.ttN.defaultBGColor')); if (defaultBGColor) {LGraphCanvas.prototype.ttNdefaultBGcolor(node, defaultBGColor)}; }, diff --git a/tinyterraNodes.py b/tinyterraNodes.py index f71af43..08f4849 100644 --- a/tinyterraNodes.py +++ b/tinyterraNodes.py @@ -19,11 +19,11 @@ from torch import Tensor from pathlib import Path import comfy.model_management from PIL.PngImagePlugin import PngInfo -from .adv_encode import advanced_encode from PIL import Image, ImageDraw, ImageFont from comfy.sd import ModelPatcher, CLIP, VAE from typing import Dict, List, Optional, Tuple, Union from comfy_extras.chainner_models import model_loading +from .adv_encode import advanced_encode, advanced_encode_XL class CC: CLEAN = '\33[0m' @@ -342,24 +342,18 @@ def enforce_mul_of_64(d): return int(d) -def upscale(samples, upscale_method, factor, crop): - s = samples.copy() - x = samples["samples"].shape[3] - y = samples["samples"].shape[2] +def upscale(samples, upscale_method, scale_by, crop): + s = samples.copy() + width = enforce_mul_of_64(round(samples["samples"].shape[3] * scale_by)) + height = enforce_mul_of_64(round(samples["samples"].shape[2] * scale_by)) - new_x = int(x * factor) - new_y = int(y * factor) - - if (new_x > MAX_RESOLUTION): - new_x = MAX_RESOLUTION - if (new_y > MAX_RESOLUTION): - new_y = MAX_RESOLUTION - - s["samples"] = comfy.utils.common_upscale( - samples["samples"], enforce_mul_of_64( - new_x), enforce_mul_of_64(new_y), upscale_method, crop - ) - return (s,) + if (width > MAX_RESOLUTION): + width = MAX_RESOLUTION + if (height > MAX_RESOLUTION): + height = MAX_RESOLUTION + + s["samples"] = comfy.utils.common_upscale(samples["samples"], width, height, upscale_method, crop) + return (s,) def tensor2pil(image: torch.Tensor) -> Image.Image: return Image.fromarray(np.clip(255. * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8)) @@ -495,7 +489,7 @@ def save_images(self, images, preview_prefix, save_prefix, image_output, prompt= #---------------------------------------------------------------ttN/pipe START----------------------------------------------------------------------# class ttN_TSC_pipeLoader: - version = '1.0.0' + version = '1.0.1' @classmethod def INPUT_TYPES(cls): return {"required": { @@ -517,11 +511,11 @@ class ttN_TSC_pipeLoader: "positive": ("STRING", {"default": "Positive","multiline": True}), "positive_token_normalization": (["none", "mean", "length", "length+mean"],), - "positive_weight_interpretation": (["comfy", "A1111", "compel", "comfy++"],), + "positive_weight_interpretation": (["comfy", "A1111", "compel", "comfy++", "down_weight"],), "negative": ("STRING", {"default": "Negative", "multiline": True}), "negative_token_normalization": (["none", "mean", "length", "length+mean"],), - "negative_weight_interpretation": (["comfy", "A1111", "compel", "comfy++"],), + "negative_weight_interpretation": (["comfy", "A1111", "compel", "comfy++", "down_weight"],), "empty_latent_width": ("INT", {"default": 512, "min": 64, "max": MAX_RESOLUTION, "step": 8}), "empty_latent_height": ("INT", {"default": 512, "min": 64, "max": MAX_RESOLUTION, "step": 8}), @@ -577,8 +571,11 @@ class ttN_TSC_pipeLoader: clip = clip.clone() clip.clip_layer(clip_skip) - positive_embeddings_final, pooled = advanced_encode(clip, positive, positive_token_normalization, positive_weight_interpretation, w_max=1.0) - negative_embeddings_final, pooled = advanced_encode(clip, negative, negative_token_normalization, negative_weight_interpretation, w_max=1.0) + positive_embeddings_final, positive_pooled = advanced_encode(clip, positive, positive_token_normalization, positive_weight_interpretation, w_max=1.0, apply_to_pooled='enable') + positive_embeddings_final = [[positive_embeddings_final, {"pooled_output": positive_pooled}]] + + negative_embeddings_final, negative_pooled = advanced_encode(clip, negative, negative_token_normalization, negative_weight_interpretation, w_max=1.0, apply_to_pooled='enable') + negative_embeddings_final = [[negative_embeddings_final, {"pooled_output": negative_pooled}]] image = pil2tensor(Image.new('RGB', (1, 1), (0, 0, 0))) pipe = {"vars": {"model": model, @@ -611,11 +608,17 @@ class ttN_TSC_pipeLoader: "lora3_model_strength": lora3_model_strength, "lora3_clip_strength": lora3_clip_strength, "positive": positive, + "positive_l": None, + "positive_g": None, "positive_token_normalization": positive_token_normalization, "positive_weight_interpretation": positive_weight_interpretation, + "positive_balance": None, "negative": negative, + "negative_l": None, + "negative_g": None, "negative_token_normalization": negative_token_normalization, "negative_weight_interpretation": negative_weight_interpretation, + "negative_balance": None, "empty_latent_width": empty_latent_width, "empty_latent_height": empty_latent_height, "batch_size": batch_size, @@ -627,9 +630,9 @@ class ttN_TSC_pipeLoader: return (pipe, model, positive_embeddings_final, negative_embeddings_final, samples, vae, clip, seed) class ttN_TSC_pipeKSampler: - version = '1.0.1' + version = '1.0.2' empty_image = pil2tensor(Image.new('RGBA', (1, 1), (0, 0, 0, 0))) - upscale_methods = ["None", "nearest-exact", "bilinear", "area"] + upscale_methods = ["None", "nearest-exact", "bilinear", "area", "bicubic", "bislerp"] crop_methods = ["disabled", "center"] def __init__(self): @@ -961,9 +964,12 @@ class ttN_TSC_pipeKSampler: clip = clip.clone() clip.clip_layer(plot_image_vars['clip_skip']) - positive, pooled = advanced_encode(clip, plot_image_vars['positive'], plot_image_vars['positive_token_normalization'], plot_image_vars['positive_weight_interpretation'], w_max=1.0) - negative, pooled = advanced_encode(clip, plot_image_vars['negative'], plot_image_vars['negative_token_normalization'], plot_image_vars['negative_weight_interpretation'], w_max=1.0) - + positive, positive_pooled = advanced_encode(clip, plot_image_vars['positive'], plot_image_vars['positive_token_normalization'], plot_image_vars['positive_weight_interpretation'], w_max=1.0, apply_to_pooled="enable") + positive = [[positive, {"pooled_output": positive_pooled}]] + + negative, negative_pooled = advanced_encode(clip, plot_image_vars['negative'], plot_image_vars['negative_token_normalization'], plot_image_vars['negative_weight_interpretation'], w_max=1.0, apply_to_pooled="enable") + negative = [[negative, {"pooled_output": negative_pooled}]] + model = model if model is not None else plot_image_vars["model"] clip = clip if clip is not None else plot_image_vars["clip"] vae = vae if vae is not None else plot_image_vars["vae"] @@ -1195,9 +1201,9 @@ class ttN_TSC_pipeKSampler: return process_hold_state(self, pipe, image_output, preview_prefix, save_prefix, prompt, extra_pnginfo, my_unique_id) class ttN_pipeKSamplerAdvanced: - version = '1.0.2' + version = '1.0.3' empty_image = pil2tensor(Image.new('RGBA', (1, 1), (0, 0, 0, 0))) - upscale_methods = ["None", "nearest-exact", "bilinear", "area"] + upscale_methods = ["None", "nearest-exact", "bilinear", "area", "bicubic", "bislerp"] crop_methods = ["disabled", "center"] def __init__(self): @@ -1916,8 +1922,8 @@ class ttN_imageOUPUT: "result": (image,)} class ttN_modelScale: - version = '1.0.0' - upscale_methods = ["nearest-exact", "bilinear", "area"] + version = '1.0.1' + upscale_methods = ["None", "nearest-exact", "bilinear", "area", "bicubic", "bislerp"] crop_methods = ["disabled", "center"] @classmethod @@ -2021,8 +2027,9 @@ class ttN_modelScale: TTN_VERSIONS = { "tinyterraNodes": ttN_version, - "pipeLoader": ttN_TSC_pipeLoader.version, + "pipeLoader": ttN_TSC_pipeLoader.version, "pipeKSampler": ttN_TSC_pipeKSampler.version, + "pipeKSamplerAdvanced": ttN_pipeKSamplerAdvanced.version, "pipeIN": ttN_pipe_IN.version, "pipeOUT": ttN_pipe_OUT.version, "pipeEDIT": ttN_pipe_EDIT.version, @@ -2043,7 +2050,7 @@ TTN_VERSIONS = { } NODE_CLASS_MAPPINGS = { #ttN/pipe - "ttN pipeLoader": ttN_TSC_pipeLoader, + "ttN pipeLoader": ttN_TSC_pipeLoader, "ttN pipeKSampler": ttN_TSC_pipeKSampler, "ttN pipeKSamplerAdvanced": ttN_pipeKSamplerAdvanced, "ttN xyPlot": ttN_XYPlot,