_shared gains default_model()/default_lora() (env overrides KREA2_TEST_MODEL/KREA2_TEST_LORA, else <repo>/../Models discovery with clear errors) and fox_source()/ref_uint8() for the reference source image boilerplate repeated across scripts. test_img2img/test_edit/ test_edit_grounded no longer hardcode machine paths; all tools compile and resolve on a fresh checkout. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
33 lines
1.4 KiB
Python
33 lines
1.4 KiB
Python
"""End-to-end: txt2img parity guard + grounded vs plain-text edit (identity LoRA)."""
|
|
|
|
import numpy as np
|
|
from PIL import Image
|
|
|
|
from _shared import PROMPT_SHORT, default_lora, default_model, fox_source, load_pipeline, ref_uint8
|
|
|
|
pipe, _ = load_pipeline(default_model())
|
|
LORA = default_lora()
|
|
|
|
# 1) parity: the grounded additions must not disturb txt2img
|
|
t2i = pipe.generate(PROMPT_SHORT, width=512, height=512, steps=8, seed=0)[0]
|
|
print(f"[guard] txt2img pixel-identical to reference: "
|
|
f"{np.array_equal(np.array(t2i), ref_uint8())}")
|
|
|
|
src = fox_source()
|
|
|
|
# 2) grounded vs plain edit, identity LoRA, same seed
|
|
pipe.set_loras([(LORA, 1.0)])
|
|
plain = pipe.generate_edit("the fox wearing a red scarf", src, grounding_px=0,
|
|
width=512, height=512, steps=8, seed=0)[0]
|
|
grounded = pipe.generate_edit("the fox wearing a red scarf", src, grounding_px=384,
|
|
width=512, height=512, steps=8, seed=0)[0]
|
|
pipe.set_loras([])
|
|
plain.save("reference/edit_plain.png")
|
|
grounded.save("reference/edit_grounded.png")
|
|
sheet = [np.asarray(src.resize((384, 384))),
|
|
np.asarray(plain.resize((384, 384))),
|
|
np.asarray(grounded.resize((384, 384)))]
|
|
Image.fromarray(np.concatenate(sheet, axis=1)).save("reference/edit_grounded_sheet.png")
|
|
print("wrote reference/edit_grounded_sheet.png (source | plain | grounded)")
|
|
print("grounded edit ran end-to-end OK")
|