Skip to content

Commit 2f89165

Browse files
committed
Avoid reusing loras from prompted confinements
1 parent 2f473a1 commit 2f89165

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

src/BuiltinExtensions/ComfyUIBackend/WorkflowGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ public void DownloadModel(string name, string filePath, string url)
238238
if (confinements is not null && confinements.Count > i)
239239
{
240240
int confinementId = int.Parse(confinements[i]);
241-
if (confinementId != confinement)
241+
if (confinementId >= 0 && confinementId != confinement)
242242
{
243243
continue;
244244
}

src/Text2Image/T2IParamInput.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -378,20 +378,17 @@ static T2IParamInput()
378378
weights.Add(strength.ToString());
379379
context.Input.Set(T2IParamTypes.Loras, loraList);
380380
context.Input.Set(T2IParamTypes.LoraWeights, weights);
381-
if (context.SectionID > 0)
381+
if (confinements is null)
382382
{
383-
if (confinements is null)
383+
confinements = [];
384+
for (int i = 0; i < loraList.Count - 1; i++)
384385
{
385-
confinements = [];
386-
for (int i = 0; i < loraList.Count - 1; i++)
387-
{
388-
confinements.Add("0");
389-
}
386+
confinements.Add("-1");
390387
}
391-
Logs.Verbose($"LoRA {lora} confined to section {context.SectionID}.");
392-
confinements.Add($"{context.SectionID}");
393-
context.Input.Set(T2IParamTypes.LoraSectionConfinement, confinements);
394388
}
389+
Logs.Verbose($"LoRA {lora} confined to section {context.SectionID}.");
390+
confinements.Add($"{context.SectionID}");
391+
context.Input.Set(T2IParamTypes.LoraSectionConfinement, confinements);
395392
return "";
396393
};
397394
PromptTagPostProcessors["segment"] = (data, context) =>

src/wwwroot/js/genpage/main.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,24 @@ function copy_current_image_params() {
8282
if ('original_negativeprompt' in metadata) {
8383
metadata.negativeprompt = metadata.original_negativeprompt;
8484
}
85+
if ('lorasectionconfinement' in metadata && 'loras' in metadata && 'loraweights' in metadata) {
86+
let confinements = metadata.lorasectionconfinement;
87+
let loras = metadata.loras;
88+
let weights = metadata.loraweights;
89+
if (confinements.length == loras.length && loras.length == weights.length) {
90+
let newLoras = [];
91+
let newWeights = [];
92+
for (let i = 0; i < confinements.length; i++) {
93+
if (confinements[i] == -1) {
94+
newLoras.push(loras[i]);
95+
newWeights.push(weights[i]);
96+
}
97+
}
98+
metadata.loras = newLoras;
99+
metadata.loraweights = newWeights;
100+
delete metadata.lorasectionconfinement;
101+
}
102+
}
85103
let exclude = getUserSetting('reuseparamexcludelist').split(',').map(s => cleanParamName(s));
86104
resetParamsToDefault(exclude);
87105
for (let param of gen_param_types) {

0 commit comments

Comments
 (0)