Files
slahiri-ComfyUI-AI-Photogra…/__init__.py
T
slahiriandClaude Opus 4.5 7f1186d412 feat: add prompt composition pipeline and tokenization spec
New Features:
- SID_PromptCompose node with Standard and Enhance with AI modes
- SID_PromptSynthesis node for VLM-based prompt generation
- SID_ImageAnalysis node for comprehensive image analysis
- Text LLM support (Qwen2.5 0.5B-7B) for prompt enhancement
- PixAI tagger integration

Documentation:
- docs/image_tokenization_spec.md - Full technical specification
  for tokenization → classification → assembly pipeline
- docs/implementation_plan.md - 8-phase implementation roadmap
- docs/SID_PromptCompose.md - Node usage documentation

Infrastructure:
- core/compose/ module with base, pipeline, standard, llm generators
- core/log.py centralized logging
- Config files for Qwen2.5 text models (YAML)
- Web assets for ComfyUI integration

This commit establishes the foundation for rewriting the compose
pipeline based on the tokenization specification.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-27 02:33:17 +05:30

148 lines
4.2 KiB
Python

# -*- coding: utf-8 -*-
"""
SID Photography Toolkit v5.0
AI-powered image captioning for ComfyUI.
Clean, modular architecture with plug-and-play models.
Author: Siddhartha Lahiri
License: MIT
"""
__version__ = "5.0.0"
# Import nodes
from .nodes import (
SID_ZImagePromptGenerator,
SID_TaggerConfig,
SID_ImageAnalysis,
SID_PromptSynthesis,
)
from .nodes.prompt_compose import SID_PromptCompose
# V1 API registration
NODE_CLASS_MAPPINGS = {
"SID_ZImagePromptGenerator": SID_ZImagePromptGenerator,
"SID_TaggerConfig": SID_TaggerConfig,
"SID_ImageAnalysis": SID_ImageAnalysis,
"SID_PromptSynthesis": SID_PromptSynthesis,
"SID_PromptCompose": SID_PromptCompose,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"SID_ZImagePromptGenerator": "SID Z-Image Prompt Generator",
"SID_TaggerConfig": "SID Tagger Config",
"SID_ImageAnalysis": "SID Image Analysis",
"SID_PromptSynthesis": "SID Prompt Synthesis",
"SID_PromptCompose": "SID Prompt Compose",
}
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
# Auto-install dependencies
def _install_dependencies():
"""Auto-install required dependencies at startup."""
import subprocess
import sys
# Required packages: (import_name, pip_package)
required = [
("yaml", "pyyaml"),
("onnxruntime", "onnxruntime-gpu"),
("cv2", "opencv-python"),
("timm", "timm"),
("huggingface_hub", "huggingface_hub"),
]
# Optional packages
optional = [
("nudenet", "nudenet"),
("pyiqa", "pyiqa"),
("ultralytics", "ultralytics"),
("imgutils", "dghs-imgutils>=0.19.0"),
]
def is_installed(module_name):
try:
__import__(module_name)
return True
except ImportError:
return False
def install(package, quiet=True):
print(f"[AI-Photo-Toolkit] Installing {package}...")
try:
cmd = [sys.executable, "-m", "pip", "install", package]
if quiet:
cmd.append("-q")
subprocess.check_call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
else:
# Show output for debugging
subprocess.check_call(cmd)
return True
except subprocess.CalledProcessError as e:
# Try without GPU for onnxruntime
if package == "onnxruntime-gpu":
print(f"[AI-Photo-Toolkit] GPU version failed, trying CPU...")
try:
subprocess.check_call(
[sys.executable, "-m", "pip", "install", "onnxruntime", "-q"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
return True
except subprocess.CalledProcessError:
pass
print(f"[AI-Photo-Toolkit] Failed to install {package}: {e}")
return False
except Exception as e:
print(f"[AI-Photo-Toolkit] Error installing {package}: {e}")
return False
# Install required
for module, package in required:
if not is_installed(module):
install(package)
# Install optional (show output for debugging)
for module, package in optional:
if not is_installed(module):
install(package, quiet=False)
# Startup
def _print_startup():
print(f"\n[AI-Photo-Toolkit] v{__version__} loading...")
# Auto-install missing deps
_install_dependencies()
# Check what's available now
available = []
missing = []
checks = [
("onnxruntime", "WD14, JoyTag"),
("cv2", "Photography, Composition"),
("timm", "Fashion"),
("nudenet", "NudeNet"),
("pyiqa", "IQA"),
("ultralytics", "YOLOv8"),
("imgutils", "PixAI"),
]
for module, taggers in checks:
try:
__import__(module)
available.append(taggers)
except ImportError:
missing.append(taggers)
print(f"[AI-Photo-Toolkit] v{__version__} ready!")
print(f"[AI-Photo-Toolkit] Available: {', '.join(available)}")
if missing:
print(f"[AI-Photo-Toolkit] Unavailable: {', '.join(missing)}")
print()
_print_startup()