Spaces:
Running
Running
Upload 3 files
Browse files- core/api_service.py +21 -1
- core/generation_service.py +4 -0
- core/prompt_processor.py +11 -4
core/api_service.py
CHANGED
|
@@ -114,6 +114,7 @@ class GenerationParameters:
|
|
| 114 |
seed: Optional[int] = None
|
| 115 |
model: str = "NAID4.5F"
|
| 116 |
noise_schedule: str = "native"
|
|
|
|
| 117 |
# Character prompts: List of (prompt, negative) tuples
|
| 118 |
character_prompts: List[Tuple[str, str]] = None
|
| 119 |
# Character reference (NAID4.5 feature)
|
|
@@ -225,9 +226,22 @@ class NAIAPIService:
|
|
| 225 |
"use_coords": False,
|
| 226 |
"v4_prompt": v4_prompt,
|
| 227 |
"v4_negative_prompt": v4_negative_prompt,
|
| 228 |
-
"skip_cfg_above_sigma": None,
|
| 229 |
}
|
| 230 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
# Add character reference if provided (NAID4.5 feature)
|
| 232 |
if params.character_reference:
|
| 233 |
ref = params.character_reference
|
|
@@ -252,6 +266,12 @@ class NAIAPIService:
|
|
| 252 |
api_parameters["inpaintImg2ImgStrength"] = 1
|
| 253 |
api_parameters["normalize_reference_strength_multiple"] = True
|
| 254 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
print(f"NAIA-WEB: Character reference enabled (style_aware={ref.style_aware}, fidelity={ref.fidelity})")
|
| 256 |
|
| 257 |
# Build request payload
|
|
|
|
| 114 |
seed: Optional[int] = None
|
| 115 |
model: str = "NAID4.5F"
|
| 116 |
noise_schedule: str = "native"
|
| 117 |
+
variety_plus: bool = False # VAR+ option (skip_cfg_above_sigma)
|
| 118 |
# Character prompts: List of (prompt, negative) tuples
|
| 119 |
character_prompts: List[Tuple[str, str]] = None
|
| 120 |
# Character reference (NAID4.5 feature)
|
|
|
|
| 226 |
"use_coords": False,
|
| 227 |
"v4_prompt": v4_prompt,
|
| 228 |
"v4_negative_prompt": v4_negative_prompt,
|
|
|
|
| 229 |
}
|
| 230 |
|
| 231 |
+
# VAR+ (skip_cfg_above_sigma) handling
|
| 232 |
+
# Reference: NAIA2.0/core/api_service.py:307-321
|
| 233 |
+
if params.variety_plus:
|
| 234 |
+
# NAID4.5: 58, NAID4.0/NAID3: 19
|
| 235 |
+
if model_name in ['nai-diffusion-4-5-curated']:
|
| 236 |
+
api_parameters["skip_cfg_above_sigma"] = 58
|
| 237 |
+
elif model_name == 'nai-diffusion-4-5-full':
|
| 238 |
+
api_parameters["skip_cfg_above_sigma"] = 58.93178654671047
|
| 239 |
+
else:
|
| 240 |
+
api_parameters["skip_cfg_above_sigma"] = 19
|
| 241 |
+
print(f"NAIA-WEB: VAR+ enabled (skip_cfg_above_sigma={api_parameters['skip_cfg_above_sigma']})")
|
| 242 |
+
else:
|
| 243 |
+
api_parameters["skip_cfg_above_sigma"] = None
|
| 244 |
+
|
| 245 |
# Add character reference if provided (NAID4.5 feature)
|
| 246 |
if params.character_reference:
|
| 247 |
ref = params.character_reference
|
|
|
|
| 266 |
api_parameters["inpaintImg2ImgStrength"] = 1
|
| 267 |
api_parameters["normalize_reference_strength_multiple"] = True
|
| 268 |
|
| 269 |
+
# Character Reference 활성화 시 skip_cfg_above_sigma 제거
|
| 270 |
+
# Reference: NAIA2.0/core/api_service.py:533-536
|
| 271 |
+
if 'skip_cfg_above_sigma' in api_parameters:
|
| 272 |
+
del api_parameters['skip_cfg_above_sigma']
|
| 273 |
+
print("NAIA-WEB: skip_cfg_above_sigma removed (Character Reference enabled)")
|
| 274 |
+
|
| 275 |
print(f"NAIA-WEB: Character reference enabled (style_aware={ref.style_aware}, fidelity={ref.fidelity})")
|
| 276 |
|
| 277 |
# Build request payload
|
core/generation_service.py
CHANGED
|
@@ -30,6 +30,8 @@ class GenerationRequest:
|
|
| 30 |
scale: float = 5.0
|
| 31 |
cfg_rescale: float = 0.4 # NAIA2.0 default
|
| 32 |
sampler: str = "k_euler"
|
|
|
|
|
|
|
| 33 |
seed: Optional[int] = None
|
| 34 |
|
| 35 |
# Prompt processing options
|
|
@@ -126,6 +128,8 @@ class GenerationService:
|
|
| 126 |
sampler=request.sampler,
|
| 127 |
seed=request.seed,
|
| 128 |
model=request.model,
|
|
|
|
|
|
|
| 129 |
character_prompts=request.character_prompts if request.character_prompts else None,
|
| 130 |
character_reference=request.character_reference,
|
| 131 |
)
|
|
|
|
| 30 |
scale: float = 5.0
|
| 31 |
cfg_rescale: float = 0.4 # NAIA2.0 default
|
| 32 |
sampler: str = "k_euler"
|
| 33 |
+
noise_schedule: str = "karras" # Noise schedule (karras, native, exponential, polyexponential)
|
| 34 |
+
variety_plus: bool = False # VAR+ option
|
| 35 |
seed: Optional[int] = None
|
| 36 |
|
| 37 |
# Prompt processing options
|
|
|
|
| 128 |
sampler=request.sampler,
|
| 129 |
seed=request.seed,
|
| 130 |
model=request.model,
|
| 131 |
+
noise_schedule=request.noise_schedule,
|
| 132 |
+
variety_plus=request.variety_plus,
|
| 133 |
character_prompts=request.character_prompts if request.character_prompts else None,
|
| 134 |
character_reference=request.character_reference,
|
| 135 |
)
|
core/prompt_processor.py
CHANGED
|
@@ -152,7 +152,7 @@ class PromptProcessor:
|
|
| 152 |
if the user's post_prompt does NOT contain "quality".
|
| 153 |
This allows users to customize quality tags via post_prompt.
|
| 154 |
|
| 155 |
-
Negative quality tags are
|
| 156 |
"""
|
| 157 |
# Check if post_prompt contains "quality" (case-insensitive)
|
| 158 |
has_quality_in_post = "quality" in context.post_prompt.lower()
|
|
@@ -167,13 +167,20 @@ class PromptProcessor:
|
|
| 167 |
else:
|
| 168 |
context.processing_log.append("Skipped positive quality tags (post_prompt has 'quality')")
|
| 169 |
|
| 170 |
-
# Append quality tags to negative prompt (
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
context.negative_prompt = f"{context.negative_prompt}, {QUALITY_TAGS_NEGATIVE}"
|
|
|
|
| 173 |
else:
|
| 174 |
context.negative_prompt = QUALITY_TAGS_NEGATIVE
|
|
|
|
| 175 |
|
| 176 |
-
context.processing_log.append("Injected negative quality tags")
|
| 177 |
return context
|
| 178 |
|
| 179 |
def _remove_auto_hide_tags(self, context: PromptContext) -> PromptContext:
|
|
|
|
| 152 |
if the user's post_prompt does NOT contain "quality".
|
| 153 |
This allows users to customize quality tags via post_prompt.
|
| 154 |
|
| 155 |
+
Negative quality tags are appended only if not already present.
|
| 156 |
"""
|
| 157 |
# Check if post_prompt contains "quality" (case-insensitive)
|
| 158 |
has_quality_in_post = "quality" in context.post_prompt.lower()
|
|
|
|
| 167 |
else:
|
| 168 |
context.processing_log.append("Skipped positive quality tags (post_prompt has 'quality')")
|
| 169 |
|
| 170 |
+
# Append quality tags to negative prompt (only if not already present)
|
| 171 |
+
# Check for signature pattern "lowres, {bad}" to detect existing quality tags
|
| 172 |
+
negative_lower = context.negative_prompt.lower() if context.negative_prompt else ""
|
| 173 |
+
has_quality_tags = "lowres, {bad}" in negative_lower
|
| 174 |
+
|
| 175 |
+
if has_quality_tags:
|
| 176 |
+
context.processing_log.append("Skipped negative quality tags (already present)")
|
| 177 |
+
elif context.negative_prompt:
|
| 178 |
context.negative_prompt = f"{context.negative_prompt}, {QUALITY_TAGS_NEGATIVE}"
|
| 179 |
+
context.processing_log.append("Injected negative quality tags")
|
| 180 |
else:
|
| 181 |
context.negative_prompt = QUALITY_TAGS_NEGATIVE
|
| 182 |
+
context.processing_log.append("Injected negative quality tags")
|
| 183 |
|
|
|
|
| 184 |
return context
|
| 185 |
|
| 186 |
def _remove_auto_hide_tags(self, context: PromptContext) -> PromptContext:
|