Use metadata for scene camera profiles
This commit is contained in:
@@ -112,6 +112,12 @@ SCENE_CAMERA_PROFILES: tuple[dict[str, Any], ...] = (
|
||||
},
|
||||
)
|
||||
|
||||
SCENE_CAMERA_PROFILE_KEYS = {str(profile["key"]): dict(profile) for profile in SCENE_CAMERA_PROFILES}
|
||||
|
||||
THEME_PROFILE_KEYS = {
|
||||
"classical_library": "classical_library",
|
||||
}
|
||||
|
||||
MISMATCHED_COMPOSITION_TERMS = (
|
||||
"outfit-check",
|
||||
"outfit check",
|
||||
@@ -123,8 +129,63 @@ MISMATCHED_COMPOSITION_TERMS = (
|
||||
)
|
||||
|
||||
|
||||
def scene_camera_profile(scene_text: Any) -> dict[str, Any]:
|
||||
text = str(scene_text or "").lower()
|
||||
def _profile_by_key(value: Any) -> dict[str, Any]:
|
||||
key = str(value or "").strip()
|
||||
if not key:
|
||||
return {}
|
||||
if key in SCENE_CAMERA_PROFILE_KEYS:
|
||||
return dict(SCENE_CAMERA_PROFILE_KEYS[key])
|
||||
mapped_key = THEME_PROFILE_KEYS.get(key)
|
||||
if mapped_key and mapped_key in SCENE_CAMERA_PROFILE_KEYS:
|
||||
return dict(SCENE_CAMERA_PROFILE_KEYS[mapped_key])
|
||||
return {}
|
||||
|
||||
|
||||
def _scene_entry_text(scene_entry: Any) -> str:
|
||||
if not isinstance(scene_entry, dict):
|
||||
return ""
|
||||
return str(
|
||||
scene_entry.get("prompt")
|
||||
or scene_entry.get("description")
|
||||
or scene_entry.get("text")
|
||||
or scene_entry.get("name")
|
||||
or ""
|
||||
).strip()
|
||||
|
||||
|
||||
def _scene_entry_profile_key(scene_entry: Any) -> str:
|
||||
if not isinstance(scene_entry, dict):
|
||||
return ""
|
||||
return str(
|
||||
scene_entry.get("scene_camera_profile_key")
|
||||
or scene_entry.get("camera_profile_key")
|
||||
or scene_entry.get("camera_profile")
|
||||
or scene_entry.get("profile")
|
||||
or ""
|
||||
).strip()
|
||||
|
||||
|
||||
def scene_camera_profile(
|
||||
scene_text: Any = "",
|
||||
*,
|
||||
scene_entry: Any = None,
|
||||
theme: Any = "",
|
||||
profile_key: Any = "",
|
||||
) -> dict[str, Any]:
|
||||
explicit_profile = _profile_by_key(profile_key)
|
||||
if explicit_profile:
|
||||
return explicit_profile
|
||||
entry_profile = _profile_by_key(_scene_entry_profile_key(scene_entry))
|
||||
if entry_profile:
|
||||
return entry_profile
|
||||
theme_profile = _profile_by_key(theme)
|
||||
if theme_profile:
|
||||
return theme_profile
|
||||
if isinstance(scene_entry, dict):
|
||||
entry_theme_profile = _profile_by_key(scene_entry.get("theme"))
|
||||
if entry_theme_profile:
|
||||
return entry_theme_profile
|
||||
text = " ".join(part for part in (str(scene_text or ""), _scene_entry_text(scene_entry)) if part).lower()
|
||||
if not text:
|
||||
return {}
|
||||
for profile in SCENE_CAMERA_PROFILES:
|
||||
@@ -323,8 +384,12 @@ def scene_camera_directive(
|
||||
pov_labels: list[str] | None = None,
|
||||
subject_kind: str = "subjects",
|
||||
compact_labels: Mapping[str, str] | None = None,
|
||||
*,
|
||||
scene_entry: Any = None,
|
||||
theme: Any = "",
|
||||
profile_key: Any = "",
|
||||
) -> str:
|
||||
profile = scene_camera_profile(scene_text)
|
||||
profile = scene_camera_profile(scene_text, scene_entry=scene_entry, theme=theme, profile_key=profile_key)
|
||||
if not profile:
|
||||
return ""
|
||||
direction = str(parsed.get("orbit_direction") or "").strip()
|
||||
@@ -378,11 +443,19 @@ def profile_composition_text(profile: dict[str, Any], subject_kind: str) -> str:
|
||||
return text
|
||||
|
||||
|
||||
def contextual_composition_prompt(scene_text: Any, composition: Any, subject_kind: str = "subjects") -> str:
|
||||
def contextual_composition_prompt(
|
||||
scene_text: Any,
|
||||
composition: Any,
|
||||
subject_kind: str = "subjects",
|
||||
*,
|
||||
scene_entry: Any = None,
|
||||
theme: Any = "",
|
||||
profile_key: Any = "",
|
||||
) -> str:
|
||||
text = str(composition or "").strip()
|
||||
if not text:
|
||||
return text
|
||||
profile = scene_camera_profile(scene_text)
|
||||
profile = scene_camera_profile(scene_text, scene_entry=scene_entry, theme=theme, profile_key=profile_key)
|
||||
if not profile:
|
||||
return text
|
||||
lower = text.lower()
|
||||
@@ -410,6 +483,10 @@ def camera_scene_directive_for_context(
|
||||
pov_labels: list[str] | None = None,
|
||||
subject_kind: str = "subjects",
|
||||
compact_labels: Mapping[str, str] | None = None,
|
||||
*,
|
||||
scene_entry: Any = None,
|
||||
theme: Any = "",
|
||||
profile_key: Any = "",
|
||||
) -> str:
|
||||
if (
|
||||
parsed_camera_config.get("camera_detail") == "off"
|
||||
@@ -422,4 +499,7 @@ def camera_scene_directive_for_context(
|
||||
pov_labels,
|
||||
subject_kind,
|
||||
compact_labels,
|
||||
scene_entry=scene_entry,
|
||||
theme=theme,
|
||||
profile_key=profile_key,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user