Skip to content

Commit bfc47d0

Browse files
committed
* A1111: add prompts to metadata only if they change
1 parent b837f38 commit bfc47d0

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

docs/CONFIG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ With this prompt: `__quality__, 1girl, ${head:__eyes__, __hair__, __expression__
4141

4242
The default value defines strings for *Pony* and *Illustrious* models.
4343
* **Apply in img2img**: check if you want to do the processing in img2img processes (*does not apply to the ComfyUI node*).
44-
* **Add original prompts to metadata**: adds to original prompts to the metadata.
44+
* **Add original prompts to metadata**: adds original prompts to the metadata if they have changed (*does not apply to the ComfyUI node*).
4545

4646
### Wildcard settings
4747

scripts/ppp_script.py

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,6 @@ def process(
359359
rpr: list[str] = getattr(p, "all_prompts", None)
360360
rnr: list[str] = getattr(p, "all_negative_prompts", None)
361361
if rpr is not None and rnr is not None:
362-
if add_prompts:
363-
extra_params.update(
364-
{
365-
"PPP original prompts": rpr.copy(),
366-
"PPP original negative prompts": rnr.copy(),
367-
}
368-
)
369362
prompts_list += [
370363
("regular", seed, prompt, negative_prompt)
371364
for seed, prompt, negative_prompt in zip(calculated_seeds, rpr, rnr)
@@ -375,24 +368,12 @@ def process(
375368
rph: list[str] = getattr(p, "all_hr_prompts", None)
376369
rnh: list[str] = getattr(p, "all_hr_negative_prompts", None)
377370
if rph is not None and rnh is not None:
378-
if add_prompts:
379-
extra_params.update(
380-
{
381-
"PPP original HR prompts": rph.copy(),
382-
"PPP original HR negative prompts": rnh.copy(),
383-
}
384-
)
385371
prompts_list += [
386372
("hiresfix", seed, prompt, negative_prompt)
387373
for seed, prompt, negative_prompt in zip(calculated_seeds, rph, rnh)
388374
if (seed, prompt, negative_prompt) not in prompts_list
389375
]
390376

391-
# fill extra generation parameters only if not already present
392-
for k, v in extra_params.items():
393-
if p.extra_generation_params.get(k) is None:
394-
p.extra_generation_params[k] = v
395-
396377
# processes prompts
397378
for i, (prompttype, seed, prompt, negative_prompt) in enumerate(prompts_list):
398379
if self.ppp_debug_level != DEBUG_LEVEL.none:
@@ -407,17 +388,48 @@ def process(
407388

408389
# updates the prompts
409390
if rpr is not None and rnr is not None:
391+
rpr_changes = False
392+
rnr_changes = False
393+
rpr_copy = rpr.copy()
394+
rnr_copy = rnr.copy()
410395
for i, (seed, prompt, negative_prompt) in enumerate(zip(calculated_seeds, rpr, rnr)):
411396
found = self.lru_cache.get((seed, hash(self.wildcards_obj), prompt, negative_prompt))
412397
if found is not None:
398+
if rpr[i].strip() != found[0].strip():
399+
rpr_changes = True
400+
if rnr[i].strip() != found[1].strip():
401+
rnr_changes = True
413402
rpr[i] = found[0]
414403
rnr[i] = found[1]
404+
if add_prompts:
405+
if rpr_changes:
406+
extra_params["PPP original prompts"] = rpr_copy
407+
if rnr_changes:
408+
extra_params["PPP original negative prompts"] = rnr_copy
415409
if rph is not None and rnh is not None:
410+
rph_changes = False
411+
rnh_changes = False
412+
rph_copy = rph.copy()
413+
rnh_copy = rnh.copy()
416414
for i, (seed, prompt, negative_prompt) in enumerate(zip(calculated_seeds, rph, rnh)):
417415
found = self.lru_cache.get((seed, hash(self.wildcards_obj), prompt, negative_prompt))
418416
if found is not None:
417+
if rph[i].strip() != found[0].strip():
418+
rph_changes = True
419+
if rnh[i].strip() != found[1].strip():
420+
rnh_changes = True
419421
rph[i] = found[0]
420422
rnh[i] = found[1]
423+
if add_prompts:
424+
if rph_changes:
425+
extra_params["PPP original HR prompts"] = rph_copy
426+
if rnh_changes:
427+
extra_params["PPP original HR negative prompts"] = rnh_copy
428+
429+
# fill extra generation parameters only if not already present
430+
for k, v in extra_params.items():
431+
if p.extra_generation_params.get(k) is None:
432+
p.extra_generation_params[k] = v
421433

422434
t2 = time.time()
423435
if self.ppp_debug_level != DEBUG_LEVEL.none:
@@ -516,7 +528,7 @@ def new_html_title(title):
516528
key="ppp_gen_addpromptstometadata",
517529
info=shared.OptionInfo(
518530
True,
519-
label="Add original prompts to metadata",
531+
label="Add original prompts to metadata (if they change)",
520532
section=section,
521533
),
522534
)

0 commit comments

Comments
 (0)