"""Shared guidance settings for local Qwen and MOSS image generation.""" import math def guidance_values(data, default=1.0, min_cfg=1, max_cfg=10): """Return the effective negative prompt, CFG and denoising pass count. A supplied negative prompt needs guidance to affect the image. Raise CFG from one (or below) to 1.1 only when that prompt is nonempty. MOSS supports CFG below one too, which still needs its unconditional denoising pass. """ negative = data.get("negative_prompt_text", "") if negative is None: negative = "" if not isinstance(negative, str): raise ValueError("Negative prompt must be text.") negative = negative.strip() value = data.get("guidance_scale", default) if isinstance(value, bool): raise ValueError(f"CFG must be a finite number between {min_cfg} and {max_cfg}.") try: cfg = float(value) except (TypeError, ValueError, OverflowError) as error: raise ValueError(f"CFG must be a finite number between {min_cfg} and {max_cfg}.") from error if not math.isfinite(cfg) or not min_cfg <= cfg <= max_cfg: raise ValueError(f"CFG must be a finite number between {min_cfg} and {max_cfg}.") if negative and cfg <= 1.0: cfg = 1.1 if cfg > max_cfg: raise ValueError("Negative prompts require CFG above 1.") return negative if cfg > 1.0 else None, cfg, 2 if cfg != 1.0 else 1