# -*- coding: utf-8 -*- """P.AI Extension: Smart Batch Workflow Presets (Plain Python, MIT License).""" from dataclasses import dataclass from typing import Any EXTENSION_META = { "id": "smart_batch_presets", "name": "Smart Batch Workflow Presets", "version": "1.0.0", "category": "Automation", } @dataclass(frozen=True) class BatchPipelinePreset: id: str title: str steps: tuple[str, ...] description: str BUILTIN_PRESETS: tuple[BatchPipelinePreset, ...] = ( BatchPipelinePreset( id="ecommerce_clean_pack", title="E-Commerce Pack (Remove BG -> Smart Outpaint 1:1 -> Enhance)", steps=("bg_remove", "square_1_1", "enhance"), description="Cuts out the product background, expands to 1:1 canvas, and enhances fine surface detail.", ), BatchPipelinePreset( id="portrait_studio_pack", title="Portrait Studio Pack (Smart Outpaint 4:5 -> Enhance)", steps=("square_1_1", "enhance"), description="Expands short sides to 4:5 portrait ratio and runs faithful photographic restoration.", ), ) def expand_preset_jobs(preset_id: str, input_paths: list[str]) -> list[dict[str, Any]]: """Expand a batch preset into an ordered list of workflow step descriptors for each input image.""" preset = next((p for p in BUILTIN_PRESETS if p.id == preset_id), None) if preset is None: raise KeyError(f"Unknown batch preset: {preset_id}") plan: list[dict[str, Any]] = [] for path in input_paths: for step_idx, wf in enumerate(preset.steps, start=1): plan.append({"input_path": path, "step": step_idx, "workflow": wf, "preset": preset.id}) return plan