Add Krea2 variant evidence node
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
import json
|
||||
|
||||
try:
|
||||
from . import krea2_eval_log
|
||||
from . import krea2_pose_variant_catalog
|
||||
from .hardcore_position_config import (
|
||||
build_hardcore_action_filter_json,
|
||||
@@ -12,6 +13,7 @@ try:
|
||||
hardcore_position_key_choices,
|
||||
)
|
||||
except ImportError: # Allows local smoke tests from the repository root.
|
||||
import krea2_eval_log
|
||||
import krea2_pose_variant_catalog
|
||||
from hardcore_position_config import (
|
||||
build_hardcore_action_filter_json,
|
||||
@@ -140,6 +142,59 @@ class SxCPKrea2PoseVariant:
|
||||
)
|
||||
|
||||
|
||||
class SxCPKrea2VariantEvidence:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
keys = krea2_pose_variant_catalog.variant_keys()
|
||||
return {
|
||||
"required": {
|
||||
"variant_key": (keys or ["missing_catalog_variant"], {"default": keys[0] if keys else "missing_catalog_variant"}),
|
||||
"result": (["accepted", "rejected", "inconclusive", "any"], {"default": "accepted"}),
|
||||
},
|
||||
"optional": {
|
||||
"variant_key_in": ("STRING", {"default": ""}),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("STRING", "STRING", "STRING", "STRING", "INT", "STRING")
|
||||
RETURN_NAMES = (
|
||||
"summary",
|
||||
"baseline_image_path",
|
||||
"candidate_image_path",
|
||||
"evidence_json",
|
||||
"seed",
|
||||
"decision",
|
||||
)
|
||||
FUNCTION = "build"
|
||||
CATEGORY = "prompt_builder"
|
||||
|
||||
def build(self, variant_key, result="accepted", variant_key_in=""):
|
||||
key = str(variant_key_in or variant_key or "").strip()
|
||||
result_filter = None if result == "any" else result
|
||||
entries = krea2_eval_log.entries_for_variant(key, result=result_filter)
|
||||
if not entries:
|
||||
empty = {
|
||||
"variant_key": key,
|
||||
"result": result,
|
||||
"summary": "no Krea2 eval evidence found",
|
||||
}
|
||||
return empty["summary"], "", "", json.dumps(empty, ensure_ascii=True, sort_keys=True), -1, ""
|
||||
entry = entries[0]
|
||||
summary = (
|
||||
f"evidence={entry.get('id')}; variant={entry.get('variant_key')}; "
|
||||
f"seed={entry.get('seed')}; result={entry.get('result')}; decision={entry.get('decision')}"
|
||||
)
|
||||
seed = entry.get("seed")
|
||||
return (
|
||||
summary,
|
||||
str(entry.get("baseline_image") or ""),
|
||||
str(entry.get("candidate_image") or ""),
|
||||
json.dumps(entry, ensure_ascii=True, sort_keys=True),
|
||||
int(seed) if isinstance(seed, int) else -1,
|
||||
str(entry.get("decision") or ""),
|
||||
)
|
||||
|
||||
|
||||
class SxCPHardcoreActionFilter:
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
@@ -203,10 +258,12 @@ NODE_CLASS_MAPPINGS = {
|
||||
"SxCPHardcorePositionPool": SxCPHardcorePositionPool,
|
||||
"SxCPHardcoreActionFilter": SxCPHardcoreActionFilter,
|
||||
"SxCPKrea2PoseVariant": SxCPKrea2PoseVariant,
|
||||
"SxCPKrea2VariantEvidence": SxCPKrea2VariantEvidence,
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"SxCPHardcorePositionPool": "SxCP Hardcore Position Pool",
|
||||
"SxCPHardcoreActionFilter": "SxCP Hardcore Action Filter",
|
||||
"SxCPKrea2PoseVariant": "SxCP Krea2 Pose Variant",
|
||||
"SxCPKrea2VariantEvidence": "SxCP Krea2 Variant Evidence",
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user