mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-10 21:42:37 +08:00
Merge branch 'feature/clipspace' into feature/maskpainting
This commit is contained in:
commit
10f17f97a6
@ -7,23 +7,6 @@ from comfy import model_management
|
|||||||
from .ldm.models.diffusion.ddim import DDIMSampler
|
from .ldm.models.diffusion.ddim import DDIMSampler
|
||||||
from .ldm.modules.diffusionmodules.util import make_ddim_timesteps
|
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
|
#The main sampling function shared by all the samplers
|
||||||
#Returns predicted noise
|
#Returns predicted noise
|
||||||
def sampling_function(model_function, x, timestep, uncond, cond, cond_scale, cond_concat=None, model_options={}):
|
def sampling_function(model_function, x, timestep, uncond, cond, cond_scale, cond_concat=None, model_options={}):
|
||||||
|
|||||||
@ -70,7 +70,7 @@ def get_directory_by_type(type_name):
|
|||||||
|
|
||||||
# determine base_dir rely on annotation if name is 'filename.ext [annotation]' format
|
# determine base_dir rely on annotation if name is 'filename.ext [annotation]' format
|
||||||
# otherwise use default_path as base_dir
|
# otherwise use default_path as base_dir
|
||||||
def get_annotated_filepath(name, default_dir=None):
|
def touch_annotated_filepath(name):
|
||||||
if name.endswith("[output]"):
|
if name.endswith("[output]"):
|
||||||
base_dir = get_output_directory()
|
base_dir = get_output_directory()
|
||||||
name = name[:-9]
|
name = name[:-9]
|
||||||
@ -80,7 +80,17 @@ def get_annotated_filepath(name, default_dir=None):
|
|||||||
elif name.endswith("[temp]"):
|
elif name.endswith("[temp]"):
|
||||||
base_dir = get_temp_directory()
|
base_dir = get_temp_directory()
|
||||||
name = name[:-7]
|
name = name[:-7]
|
||||||
elif default_dir is not None:
|
else:
|
||||||
|
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
|
base_dir = default_dir
|
||||||
else:
|
else:
|
||||||
base_dir = get_input_directory() # fallback path
|
base_dir = get_input_directory() # fallback path
|
||||||
@ -89,15 +99,10 @@ def get_annotated_filepath(name, default_dir=None):
|
|||||||
|
|
||||||
|
|
||||||
def exists_annotated_filepath(name):
|
def exists_annotated_filepath(name):
|
||||||
if name.endswith("[output]"):
|
name, base_dir = touch_annotated_filepath(name)
|
||||||
base_dir = get_output_directory()
|
|
||||||
name = name[:-9]
|
if base_dir is None:
|
||||||
elif name.endswith("[temp]"):
|
base_dir = get_input_directory() # fallback path
|
||||||
base_dir = get_temp_directory()
|
|
||||||
name = name[:-7]
|
|
||||||
else:
|
|
||||||
base_dir = get_input_directory()
|
|
||||||
name = name[:-8]
|
|
||||||
|
|
||||||
filepath = os.path.join(base_dir, name)
|
filepath = os.path.join(base_dir, name)
|
||||||
return os.path.exists(filepath)
|
return os.path.exists(filepath)
|
||||||
|
|||||||
@ -89,24 +89,17 @@ app.registerExtension({
|
|||||||
end = nearestEnclosure.end;
|
end = nearestEnclosure.end;
|
||||||
selectedText = inputField.value.substring(start, end);
|
selectedText = inputField.value.substring(start, end);
|
||||||
} else {
|
} else {
|
||||||
// Select the current word, find the start and end of the word (first space before and after)
|
// Select the current word, find the start and end of the word
|
||||||
const wordStart = inputField.value.substring(0, start).lastIndexOf(" ") + 1;
|
const delimiters = " .,\\/!?%^*;:{}=-_`~()\r\n\t";
|
||||||
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;
|
|
||||||
}
|
|
||||||
start = wordStart;
|
|
||||||
|
|
||||||
// Remove all punctuation at the end and beginning of the word
|
while (!delimiters.includes(inputField.value[start - 1]) && start > 0) {
|
||||||
while (inputField.value[start].match(/[.,\/#!$%\^&\*;:{}=\-_`~()]/)) {
|
start--;
|
||||||
start++;
|
|
||||||
}
|
}
|
||||||
while (inputField.value[end - 1].match(/[.,\/#!$%\^&\*;:{}=\-_`~()]/)) {
|
|
||||||
end--;
|
while (!delimiters.includes(inputField.value[end]) && end < inputField.value.length) {
|
||||||
|
end++;
|
||||||
}
|
}
|
||||||
|
|
||||||
selectedText = inputField.value.substring(start, end);
|
selectedText = inputField.value.substring(start, end);
|
||||||
if (!selectedText) return;
|
if (!selectedText) return;
|
||||||
}
|
}
|
||||||
@ -135,8 +128,13 @@ app.registerExtension({
|
|||||||
|
|
||||||
// Increment the weight
|
// Increment the weight
|
||||||
const weightDelta = event.key === "ArrowUp" ? delta : -delta;
|
const weightDelta = event.key === "ArrowUp" ? delta : -delta;
|
||||||
const updatedText = selectedText.replace(/(.*:)(\d+(\.\d+)?)(.*)/, (match, prefix, weight, _, suffix) => {
|
const updatedText = selectedText.replace(/\((.*):(\d+(?:\.\d+)?)\)/, (match, text, weight) => {
|
||||||
return prefix + incrementWeight(weight, weightDelta) + suffix;
|
weight = incrementWeight(weight, weightDelta);
|
||||||
|
if (weight == 1) {
|
||||||
|
return text;
|
||||||
|
} else {
|
||||||
|
return `(${text}:${weight})`;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
inputField.setRangeText(updatedText, start, end, "select");
|
inputField.setRangeText(updatedText, start, end, "select");
|
||||||
|
|||||||
@ -141,18 +141,22 @@ export class ComfyApp {
|
|||||||
{
|
{
|
||||||
content: "Copy (Clipspace)",
|
content: "Copy (Clipspace)",
|
||||||
callback: (obj) => {
|
callback: (obj) => {
|
||||||
console.log(this);
|
|
||||||
var widgets = null;
|
var widgets = null;
|
||||||
if(this.widgets) {
|
if(this.widgets) {
|
||||||
widgets = this.widgets.map(({ type, name, value }) => ({ type, name, value }));
|
widgets = this.widgets.map(({ type, name, value }) => ({ type, name, value }));
|
||||||
}
|
}
|
||||||
|
|
||||||
let img = new Image();
|
let img = new Image();
|
||||||
|
var imgs = undefined;
|
||||||
|
if(this.imgs != undefined) {
|
||||||
img.src = this.imgs[0].src;
|
img.src = this.imgs[0].src;
|
||||||
|
imgs = [img];
|
||||||
|
}
|
||||||
|
|
||||||
ComfyApp.clipspace = {
|
ComfyApp.clipspace = {
|
||||||
'widgets': widgets,
|
'widgets': widgets,
|
||||||
'imgs': [img],
|
'imgs': imgs,
|
||||||
'original_imgs': [img],
|
'original_imgs': imgs,
|
||||||
'images': this.images
|
'images': this.images
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -161,8 +165,7 @@ export class ComfyApp {
|
|||||||
content: "Paste (Clipspace)",
|
content: "Paste (Clipspace)",
|
||||||
callback: () => {
|
callback: () => {
|
||||||
if(ComfyApp.clipspace != null) {
|
if(ComfyApp.clipspace != null) {
|
||||||
console.log(ComfyApp.clipspace.widgets);
|
if(ComfyApp.clipspace.widgets != null && this.widgets != null) {
|
||||||
if(ComfyApp.clipspace.widgets != null) {
|
|
||||||
ComfyApp.clipspace.widgets.forEach(({ type, name, value }) => {
|
ComfyApp.clipspace.widgets.forEach(({ type, name, value }) => {
|
||||||
const prop = Object.values(this.widgets).find(obj => obj.type === type && obj.name === name);
|
const prop = Object.values(this.widgets).find(obj => obj.type === type && obj.name === name);
|
||||||
if (prop) {
|
if (prop) {
|
||||||
@ -171,12 +174,27 @@ export class ComfyApp {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(ComfyApp.clipspace.imgs != undefined && this.imgs != undefined) {
|
// image paste
|
||||||
this.imgs = ComfyApp.clipspace.imgs;
|
if(ComfyApp.clipspace.imgs != undefined && this.imgs != undefined && this.widgets != null) {
|
||||||
|
var filename = "";
|
||||||
|
if(this.images && ComfyApp.clipspace.images) {
|
||||||
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');
|
const index = this.widgets.findIndex(obj => obj.name === 'image');
|
||||||
if(index >= 0) {
|
if(index >= 0 && filename != "" && ComfyApp.clipspace.imgs != undefined) {
|
||||||
let filename = `${this.images[0].filename} [${this.images[0].type}]`;
|
this.imgs = ComfyApp.clipspace.imgs;
|
||||||
|
|
||||||
this.widgets[index].value = filename;
|
this.widgets[index].value = filename;
|
||||||
if(this.widgets_values != undefined) {
|
if(this.widgets_values != undefined) {
|
||||||
this.widgets_values[index] = filename;
|
this.widgets_values[index] = filename;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user