daily
This commit is contained in:
@@ -1,13 +1,17 @@
|
||||
"""Сборка Anima-промптов без LLM (теги, без POV/hybrid)."""
|
||||
"""Сборка Anima-промптов: appearance из карточки + action/outfit из контекста."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
|
||||
ANIMA_QUALITY = "masterpiece, best quality, score_7, anime"
|
||||
ANIMA_NEGATIVE = "worst quality, low quality, score_1, score_2, score_3, blurry, jpeg artifacts, sepia"
|
||||
|
||||
_INVALID_TAGS = frozenset({
|
||||
"pumped_up", "pumped", "looking_at_each_other", "couple",
|
||||
"2girls", "2boys", "multiple_girls", "multiple_boys",
|
||||
})
|
||||
|
||||
_JUNK_STANDALONE_TAGS = frozenset({
|
||||
"white", "black", "skin", "ear", "ears", "girl", "boy", "fox", "wolf", "cat",
|
||||
"short", "tall", "golden", "silver", "red", "blue", "green", "purple",
|
||||
@@ -33,6 +37,8 @@ def _sanitize_tags(tag_str: str) -> str:
|
||||
key = t.lower().replace(" ", "_")
|
||||
if key in seen or len(key) <= 2:
|
||||
continue
|
||||
if key in _INVALID_TAGS:
|
||||
continue
|
||||
if "_" not in key and key in _JUNK_STANDALONE_TAGS:
|
||||
continue
|
||||
seen.add(key)
|
||||
@@ -48,20 +54,26 @@ def _append_lora(parts: list[str], lora_name: str, lora_weight: float) -> None:
|
||||
parts.append(f"<lora:{lora}:{weight}>")
|
||||
|
||||
|
||||
def build_draw_self_prompt(
|
||||
def build_character_image_prompt(
|
||||
appearance_tags: str,
|
||||
*,
|
||||
action_tags: str = "",
|
||||
outfit_tags: str = "",
|
||||
environment_tags: str = "",
|
||||
lora_name: str = "",
|
||||
lora_weight: float = 0.8,
|
||||
) -> AnimaPromptBundle:
|
||||
"""Портрет «нарисуй себя» — только booru-теги, без POV и prose."""
|
||||
"""Appearance (карточка) + action/outfit/env (контекст), только теги."""
|
||||
appearance = _sanitize_tags(appearance_tags)
|
||||
action = "looking_at_viewer, smile, upper_body, portrait"
|
||||
environment = "simple_background, soft_lighting"
|
||||
outfit = _sanitize_tags(outfit_tags)
|
||||
action = _sanitize_tags(action_tags) or "looking_at_viewer, smile"
|
||||
environment = _sanitize_tags(environment_tags) or "simple_background, soft_lighting"
|
||||
|
||||
parts = [ANIMA_QUALITY]
|
||||
if appearance:
|
||||
parts.append(appearance)
|
||||
if outfit:
|
||||
parts.append(outfit)
|
||||
parts.append(action)
|
||||
parts.append(environment)
|
||||
_append_lora(parts, lora_name, lora_weight)
|
||||
@@ -70,6 +82,25 @@ def build_draw_self_prompt(
|
||||
return AnimaPromptBundle(positive=positive, negative=ANIMA_NEGATIVE)
|
||||
|
||||
|
||||
def build_draw_self_prompt(
|
||||
appearance_tags: str,
|
||||
*,
|
||||
action_tags: str = "",
|
||||
outfit_tags: str = "",
|
||||
environment_tags: str = "",
|
||||
lora_name: str = "",
|
||||
lora_weight: float = 0.8,
|
||||
) -> AnimaPromptBundle:
|
||||
return build_character_image_prompt(
|
||||
appearance_tags,
|
||||
action_tags=action_tags,
|
||||
outfit_tags=outfit_tags,
|
||||
environment_tags=environment_tags,
|
||||
lora_name=lora_name,
|
||||
lora_weight=lora_weight,
|
||||
)
|
||||
|
||||
|
||||
def build_scene_tags_prompt(
|
||||
scene_tags: str,
|
||||
appearance_tags: str,
|
||||
@@ -77,24 +108,13 @@ def build_scene_tags_prompt(
|
||||
lora_name: str = "",
|
||||
lora_weight: float = 0.8,
|
||||
) -> AnimaPromptBundle:
|
||||
"""Прямая сцена из booru-тегов (без LLM)."""
|
||||
appearance = _sanitize_tags(appearance_tags)
|
||||
"""Готовые booru-теги сцены + appearance."""
|
||||
scene = _sanitize_tags(scene_tags)
|
||||
parts = [ANIMA_QUALITY]
|
||||
if appearance:
|
||||
parts.append(appearance)
|
||||
if scene:
|
||||
parts.append(scene)
|
||||
_append_lora(parts, lora_name, lora_weight)
|
||||
positive = ", ".join(p.strip() for p in parts if p.strip())
|
||||
return AnimaPromptBundle(positive=positive, negative=ANIMA_NEGATIVE)
|
||||
|
||||
|
||||
def looks_like_booru_tags(text: str) -> bool:
|
||||
"""Грубая эвристика: строка похожа на теги, а не на прозу."""
|
||||
raw = (text or "").strip()
|
||||
if not raw or len(raw) > 400:
|
||||
return False
|
||||
if raw.count(",") >= 2:
|
||||
return True
|
||||
return bool(re.search(r"\b\d+(girl|boy)s?\b", raw, re.I))
|
||||
return build_character_image_prompt(
|
||||
appearance_tags,
|
||||
action_tags=scene,
|
||||
outfit_tags="",
|
||||
environment_tags="simple_background, soft_lighting",
|
||||
lora_name=lora_name,
|
||||
lora_weight=lora_weight,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user