Files
comfyui_o1key/utils/o1key_image_catalog.py
T
Jony ba920f2b66 Publish current ComfyUI O1Key code baseline
Replace the prior release tree with the current plugin, frontend, tests, and documentation. Document retired node IDs and the public Gitea update source.
2026-09-24 19:56:48 +08:00

230 lines
7.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Shared capability catalog for the unified o1key image generator."""
from __future__ import annotations
from .nano_banana_models import (
NANO_BANANA_MODEL_OPTIONS,
NANO_BANANA_ROUTE_OPTIONS,
)
GPT_IMAGE_MODEL_OPTIONS = [
"gpt-image-2",
"gpt-image-2.5-sunburst",
"gpt-image-2.5-flare",
]
SEEDREAM_MODEL_OPTIONS = ["Seedream 5.0 Pro"]
UNIFIED_IMAGE_MODEL_OPTIONS = [
*NANO_BANANA_MODEL_OPTIONS[:2],
*GPT_IMAGE_MODEL_OPTIONS,
*SEEDREAM_MODEL_OPTIONS,
*NANO_BANANA_MODEL_OPTIONS[2:],
]
UNIFIED_IMAGE_ROUTE_OPTIONS = list(NANO_BANANA_ROUTE_OPTIONS)
UNIFIED_IMAGE_COUNTS = [1, 2, 4, 9]
GPT_IMAGE_COUNTS = list(range(1, 9))
MAX_UNIFIED_REFERENCE_IMAGES = 10
MAX_UNIFIED_BATCH_IMAGES = 50
MAX_UNIFIED_IMAGE_TASKS = 1000
UNIFIED_IMAGE_SMART_RESOLUTION = "智能"
BANANA_RESOLUTION_OPTIONS = ["512", "1K", "2K", "4K"]
BANANA_ASPECT_RATIO_OPTIONS = [
"智能", "1:1", "1:4", "1:8", "2:3", "3:2", "3:4",
"4:1", "4:3", "4:5", "5:4", "8:1", "9:16", "16:9", "21:9",
]
GPT_IMAGE_RESOLUTION_OPTIONS = ["1K", "2K", "4K"]
GPT_IMAGE_ASPECT_RATIO_OPTIONS = [
"智能", "1:1", "3:2", "2:3", "4:3", "3:4", "16:9", "9:16",
]
GPT_IMAGE_EXACT_SIZE_OPTIONS = [
"智能",
"1024x1024(1K 正方形 1:1)",
"1536x1024(1K 横版 3:2)",
"1024x1536(1K 竖版 2:3)",
"1360x1024(1K 横版 4:3)",
"1024x1360(1K 竖版 3:4)",
"1824x1024(1K 横版 16:9)",
"1024x1824(1K 竖版 9:16)",
"2048x2048(2K 正方形 1:1)",
"3072x2048(2K 横版 3:2)",
"2048x3072(2K 竖版 2:3)",
"2736x2048(2K 横版 4:3)",
"2048x2736(2K 竖版 3:4)",
"3648x2048(2K 横版 16:9)",
"2048x3648(2K 竖版 9:16)",
"2880x2880(4K 正方形 1:1)",
"3504x2336(4K 横版 3:2)",
"2336x3504(4K 竖版 2:3)",
"3264x2448(4K 横版 4:3)",
"2448x3264(4K 竖版 3:4)",
"3840x2160(4K 横版 16:9)",
"2160x3840(4K 竖版 9:16)",
]
GPT_IMAGE_QUALITY_OPTIONS = ["高", "中", "低", "自动"]
GPT_IMAGE_25_QUALITY_OPTIONS = [*GPT_IMAGE_QUALITY_OPTIONS, "超高", "最高"]
GPT_IMAGE_OUTPUT_FORMAT_OPTIONS = ["jpeg", "png", "webp"]
GPT_IMAGE_BACKGROUND_OPTIONS = ["auto", "transparent", "opaque"]
GPT_IMAGE_SIZE_MATRIX = {
("1K", "1:1"): "1024x1024",
("1K", "3:2"): "1536x1024",
("1K", "2:3"): "1024x1536",
("1K", "4:3"): "1360x1024",
("1K", "3:4"): "1024x1360",
("1K", "16:9"): "1824x1024",
("1K", "9:16"): "1024x1824",
("2K", "1:1"): "2048x2048",
("2K", "3:2"): "3072x2048",
("2K", "2:3"): "2048x3072",
("2K", "4:3"): "2736x2048",
("2K", "3:4"): "2048x2736",
("2K", "16:9"): "3648x2048",
("2K", "9:16"): "2048x3648",
("4K", "1:1"): "2880x2880",
("4K", "3:2"): "3504x2336",
("4K", "2:3"): "2336x3504",
("4K", "4:3"): "3264x2448",
("4K", "3:4"): "2448x3264",
("4K", "16:9"): "3840x2160",
("4K", "9:16"): "2160x3840",
}
SEEDREAM_RESOLUTION_OPTIONS = ["1K", "2K"]
SEEDREAM_LAYER_RESOLUTION_OPTIONS = ["auto", "1K", "1.5K", "2K"]
SEEDREAM_ASPECT_RATIO_OPTIONS = [
"智能", "1:1", "4:3", "3:4", "16:9", "9:16", "3:2", "2:3", "21:9",
]
SEEDREAM_OUTPUT_FORMAT_OPTIONS = ["png", "jpeg"]
SEEDREAM_SIZE_MATRIX = {
("1K", "1:1"): "1024x1024",
("1K", "4:3"): "1152x864",
("1K", "3:4"): "864x1152",
("1K", "16:9"): "1424x800",
("1K", "9:16"): "800x1424",
("1K", "3:2"): "1248x832",
("1K", "2:3"): "832x1248",
("1K", "21:9"): "1568x672",
("2K", "1:1"): "2048x2048",
("2K", "4:3"): "2368x1776",
("2K", "3:4"): "1776x2368",
("2K", "16:9"): "2816x1584",
("2K", "9:16"): "1584x2816",
("2K", "3:2"): "2496x1664",
("2K", "2:3"): "1664x2496",
("2K", "21:9"): "3136x1344",
}
def is_gpt_image_model(model: str) -> bool:
return model in GPT_IMAGE_MODEL_OPTIONS
def resolve_gpt_image_quality(model_name: str, quality: str) -> str:
"""Resolve a displayed GPT quality for the selected model family."""
if quality in {"超高", "最高"}:
if model_name not in GPT_IMAGE_MODEL_OPTIONS or not model_name.startswith("gpt-image-2.5-"):
raise ValueError("超高和最高质量仅支持 GPT Image 2.5 系列模型")
return {"超高": "xhigh", "最高": "max"}[quality]
try:
return {"高": "high", "中": "medium", "低": "low", "自动": "auto"}[quality]
except KeyError:
raise ValueError("GPT Image 质量参数无效") from None
def is_seedream_model(model: str) -> bool:
return model in SEEDREAM_MODEL_OPTIONS
def resolve_gpt_image_size(value: str, aspect_ratio: str = "智能") -> str:
"""Convert a GPT Image display-size value into the API value."""
value = (value or "").strip()
aspect_ratio = (aspect_ratio or "智能").strip()
normalized_resolution = value.upper()
if normalized_resolution in GPT_IMAGE_RESOLUTION_OPTIONS:
effective_ratio = "1:1" if aspect_ratio == "智能" else aspect_ratio
mapped = GPT_IMAGE_SIZE_MATRIX.get((normalized_resolution, effective_ratio))
if mapped is None:
raise ValueError(
f"GPT Image 不支持分辨率 {value} 与宽高比 {aspect_ratio} 的组合"
)
return mapped
if not value or value == "智能" or value.lower() == "auto":
return "auto"
first_part = value.split("(")[0].strip()
normalized_size = first_part.lower().replace("*", "x").replace("×", "x")
size_parts = [part.strip() for part in normalized_size.split("x")]
if len(size_parts) == 2 and all(part.isdigit() for part in size_parts):
return f"{int(size_parts[0])}x{int(size_parts[1])}"
if first_part in {"auto", "1024x1024", "1K", "2K", "4K"}:
return first_part
if "4K" in value:
return "4K"
if "2K" in value:
return "2K"
if "1K" in value:
return "1K"
return "auto"
def resolve_seedream_size(resolution: str, aspect_ratio: str = "智能") -> str:
"""Resolve Seedream's UI resolution and ratio into its exact size value."""
normalized_resolution = str(resolution or "").strip().upper()
normalized_ratio = str(aspect_ratio or "智能").strip()
if normalized_resolution not in SEEDREAM_RESOLUTION_OPTIONS:
raise ValueError(f"Seedream 分辨率无效:{resolution}")
effective_ratio = "1:1" if normalized_ratio == "智能" else normalized_ratio
mapped = SEEDREAM_SIZE_MATRIX.get((normalized_resolution, effective_ratio))
if mapped is None:
raise ValueError(
f"Seedream 不支持分辨率 {resolution} 与宽高比 {aspect_ratio} 的组合"
)
return mapped
def resolve_seedream_layer_size(resolution: str) -> str:
"""Normalize Seedream's layer-decomposition size without applying a ratio."""
value = str(resolution or "auto").strip()
normalized = "auto" if value.lower() == "auto" else value.upper()
if normalized not in SEEDREAM_LAYER_RESOLUTION_OPTIONS:
raise ValueError(f"Seedream 图层拆分分辨率无效:{resolution}")
return normalized
__all__ = [
"BANANA_ASPECT_RATIO_OPTIONS",
"BANANA_RESOLUTION_OPTIONS",
"GPT_IMAGE_ASPECT_RATIO_OPTIONS",
"GPT_IMAGE_BACKGROUND_OPTIONS",
"GPT_IMAGE_COUNTS",
"GPT_IMAGE_EXACT_SIZE_OPTIONS",
"GPT_IMAGE_MODEL_OPTIONS",
"GPT_IMAGE_25_QUALITY_OPTIONS",
"GPT_IMAGE_OUTPUT_FORMAT_OPTIONS",
"GPT_IMAGE_QUALITY_OPTIONS",
"GPT_IMAGE_RESOLUTION_OPTIONS",
"GPT_IMAGE_SIZE_MATRIX",
"SEEDREAM_ASPECT_RATIO_OPTIONS",
"SEEDREAM_LAYER_RESOLUTION_OPTIONS",
"SEEDREAM_MODEL_OPTIONS",
"SEEDREAM_OUTPUT_FORMAT_OPTIONS",
"SEEDREAM_RESOLUTION_OPTIONS",
"SEEDREAM_SIZE_MATRIX",
"MAX_UNIFIED_BATCH_IMAGES",
"MAX_UNIFIED_IMAGE_TASKS",
"MAX_UNIFIED_REFERENCE_IMAGES",
"UNIFIED_IMAGE_COUNTS",
"UNIFIED_IMAGE_MODEL_OPTIONS",
"UNIFIED_IMAGE_ROUTE_OPTIONS",
"UNIFIED_IMAGE_SMART_RESOLUTION",
"is_gpt_image_model",
"is_seedream_model",
"resolve_gpt_image_size",
"resolve_gpt_image_quality",
"resolve_seedream_size",
"resolve_seedream_layer_size",
]