diff --git a/comfy/samplers.py b/comfy/samplers.py index 19ebc97d9..15527224e 100644 --- a/comfy/samplers.py +++ b/comfy/samplers.py @@ -7,23 +7,6 @@ from comfy import model_management from .ldm.models.diffusion.ddim import DDIMSampler from .ldm.modules.diffusionmodules.util import make_ddim_timesteps -class CFGDenoiser(torch.nn.Module): - def __init__(self, model): - super().__init__() - self.inner_model = model - - def forward(self, x, sigma, uncond, cond, cond_scale): - if len(uncond[0]) == len(cond[0]) and x.shape[0] * x.shape[2] * x.shape[3] < (96 * 96): #TODO check memory instead - x_in = torch.cat([x] * 2) - sigma_in = torch.cat([sigma] * 2) - cond_in = torch.cat([uncond, cond]) - uncond, cond = self.inner_model(x_in, sigma_in, cond=cond_in).chunk(2) - else: - cond = self.inner_model(x, sigma, cond=cond) - uncond = self.inner_model(x, sigma, cond=uncond) - return uncond + (cond - uncond) * cond_scale - - #The main sampling function shared by all the samplers #Returns predicted noise def sampling_function(model_function, x, timestep, uncond, cond, cond_scale, cond_concat=None, model_options={}): diff --git a/folder_paths.py b/folder_paths.py index 5c2c75b28..8d24e3ed6 100644 --- a/folder_paths.py +++ b/folder_paths.py @@ -70,7 +70,7 @@ def get_directory_by_type(type_name): # determine base_dir rely on annotation if name is 'filename.ext [annotation]' format # otherwise use default_path as base_dir -def get_annotated_filepath(name, default_dir=None): +def touch_annotated_filepath(name): if name.endswith("[output]"): base_dir = get_output_directory() name = name[:-9] @@ -80,24 +80,29 @@ def get_annotated_filepath(name, default_dir=None): elif name.endswith("[temp]"): base_dir = get_temp_directory() name = name[:-7] - elif default_dir is not None: - base_dir = default_dir else: - base_dir = get_input_directory() # fallback path + return name, None + + return name, base_dir + + +def get_annotated_filepath(name, default_dir=None): + name, base_dir = touch_annotated_filepath(name) + + if base_dir is None: + if default_dir is not None: + base_dir = default_dir + else: + base_dir = get_input_directory() # fallback path return os.path.join(base_dir, name) def exists_annotated_filepath(name): - if name.endswith("[output]"): - base_dir = get_output_directory() - name = name[:-9] - elif name.endswith("[temp]"): - base_dir = get_temp_directory() - name = name[:-7] - else: - base_dir = get_input_directory() - name = name[:-8] + name, base_dir = touch_annotated_filepath(name) + + if base_dir is None: + base_dir = get_input_directory() # fallback path filepath = os.path.join(base_dir, name) return os.path.exists(filepath) diff --git a/web/extensions/core/editAttention.js b/web/extensions/core/editAttention.js index bebc80b12..b937bb103 100644 --- a/web/extensions/core/editAttention.js +++ b/web/extensions/core/editAttention.js @@ -89,24 +89,17 @@ app.registerExtension({ end = nearestEnclosure.end; selectedText = inputField.value.substring(start, end); } else { - // Select the current word, find the start and end of the word (first space before and after) - const wordStart = inputField.value.substring(0, start).lastIndexOf(" ") + 1; - const wordEnd = inputField.value.substring(end).indexOf(" "); - // If there is no space after the word, select to the end of the string - if (wordEnd === -1) { - end = inputField.value.length; - } else { - end += wordEnd; + // Select the current word, find the start and end of the word + const delimiters = " .,\\/!?%^*;:{}=-_`~()\r\n\t"; + + while (!delimiters.includes(inputField.value[start - 1]) && start > 0) { + start--; + } + + while (!delimiters.includes(inputField.value[end]) && end < inputField.value.length) { + end++; } - start = wordStart; - // Remove all punctuation at the end and beginning of the word - while (inputField.value[start].match(/[.,\/#!$%\^&\*;:{}=\-_`~()]/)) { - start++; - } - while (inputField.value[end - 1].match(/[.,\/#!$%\^&\*;:{}=\-_`~()]/)) { - end--; - } selectedText = inputField.value.substring(start, end); if (!selectedText) return; } @@ -135,8 +128,13 @@ app.registerExtension({ // Increment the weight const weightDelta = event.key === "ArrowUp" ? delta : -delta; - const updatedText = selectedText.replace(/(.*:)(\d+(\.\d+)?)(.*)/, (match, prefix, weight, _, suffix) => { - return prefix + incrementWeight(weight, weightDelta) + suffix; + const updatedText = selectedText.replace(/\((.*):(\d+(?:\.\d+)?)\)/, (match, text, weight) => { + weight = incrementWeight(weight, weightDelta); + if (weight == 1) { + return text; + } else { + return `(${text}:${weight})`; + } }); inputField.setRangeText(updatedText, start, end, "select"); diff --git a/web/scripts/app.js b/web/scripts/app.js index ed12ccc23..2bde6a162 100644 --- a/web/scripts/app.js +++ b/web/scripts/app.js @@ -141,18 +141,22 @@ export class ComfyApp { { content: "Copy (Clipspace)", callback: (obj) => { - console.log(this); var widgets = null; if(this.widgets) { widgets = this.widgets.map(({ type, name, value }) => ({ type, name, value })); } let img = new Image(); - img.src = this.imgs[0].src; + var imgs = undefined; + if(this.imgs != undefined) { + img.src = this.imgs[0].src; + imgs = [img]; + } + ComfyApp.clipspace = { 'widgets': widgets, - 'imgs': [img], - 'original_imgs': [img], + 'imgs': imgs, + 'original_imgs': imgs, 'images': this.images }; } @@ -161,8 +165,7 @@ export class ComfyApp { content: "Paste (Clipspace)", callback: () => { if(ComfyApp.clipspace != null) { - console.log(ComfyApp.clipspace.widgets); - if(ComfyApp.clipspace.widgets != null) { + if(ComfyApp.clipspace.widgets != null && this.widgets != null) { ComfyApp.clipspace.widgets.forEach(({ type, name, value }) => { const prop = Object.values(this.widgets).find(obj => obj.type === type && obj.name === name); if (prop) { @@ -171,12 +174,27 @@ export class ComfyApp { }); } - if(ComfyApp.clipspace.imgs != undefined && this.imgs != undefined) { - this.imgs = ComfyApp.clipspace.imgs; - this.images = ComfyApp.clipspace.images; + // image paste + if(ComfyApp.clipspace.imgs != undefined && this.imgs != undefined && this.widgets != null) { + var filename = ""; + if(this.images && ComfyApp.clipspace.images) { + this.images = ComfyApp.clipspace.images; + } + + if(ComfyApp.clipspace.images != undefined) { + filename = `${ComfyApp.clipspace.images[0].filename} [${ComfyApp.clipspace.images[0].type}]`; + } + else if(ComfyApp.clipspace.widgets != undefined) { + const index_in_clip = ComfyApp.clipspace.widgets.findIndex(obj => obj.name === 'image'); + if(index_in_clip >= 0) { + filename = `${ComfyApp.clipspace.widgets[index_in_clip].value}`; + } + } + const index = this.widgets.findIndex(obj => obj.name === 'image'); - if(index >= 0) { - let filename = `${this.images[0].filename} [${this.images[0].type}]`; + if(index >= 0 && filename != "" && ComfyApp.clipspace.imgs != undefined) { + this.imgs = ComfyApp.clipspace.imgs; + this.widgets[index].value = filename; if(this.widgets_values != undefined) { this.widgets_values[index] = filename;