Add MCP tool examples
Browse files- core/pipelines/sd_image_pipeline.py +0 -7
- core/pipelines/workflow_recipes/_partials/conditioning/sd15.yaml +6 -12
- mcp_tools/common.py +113 -1
- mcp_tools/get_feature_list.py +85 -0
- mcp_tools/get_model_features.py +22 -0
- mcp_tools/mcp_gradio_integration.py +33 -7
- mcp_tools/run.py +64 -1
- ui/events/change_handlers.py +2 -6
- ui/events/main.py +2 -5
- ui/events/run_handlers.py +0 -2
- ui/shared/hires_fix_ui.py +0 -1
- ui/shared/img2img_ui.py +0 -1
- ui/shared/inpaint_ui.py +0 -1
- ui/shared/outpaint_ui.py +0 -1
- ui/shared/ui_components.py +0 -1
- yaml/chain_features.yaml +4 -4
core/pipelines/sd_image_pipeline.py
CHANGED
|
@@ -48,7 +48,6 @@ class SdImagePipeline(BasePipeline):
|
|
| 48 |
params_string = f"{ui_inputs['positive_prompt']}\nNegative prompt: {ui_inputs['negative_prompt']}\n"
|
| 49 |
params_string += f"Steps: {ui_inputs['num_inference_steps']}, Sampler: {ui_inputs['sampler']}, Scheduler: {ui_inputs['scheduler']}, CFG scale: {ui_inputs['guidance_scale']}, Seed: {current_seed}, Size: {width_for_meta}x{height_for_meta}, Base Model: {model_display_name}"
|
| 50 |
if ui_inputs['task_type'] != 'txt2img': params_string += f", Denoise: {ui_inputs['denoise']}"
|
| 51 |
-
if ui_inputs.get('clip_skip') and ui_inputs['clip_skip'] != 1: params_string += f", Clip skip: {abs(ui_inputs['clip_skip'])}"
|
| 52 |
if loras_string: params_string += f", {loras_string}"
|
| 53 |
|
| 54 |
pil_image.info = {'parameters': params_string.strip()}
|
|
@@ -68,11 +67,6 @@ class SdImagePipeline(BasePipeline):
|
|
| 68 |
|
| 69 |
ui_inputs['positive_prompt'] = sanitize_prompt(ui_inputs.get('positive_prompt', ''))
|
| 70 |
ui_inputs['negative_prompt'] = sanitize_prompt(ui_inputs.get('negative_prompt', ''))
|
| 71 |
-
|
| 72 |
-
if 'clip_skip' in ui_inputs and ui_inputs['clip_skip'] is not None:
|
| 73 |
-
ui_inputs['clip_skip'] = -int(ui_inputs['clip_skip'])
|
| 74 |
-
else:
|
| 75 |
-
ui_inputs['clip_skip'] = -1
|
| 76 |
|
| 77 |
required_models = self.get_required_models(model_display_name=model_display_name)
|
| 78 |
|
|
@@ -164,7 +158,6 @@ class SdImagePipeline(BasePipeline):
|
|
| 164 |
"seed": ui_inputs['seed'], "steps": ui_inputs['num_inference_steps'], "cfg": ui_inputs['guidance_scale'],
|
| 165 |
"sampler_name": ui_inputs['sampler'], "scheduler": ui_inputs['scheduler'],
|
| 166 |
"batch_size": ui_inputs['batch_size'],
|
| 167 |
-
"clip_skip": ui_inputs['clip_skip'],
|
| 168 |
"denoise": ui_inputs['denoise'],
|
| 169 |
"vae_name": ui_inputs.get('vae_name'),
|
| 170 |
"guidance": ui_inputs.get('guidance', 3.5),
|
|
|
|
| 48 |
params_string = f"{ui_inputs['positive_prompt']}\nNegative prompt: {ui_inputs['negative_prompt']}\n"
|
| 49 |
params_string += f"Steps: {ui_inputs['num_inference_steps']}, Sampler: {ui_inputs['sampler']}, Scheduler: {ui_inputs['scheduler']}, CFG scale: {ui_inputs['guidance_scale']}, Seed: {current_seed}, Size: {width_for_meta}x{height_for_meta}, Base Model: {model_display_name}"
|
| 50 |
if ui_inputs['task_type'] != 'txt2img': params_string += f", Denoise: {ui_inputs['denoise']}"
|
|
|
|
| 51 |
if loras_string: params_string += f", {loras_string}"
|
| 52 |
|
| 53 |
pil_image.info = {'parameters': params_string.strip()}
|
|
|
|
| 67 |
|
| 68 |
ui_inputs['positive_prompt'] = sanitize_prompt(ui_inputs.get('positive_prompt', ''))
|
| 69 |
ui_inputs['negative_prompt'] = sanitize_prompt(ui_inputs.get('negative_prompt', ''))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
required_models = self.get_required_models(model_display_name=model_display_name)
|
| 72 |
|
|
|
|
| 158 |
"seed": ui_inputs['seed'], "steps": ui_inputs['num_inference_steps'], "cfg": ui_inputs['guidance_scale'],
|
| 159 |
"sampler_name": ui_inputs['sampler'], "scheduler": ui_inputs['scheduler'],
|
| 160 |
"batch_size": ui_inputs['batch_size'],
|
|
|
|
| 161 |
"denoise": ui_inputs['denoise'],
|
| 162 |
"vae_name": ui_inputs.get('vae_name'),
|
| 163 |
"guidance": ui_inputs.get('guidance', 3.5),
|
core/pipelines/workflow_recipes/_partials/conditioning/sd15.yaml
CHANGED
|
@@ -8,18 +8,13 @@ nodes:
|
|
| 8 |
ckpt_loader:
|
| 9 |
class_type: CheckpointLoaderSimple
|
| 10 |
title: "Load Checkpoint"
|
| 11 |
-
clip_set_last_layer:
|
| 12 |
-
class_type: CLIPSetLastLayer
|
| 13 |
-
title: "CLIP Set Last Layer"
|
| 14 |
|
| 15 |
connections:
|
| 16 |
- from: "ckpt_loader:0"
|
| 17 |
to: "ksampler:model"
|
| 18 |
- from: "ckpt_loader:1"
|
| 19 |
-
to: "clip_set_last_layer:clip"
|
| 20 |
-
- from: "clip_set_last_layer:0"
|
| 21 |
to: "pos_prompt:clip"
|
| 22 |
-
- from: "
|
| 23 |
to: "neg_prompt:clip"
|
| 24 |
- from: "pos_prompt:0"
|
| 25 |
to: "ksampler:positive"
|
|
@@ -39,10 +34,10 @@ dynamic_vae_chains:
|
|
| 39 |
dynamic_lora_chains:
|
| 40 |
lora_chain:
|
| 41 |
template: "LoraLoader"
|
| 42 |
-
start: "
|
| 43 |
output_map:
|
| 44 |
-
"
|
| 45 |
-
"
|
| 46 |
input_map:
|
| 47 |
"model": "model"
|
| 48 |
"clip": "clip"
|
|
@@ -68,10 +63,9 @@ dynamic_ipadapter_chains:
|
|
| 68 |
dynamic_conditioning_chains:
|
| 69 |
conditioning_chain:
|
| 70 |
ksampler_node: "ksampler"
|
| 71 |
-
clip_source: "
|
| 72 |
|
| 73 |
ui_map:
|
| 74 |
positive_prompt: "pos_prompt:text"
|
| 75 |
negative_prompt: "neg_prompt:text"
|
| 76 |
-
model_name: "ckpt_loader:ckpt_name"
|
| 77 |
-
clip_skip: "clip_set_last_layer:stop_at_clip_layer"
|
|
|
|
| 8 |
ckpt_loader:
|
| 9 |
class_type: CheckpointLoaderSimple
|
| 10 |
title: "Load Checkpoint"
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
connections:
|
| 13 |
- from: "ckpt_loader:0"
|
| 14 |
to: "ksampler:model"
|
| 15 |
- from: "ckpt_loader:1"
|
|
|
|
|
|
|
| 16 |
to: "pos_prompt:clip"
|
| 17 |
+
- from: "ckpt_loader:1"
|
| 18 |
to: "neg_prompt:clip"
|
| 19 |
- from: "pos_prompt:0"
|
| 20 |
to: "ksampler:positive"
|
|
|
|
| 34 |
dynamic_lora_chains:
|
| 35 |
lora_chain:
|
| 36 |
template: "LoraLoader"
|
| 37 |
+
start: "ckpt_loader"
|
| 38 |
output_map:
|
| 39 |
+
"0": "model"
|
| 40 |
+
"1": "clip"
|
| 41 |
input_map:
|
| 42 |
"model": "model"
|
| 43 |
"clip": "clip"
|
|
|
|
| 63 |
dynamic_conditioning_chains:
|
| 64 |
conditioning_chain:
|
| 65 |
ksampler_node: "ksampler"
|
| 66 |
+
clip_source: "ckpt_loader:1"
|
| 67 |
|
| 68 |
ui_map:
|
| 69 |
positive_prompt: "pos_prompt:text"
|
| 70 |
negative_prompt: "neg_prompt:text"
|
| 71 |
+
model_name: "ckpt_loader:ckpt_name"
|
|
|
mcp_tools/common.py
CHANGED
|
@@ -145,9 +145,61 @@ def _load_yaml(filepath: str) -> dict:
|
|
| 145 |
|
| 146 |
_COMMON_OPTIONAL_INPUTS = [
|
| 147 |
"steps", "cfg", "sampler", "scheduler", "seed",
|
| 148 |
-
"negative_prompt", "batch_size", "chain", "async_execution",
|
| 149 |
]
|
| 150 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
_TASK_DEFINITIONS = [
|
| 152 |
{
|
| 153 |
"task_type": "txt2img",
|
|
@@ -155,6 +207,29 @@ _TASK_DEFINITIONS = [
|
|
| 155 |
"description": "Generate images from text prompts. Canvas width and height must be specified.",
|
| 156 |
"required_inputs": ["prompt", "width", "height"],
|
| 157 |
"optional_inputs": _COMMON_OPTIONAL_INPUTS,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
},
|
| 159 |
{
|
| 160 |
"task_type": "img2img",
|
|
@@ -162,6 +237,14 @@ _TASK_DEFINITIONS = [
|
|
| 162 |
"description": "Perform global repaint and style transfer based on a source image. Denoise strength must be specified.",
|
| 163 |
"required_inputs": ["prompt", "image", "denoise"],
|
| 164 |
"optional_inputs": _COMMON_OPTIONAL_INPUTS,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
},
|
| 166 |
{
|
| 167 |
"task_type": "inpaint",
|
|
@@ -169,6 +252,14 @@ _TASK_DEFINITIONS = [
|
|
| 169 |
"description": "Repaint specified masked regions of the input image (with alpha mask/channel).",
|
| 170 |
"required_inputs": ["prompt", "image"],
|
| 171 |
"optional_inputs": ["denoise"] + _COMMON_OPTIONAL_INPUTS,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
},
|
| 173 |
{
|
| 174 |
"task_type": "outpaint",
|
|
@@ -176,6 +267,17 @@ _TASK_DEFINITIONS = [
|
|
| 176 |
"description": "Extend the canvas outward from the source image. Padding pixel values for top, bottom, left, and right must be specified.",
|
| 177 |
"required_inputs": ["prompt", "image", "pad_left", "pad_right", "pad_top", "pad_bottom"],
|
| 178 |
"optional_inputs": _COMMON_OPTIONAL_INPUTS,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
},
|
| 180 |
{
|
| 181 |
"task_type": "hires_fix",
|
|
@@ -183,6 +285,16 @@ _TASK_DEFINITIONS = [
|
|
| 183 |
"description": "Enhance details and upscale an existing low-resolution image.",
|
| 184 |
"required_inputs": ["prompt", "image", "upscale_by"],
|
| 185 |
"optional_inputs": ["upscaler", "denoise"] + _COMMON_OPTIONAL_INPUTS,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
},
|
| 187 |
]
|
| 188 |
|
|
|
|
| 145 |
|
| 146 |
_COMMON_OPTIONAL_INPUTS = [
|
| 147 |
"steps", "cfg", "sampler", "scheduler", "seed",
|
| 148 |
+
"negative_prompt", "batch_size", "zero_gpu_duration", "chain", "async_execution",
|
| 149 |
]
|
| 150 |
|
| 151 |
+
_COMMON_OPTIONAL_INPUTS_SCHEMA = {
|
| 152 |
+
"seed": {
|
| 153 |
+
"type": "integer",
|
| 154 |
+
"default": -1,
|
| 155 |
+
"description": "Random seed for image generation. Default: -1 (random seed). Specify a non-negative integer for deterministic reproducible generation."
|
| 156 |
+
},
|
| 157 |
+
"batch_size": {
|
| 158 |
+
"type": "integer",
|
| 159 |
+
"default": 1,
|
| 160 |
+
"minimum": 1,
|
| 161 |
+
"maximum": 16,
|
| 162 |
+
"description": "Number of images generated in a single inference batch (1 to 16, default: 1)."
|
| 163 |
+
},
|
| 164 |
+
"zero_gpu_duration": {
|
| 165 |
+
"type": "integer",
|
| 166 |
+
"default": 60,
|
| 167 |
+
"minimum": 1,
|
| 168 |
+
"maximum": 120,
|
| 169 |
+
"description": "GPU execution time quota allocation in seconds on HuggingFace ZeroGPU spaces (default: 60, maximum: 120)."
|
| 170 |
+
},
|
| 171 |
+
"steps": {
|
| 172 |
+
"type": "integer",
|
| 173 |
+
"description": "Number of inference steps. If omitted, model optimal default is automatically applied."
|
| 174 |
+
},
|
| 175 |
+
"cfg": {
|
| 176 |
+
"type": "number",
|
| 177 |
+
"description": "Classifier-Free Guidance scale. If omitted, model optimal default is automatically applied."
|
| 178 |
+
},
|
| 179 |
+
"sampler": {
|
| 180 |
+
"type": "string",
|
| 181 |
+
"description": "Sampling algorithm (e.g., 'euler', 'dpmpp_2m'). If omitted, model optimal default is applied."
|
| 182 |
+
},
|
| 183 |
+
"scheduler": {
|
| 184 |
+
"type": "string",
|
| 185 |
+
"description": "Noise scheduler type (e.g., 'simple', 'karras'). If omitted, model optimal default is applied."
|
| 186 |
+
},
|
| 187 |
+
"negative_prompt": {
|
| 188 |
+
"type": "string",
|
| 189 |
+
"default": "",
|
| 190 |
+
"description": "Negative prompt specifying undesired attributes or quality flaws to avoid."
|
| 191 |
+
},
|
| 192 |
+
"async_execution": {
|
| 193 |
+
"type": "boolean",
|
| 194 |
+
"default": False,
|
| 195 |
+
"description": "If true, submits task asynchronously and returns task_id immediately for polling via get_task_status."
|
| 196 |
+
},
|
| 197 |
+
"chain": {
|
| 198 |
+
"type": "array",
|
| 199 |
+
"description": "List of injector objects for extended features (LoRA, ControlNet, IPAdapter, etc.). Must be a JSON array of dicts with 'injector_type'."
|
| 200 |
+
}
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
_TASK_DEFINITIONS = [
|
| 204 |
{
|
| 205 |
"task_type": "txt2img",
|
|
|
|
| 207 |
"description": "Generate images from text prompts. Canvas width and height must be specified.",
|
| 208 |
"required_inputs": ["prompt", "width", "height"],
|
| 209 |
"optional_inputs": _COMMON_OPTIONAL_INPUTS,
|
| 210 |
+
"optional_inputs_schema": _COMMON_OPTIONAL_INPUTS_SCHEMA,
|
| 211 |
+
"example_json_params": {
|
| 212 |
+
"task_type": "txt2img",
|
| 213 |
+
"model": "stabilityai/SDXL-Base-1.0",
|
| 214 |
+
"prompt": "A majestic lion jumping from a big stone at night",
|
| 215 |
+
"width": 1024,
|
| 216 |
+
"height": 1024
|
| 217 |
+
},
|
| 218 |
+
"example_json_params_with_chain": {
|
| 219 |
+
"task_type": "txt2img",
|
| 220 |
+
"model": "stabilityai/SDXL-Base-1.0",
|
| 221 |
+
"prompt": "A majestic lion jumping from a big stone at night",
|
| 222 |
+
"width": 1024,
|
| 223 |
+
"height": 1024,
|
| 224 |
+
"chain": [
|
| 225 |
+
{
|
| 226 |
+
"injector_type": "lora",
|
| 227 |
+
"source": "Civitai",
|
| 228 |
+
"lora_value": "12345",
|
| 229 |
+
"scale": 0.8
|
| 230 |
+
}
|
| 231 |
+
]
|
| 232 |
+
}
|
| 233 |
},
|
| 234 |
{
|
| 235 |
"task_type": "img2img",
|
|
|
|
| 237 |
"description": "Perform global repaint and style transfer based on a source image. Denoise strength must be specified.",
|
| 238 |
"required_inputs": ["prompt", "image", "denoise"],
|
| 239 |
"optional_inputs": _COMMON_OPTIONAL_INPUTS,
|
| 240 |
+
"optional_inputs_schema": _COMMON_OPTIONAL_INPUTS_SCHEMA,
|
| 241 |
+
"example_json_params": {
|
| 242 |
+
"task_type": "img2img",
|
| 243 |
+
"model": "stabilityai/SDXL-Base-1.0",
|
| 244 |
+
"prompt": "A majestic lion jumping from a big stone at night",
|
| 245 |
+
"image": "https://example.com/source_image.png",
|
| 246 |
+
"denoise": 0.7
|
| 247 |
+
}
|
| 248 |
},
|
| 249 |
{
|
| 250 |
"task_type": "inpaint",
|
|
|
|
| 252 |
"description": "Repaint specified masked regions of the input image (with alpha mask/channel).",
|
| 253 |
"required_inputs": ["prompt", "image"],
|
| 254 |
"optional_inputs": ["denoise"] + _COMMON_OPTIONAL_INPUTS,
|
| 255 |
+
"optional_inputs_schema": _COMMON_OPTIONAL_INPUTS_SCHEMA,
|
| 256 |
+
"example_json_params": {
|
| 257 |
+
"task_type": "inpaint",
|
| 258 |
+
"model": "stabilityai/SDXL-Base-1.0",
|
| 259 |
+
"prompt": "red floral dress, detailed lace",
|
| 260 |
+
"image": "https://example.com/image_with_alpha_mask.png",
|
| 261 |
+
"denoise": 0.95
|
| 262 |
+
}
|
| 263 |
},
|
| 264 |
{
|
| 265 |
"task_type": "outpaint",
|
|
|
|
| 267 |
"description": "Extend the canvas outward from the source image. Padding pixel values for top, bottom, left, and right must be specified.",
|
| 268 |
"required_inputs": ["prompt", "image", "pad_left", "pad_right", "pad_top", "pad_bottom"],
|
| 269 |
"optional_inputs": _COMMON_OPTIONAL_INPUTS,
|
| 270 |
+
"optional_inputs_schema": _COMMON_OPTIONAL_INPUTS_SCHEMA,
|
| 271 |
+
"example_json_params": {
|
| 272 |
+
"task_type": "outpaint",
|
| 273 |
+
"model": "stabilityai/SDXL-Base-1.0",
|
| 274 |
+
"prompt": "beautiful scenery background, high quality",
|
| 275 |
+
"image": "https://example.com/source_image.png",
|
| 276 |
+
"pad_left": 128,
|
| 277 |
+
"pad_right": 128,
|
| 278 |
+
"pad_top": 0,
|
| 279 |
+
"pad_bottom": 0
|
| 280 |
+
}
|
| 281 |
},
|
| 282 |
{
|
| 283 |
"task_type": "hires_fix",
|
|
|
|
| 285 |
"description": "Enhance details and upscale an existing low-resolution image.",
|
| 286 |
"required_inputs": ["prompt", "image", "upscale_by"],
|
| 287 |
"optional_inputs": ["upscaler", "denoise"] + _COMMON_OPTIONAL_INPUTS,
|
| 288 |
+
"optional_inputs_schema": _COMMON_OPTIONAL_INPUTS_SCHEMA,
|
| 289 |
+
"example_json_params": {
|
| 290 |
+
"task_type": "hires_fix",
|
| 291 |
+
"model": "stabilityai/SDXL-Base-1.0",
|
| 292 |
+
"prompt": "masterpiece, best quality, sharp focus",
|
| 293 |
+
"image": "https://example.com/low_res_image.png",
|
| 294 |
+
"upscale_by": 2.0,
|
| 295 |
+
"upscaler": "nearest-exact",
|
| 296 |
+
"denoise": 0.55
|
| 297 |
+
}
|
| 298 |
},
|
| 299 |
]
|
| 300 |
|
mcp_tools/get_feature_list.py
CHANGED
|
@@ -4,7 +4,83 @@ from .common import _load_yaml, _CHAIN_FEATURES_PATH, _YAML_DIR
|
|
| 4 |
from .error_schema import make_not_found_error
|
| 5 |
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
def _build_feature_entry(chain_name: str, chain_data: dict, include_schema: bool = False) -> dict:
|
|
|
|
| 8 |
entry = {
|
| 9 |
"feature_name": chain_name,
|
| 10 |
"chains": chain_data.get("chains", chain_name),
|
|
@@ -13,6 +89,15 @@ def _build_feature_entry(chain_name: str, chain_data: dict, include_schema: bool
|
|
| 13 |
"supported_tasks": chain_data.get("supported_tasks", []),
|
| 14 |
"max_count": chain_data.get("max_count", 1),
|
| 15 |
"usage_guideline": chain_data.get("usage_guideline", ""),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
}
|
| 17 |
if include_schema:
|
| 18 |
schema = deepcopy(chain_data.get("parameters_schema", {}))
|
|
|
|
| 4 |
from .error_schema import make_not_found_error
|
| 5 |
|
| 6 |
|
| 7 |
+
def _get_default_example_chain_item(chain_name: str, chain_data: dict) -> dict:
|
| 8 |
+
if "example_chain_item" in chain_data and isinstance(chain_data["example_chain_item"], dict):
|
| 9 |
+
return deepcopy(chain_data["example_chain_item"])
|
| 10 |
+
|
| 11 |
+
if chain_name == "lora":
|
| 12 |
+
return {
|
| 13 |
+
"injector_type": "lora",
|
| 14 |
+
"source": "Civitai",
|
| 15 |
+
"lora_value": "12345",
|
| 16 |
+
"scale": 1.0,
|
| 17 |
+
}
|
| 18 |
+
elif chain_name == "ipadapter":
|
| 19 |
+
return {
|
| 20 |
+
"injector_type": "ipadapter",
|
| 21 |
+
"image": "https://example.com/reference_image.png",
|
| 22 |
+
"weight": 1.0,
|
| 23 |
+
"preset": "STANDARD (medium strength)",
|
| 24 |
+
}
|
| 25 |
+
elif chain_name in ("controlnet", "diffsynth_controlnet", "krea2_controlnet", "anima_controlnet_lllite"):
|
| 26 |
+
return {
|
| 27 |
+
"injector_type": chain_name,
|
| 28 |
+
"type": "Depth",
|
| 29 |
+
"series": "SDXL" if chain_name == "controlnet" else "Patil",
|
| 30 |
+
"image": "https://example.com/control_depth_map.png",
|
| 31 |
+
"strength": 1.0,
|
| 32 |
+
}
|
| 33 |
+
elif chain_name == "conditioning":
|
| 34 |
+
return {
|
| 35 |
+
"injector_type": "conditioning",
|
| 36 |
+
"prompt": "blue sky with soft clouds",
|
| 37 |
+
"x": 0,
|
| 38 |
+
"y": 0,
|
| 39 |
+
"width": 1024,
|
| 40 |
+
"height": 512,
|
| 41 |
+
"strength": 1.0,
|
| 42 |
+
}
|
| 43 |
+
elif chain_name == "vae":
|
| 44 |
+
return {
|
| 45 |
+
"injector_type": "vae",
|
| 46 |
+
"source": "Civitai",
|
| 47 |
+
"vae_value": "12345",
|
| 48 |
+
}
|
| 49 |
+
elif chain_name == "embedding":
|
| 50 |
+
return {
|
| 51 |
+
"injector_type": "embedding",
|
| 52 |
+
"source": "Civitai",
|
| 53 |
+
"embedding_value": "12345",
|
| 54 |
+
}
|
| 55 |
+
elif chain_name == "pid":
|
| 56 |
+
return {
|
| 57 |
+
"injector_type": "pid",
|
| 58 |
+
"enabled": True,
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
injector_type = chain_data.get("chains")
|
| 62 |
+
if isinstance(injector_type, list):
|
| 63 |
+
injector_type = injector_type[0]
|
| 64 |
+
elif not isinstance(injector_type, str):
|
| 65 |
+
injector_type = chain_name
|
| 66 |
+
|
| 67 |
+
item = {"injector_type": injector_type}
|
| 68 |
+
schema = chain_data.get("parameters_schema", {})
|
| 69 |
+
props = schema.get("properties", {})
|
| 70 |
+
for p_name, p_info in props.items():
|
| 71 |
+
if p_name == "image":
|
| 72 |
+
item["image"] = "https://example.com/reference.png"
|
| 73 |
+
elif p_name == "source":
|
| 74 |
+
item["source"] = "Civitai"
|
| 75 |
+
elif p_name in ("weight", "strength", "scale", "factor"):
|
| 76 |
+
item[p_name] = p_info.get("default", 1.0)
|
| 77 |
+
elif p_name == "enabled":
|
| 78 |
+
item["enabled"] = True
|
| 79 |
+
return item
|
| 80 |
+
|
| 81 |
+
|
| 82 |
def _build_feature_entry(chain_name: str, chain_data: dict, include_schema: bool = False) -> dict:
|
| 83 |
+
example_item = _get_default_example_chain_item(chain_name, chain_data)
|
| 84 |
entry = {
|
| 85 |
"feature_name": chain_name,
|
| 86 |
"chains": chain_data.get("chains", chain_name),
|
|
|
|
| 89 |
"supported_tasks": chain_data.get("supported_tasks", []),
|
| 90 |
"max_count": chain_data.get("max_count", 1),
|
| 91 |
"usage_guideline": chain_data.get("usage_guideline", ""),
|
| 92 |
+
"example_chain_item": example_item,
|
| 93 |
+
"example_json_params": {
|
| 94 |
+
"task_type": "txt2img",
|
| 95 |
+
"model": "stabilityai/SDXL-Base-1.0",
|
| 96 |
+
"prompt": "A majestic lion jumping from a big stone at night",
|
| 97 |
+
"width": 1024,
|
| 98 |
+
"height": 1024,
|
| 99 |
+
"chain": [example_item],
|
| 100 |
+
},
|
| 101 |
}
|
| 102 |
if include_schema:
|
| 103 |
schema = deepcopy(chain_data.get("parameters_schema", {}))
|
mcp_tools/get_model_features.py
CHANGED
|
@@ -84,6 +84,28 @@ def handle_get_model_features(model: str) -> dict:
|
|
| 84 |
"supported_tasks": supported_tasks,
|
| 85 |
"supported_features": supported_features,
|
| 86 |
"default_parameter": default_parameter,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
}
|
| 88 |
|
| 89 |
default_pos = model_specific_defaults.get(
|
|
|
|
| 84 |
"supported_tasks": supported_tasks,
|
| 85 |
"supported_features": supported_features,
|
| 86 |
"default_parameter": default_parameter,
|
| 87 |
+
"example_json_params": {
|
| 88 |
+
"task_type": "txt2img",
|
| 89 |
+
"model": model,
|
| 90 |
+
"prompt": "A majestic lion jumping from a big stone at night",
|
| 91 |
+
"width": 1024,
|
| 92 |
+
"height": 1024
|
| 93 |
+
},
|
| 94 |
+
"example_json_params_with_chain": {
|
| 95 |
+
"task_type": "txt2img",
|
| 96 |
+
"model": model,
|
| 97 |
+
"prompt": "A majestic lion jumping from a big stone at night",
|
| 98 |
+
"width": 1024,
|
| 99 |
+
"height": 1024,
|
| 100 |
+
"chain": [
|
| 101 |
+
{
|
| 102 |
+
"injector_type": "lora",
|
| 103 |
+
"source": "Civitai",
|
| 104 |
+
"lora_value": "12345",
|
| 105 |
+
"scale": 1.0
|
| 106 |
+
}
|
| 107 |
+
]
|
| 108 |
+
}
|
| 109 |
}
|
| 110 |
|
| 111 |
default_pos = model_specific_defaults.get(
|
mcp_tools/mcp_gradio_integration.py
CHANGED
|
@@ -75,7 +75,7 @@ def register_high_level_mcp_apis(demo):
|
|
| 75 |
Using gr.api() never adds any visual UI components (such as Row, Textbox, Button, etc.), avoiding duplicate interface rendering.
|
| 76 |
"""
|
| 77 |
def get_task_list() -> list:
|
| 78 |
-
"""[Recommended Discovery Flow Step 1] Get a list of all supported image generation task types (txt2img, img2img, inpaint, outpaint, hires_fix) along with their required and
|
| 79 |
return sanitize_keys(handle_get_task_list())
|
| 80 |
|
| 81 |
def get_model_architecture_list() -> list:
|
|
@@ -84,19 +84,42 @@ def register_high_level_mcp_apis(demo):
|
|
| 84 |
|
| 85 |
def get_model_list(model_architecture: str = "") -> list | dict:
|
| 86 |
"""[Recommended Discovery Flow Step 3] Query the list of available image generation models. After obtaining models, choose one of two paths: 1. [Path 1 (Recommended - Minimal Mode)] Call run directly with only required parameters. Do NOT guess steps/cfg/sampler/scheduler from experience; the server will automatically apply the model's optimal default hyperparameters. 2. [Path 2 (Explicit Alignment Mode)] First call get_model_features to query the model's officially recommended hyperparameters, then pass them to run."""
|
| 87 |
-
|
|
|
|
|
|
|
| 88 |
return sanitize_keys(handle_get_model_list(arch))
|
| 89 |
|
| 90 |
def get_feature_list(feature_name: str = "") -> list | dict:
|
| 91 |
-
"""Get supported advanced features. If feature_name is empty, returns
|
|
|
|
|
|
|
| 92 |
return sanitize_keys(handle_get_feature_list(feature_name.strip() if isinstance(feature_name, str) else feature_name))
|
| 93 |
|
| 94 |
def get_model_features(model: str = "") -> dict:
|
| 95 |
-
"""Query metadata for the specified model, including supported task types, extended features,
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
def run(json_params: str = "{}") -> dict:
|
| 99 |
-
"""[Recommended Discovery Flow Step 4] Unified image generation task execution interface.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
try:
|
| 101 |
if isinstance(json_params, dict):
|
| 102 |
params = json_params
|
|
@@ -108,7 +131,10 @@ def register_high_level_mcp_apis(demo):
|
|
| 108 |
|
| 109 |
def get_task_status(task_id: str = "") -> dict:
|
| 110 |
"""Query the progress, status, and final generated results of an async image generation task."""
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
funcs = [
|
| 114 |
get_task_list,
|
|
|
|
| 75 |
Using gr.api() never adds any visual UI components (such as Row, Textbox, Button, etc.), avoiding duplicate interface rendering.
|
| 76 |
"""
|
| 77 |
def get_task_list() -> list:
|
| 78 |
+
"""[Recommended Discovery Flow Step 1] Get a list of all supported image generation task types (txt2img, img2img, inpaint, outpaint, hires_fix) along with their required/optional parameters and paste-and-run example_json_params. Recommended flow: get_task_list -> get_model_architecture_list -> get_model_list -> run."""
|
| 79 |
return sanitize_keys(handle_get_task_list())
|
| 80 |
|
| 81 |
def get_model_architecture_list() -> list:
|
|
|
|
| 84 |
|
| 85 |
def get_model_list(model_architecture: str = "") -> list | dict:
|
| 86 |
"""[Recommended Discovery Flow Step 3] Query the list of available image generation models. After obtaining models, choose one of two paths: 1. [Path 1 (Recommended - Minimal Mode)] Call run directly with only required parameters. Do NOT guess steps/cfg/sampler/scheduler from experience; the server will automatically apply the model's optimal default hyperparameters. 2. [Path 2 (Explicit Alignment Mode)] First call get_model_features to query the model's officially recommended hyperparameters, then pass them to run."""
|
| 87 |
+
if isinstance(model_architecture, dict):
|
| 88 |
+
model_architecture = model_architecture.get("model_architecture") or model_architecture.get("arch") or ""
|
| 89 |
+
arch = model_architecture.strip() if isinstance(model_architecture, str) and model_architecture.strip() else None
|
| 90 |
return sanitize_keys(handle_get_model_list(arch))
|
| 91 |
|
| 92 |
def get_feature_list(feature_name: str = "") -> list | dict:
|
| 93 |
+
"""Get supported advanced features (LoRA, ControlNet, IPAdapter, etc.). Each feature includes ready-to-run example_chain_item and example_json_params. If feature_name is empty, returns summary of ALL features. Pass specific feature_name to retrieve complete parameters_schema."""
|
| 94 |
+
if isinstance(feature_name, dict):
|
| 95 |
+
feature_name = feature_name.get("feature_name") or feature_name.get("name") or ""
|
| 96 |
return sanitize_keys(handle_get_feature_list(feature_name.strip() if isinstance(feature_name, str) else feature_name))
|
| 97 |
|
| 98 |
def get_model_features(model: str = "") -> dict:
|
| 99 |
+
"""Query metadata for the specified model, including supported task types, extended features, default parameters, and paste-and-run example_json_params."""
|
| 100 |
+
if isinstance(model, dict):
|
| 101 |
+
model = model.get("model") or model.get("name") or ""
|
| 102 |
+
model_str = model.strip() if isinstance(model, str) else ""
|
| 103 |
+
return sanitize_keys(handle_get_model_features(model_str))
|
| 104 |
|
| 105 |
def run(json_params: str = "{}") -> dict:
|
| 106 |
+
"""[Recommended Discovery Flow Step 4] Unified image generation task execution interface. Accepts a JSON string or dict of parameters.
|
| 107 |
+
|
| 108 |
+
OPTIONAL CONTROL PARAMETERS:
|
| 109 |
+
- seed (int): Random seed (-1 for random, >=0 for deterministic reproducibility). Default: -1.
|
| 110 |
+
- batch_size (int): Number of images generated per batch (1 to 16). Default: 1.
|
| 111 |
+
- zero_gpu_duration (int): GPU quota allocation in seconds on HuggingFace ZeroGPU spaces (default: 60, max: 120).
|
| 112 |
+
- negative_prompt (str): Text prompt specifying elements to avoid.
|
| 113 |
+
|
| 114 |
+
IMPORTANT FORMAT RULES FOR 'chain':
|
| 115 |
+
- For LoRA/Civitai: 'lora_value' refers to the Civitai Version ID (modelVersionId), not the main Model ID.
|
| 116 |
+
|
| 117 |
+
Paste-and-Run Example (Basic):
|
| 118 |
+
{"task_type": "txt2img", "model": "stabilityai/SDXL-Base-1.0", "prompt": "A majestic lion jumping from a big stone at night", "width": 1024, "height": 1024}
|
| 119 |
+
|
| 120 |
+
Paste-and-Run Example (With chain):
|
| 121 |
+
{"task_type": "txt2img", "model": "stabilityai/SDXL-Base-1.0", "prompt": "A majestic lion jumping from a big stone at night", "width": 1024, "height": 1024, "chain": [{"injector_type": "lora", "source": "Civitai", "lora_value": "12345", "scale": 1.0}]}
|
| 122 |
+
"""
|
| 123 |
try:
|
| 124 |
if isinstance(json_params, dict):
|
| 125 |
params = json_params
|
|
|
|
| 131 |
|
| 132 |
def get_task_status(task_id: str = "") -> dict:
|
| 133 |
"""Query the progress, status, and final generated results of an async image generation task."""
|
| 134 |
+
if isinstance(task_id, dict):
|
| 135 |
+
task_id = task_id.get("task_id") or task_id.get("id") or ""
|
| 136 |
+
task_id_str = task_id.strip() if isinstance(task_id, str) else ""
|
| 137 |
+
return sanitize_keys(handle_get_task_status(task_id_str))
|
| 138 |
|
| 139 |
funcs = [
|
| 140 |
get_task_list,
|
mcp_tools/run.py
CHANGED
|
@@ -17,7 +17,42 @@ from .error_schema import make_validation_error, make_not_found_error
|
|
| 17 |
|
| 18 |
|
| 19 |
def handle_run(params: dict) -> dict:
|
| 20 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
if not isinstance(params, dict):
|
| 22 |
return make_validation_error("Request params must be an object.")
|
| 23 |
|
|
@@ -39,6 +74,34 @@ def handle_run(params: dict) -> dict:
|
|
| 39 |
invalid_fields={"task_type": f"Must be in {valid_tasks}"},
|
| 40 |
)
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
model_list = _load_yaml(_MODEL_LIST_PATH)
|
| 43 |
checkpoints = model_list.get("Checkpoint", {})
|
| 44 |
all_models = set()
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
def handle_run(params: dict) -> dict:
|
| 20 |
+
"""
|
| 21 |
+
Unified image generation task execution interface.
|
| 22 |
+
|
| 23 |
+
[OPTIONAL CONTROL PARAMETERS]
|
| 24 |
+
- seed (int): Random seed for generation. Default: -1 (random seed). Specify >=0 for deterministic reproducibility.
|
| 25 |
+
- batch_size (int): Number of images generated in a single batch (1 to 16, default: 1).
|
| 26 |
+
- zero_gpu_duration (int): GPU quota allocation in seconds on HuggingFace ZeroGPU spaces (default: 60, max: 120).
|
| 27 |
+
- negative_prompt (str): Text prompt specifying undesirable elements to avoid.
|
| 28 |
+
- steps (int), cfg (float), sampler (str), scheduler (str): Inference hyperparams (auto-applied from model defaults if omitted).
|
| 29 |
+
|
| 30 |
+
[Paste-and-Run json_params Example (Basic)]
|
| 31 |
+
{
|
| 32 |
+
"task_type": "txt2img",
|
| 33 |
+
"model": "stabilityai/SDXL-Base-1.0",
|
| 34 |
+
"prompt": "A majestic lion jumping from a big stone at night",
|
| 35 |
+
"width": 1024,
|
| 36 |
+
"height": 1024
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
[Paste-and-Run json_params Example (With chain)]
|
| 40 |
+
{
|
| 41 |
+
"task_type": "txt2img",
|
| 42 |
+
"model": "stabilityai/SDXL-Base-1.0",
|
| 43 |
+
"prompt": "A majestic lion jumping from a big stone at night",
|
| 44 |
+
"width": 1024,
|
| 45 |
+
"height": 1024,
|
| 46 |
+
"chain": [
|
| 47 |
+
{
|
| 48 |
+
"injector_type": "lora",
|
| 49 |
+
"source": "Civitai",
|
| 50 |
+
"lora_value": "12345",
|
| 51 |
+
"scale": 1.0
|
| 52 |
+
}
|
| 53 |
+
]
|
| 54 |
+
}
|
| 55 |
+
"""
|
| 56 |
if not isinstance(params, dict):
|
| 57 |
return make_validation_error("Request params must be an object.")
|
| 58 |
|
|
|
|
| 74 |
invalid_fields={"task_type": f"Must be in {valid_tasks}"},
|
| 75 |
)
|
| 76 |
|
| 77 |
+
if "chain" in params and params["chain"] is not None:
|
| 78 |
+
chain_val = params["chain"]
|
| 79 |
+
if isinstance(chain_val, dict):
|
| 80 |
+
return make_validation_error(
|
| 81 |
+
"Parameter 'chain' must be a JSON array (list) of injector objects [{'injector_type': 'lora', ...}], but received a dictionary. "
|
| 82 |
+
"Do NOT structure chain as a dict like {'lora': [...]}. "
|
| 83 |
+
"Example correct format: [{'injector_type': 'lora', 'source': 'Civitai', 'lora_value': '12345', 'scale': 1.0}]",
|
| 84 |
+
invalid_fields={"chain": "Expected list of objects, received dict"},
|
| 85 |
+
)
|
| 86 |
+
if not isinstance(chain_val, list):
|
| 87 |
+
return make_validation_error(
|
| 88 |
+
"Parameter 'chain' must be a JSON array (list) of injector objects.",
|
| 89 |
+
invalid_fields={"chain": f"Expected list, received {type(chain_val).__name__}"},
|
| 90 |
+
)
|
| 91 |
+
for idx, item in enumerate(chain_val):
|
| 92 |
+
if not isinstance(item, dict):
|
| 93 |
+
return make_validation_error(
|
| 94 |
+
f"Item at chain[{idx}] must be an object (dict) containing 'injector_type'. "
|
| 95 |
+
f"Example: {{'injector_type': 'lora', 'source': 'Civitai', 'lora_value': '12345', 'scale': 1.0}}",
|
| 96 |
+
invalid_fields={f"chain[{idx}]": f"Expected dict, received {type(item).__name__}"},
|
| 97 |
+
)
|
| 98 |
+
if "injector_type" not in item or not item["injector_type"]:
|
| 99 |
+
return make_validation_error(
|
| 100 |
+
f"Item at chain[{idx}] is missing required string field 'injector_type'. "
|
| 101 |
+
f"Example: {{'injector_type': 'lora', 'source': 'Civitai', 'lora_value': '12345', 'scale': 1.0}}",
|
| 102 |
+
missing_fields=[f"chain[{idx}].injector_type"],
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
model_list = _load_yaml(_MODEL_LIST_PATH)
|
| 106 |
checkpoints = model_list.get("Checkpoint", {})
|
| 107 |
all_models = set()
|
ui/events/change_handlers.py
CHANGED
|
@@ -17,7 +17,7 @@ from .config_loaders import (
|
|
| 17 |
load_ipadapter_config
|
| 18 |
)
|
| 19 |
|
| 20 |
-
def make_update_fn(m_comp, cat_comp,
|
| 21 |
def update_fn(*args):
|
| 22 |
arch = args[0]
|
| 23 |
category = args[1]
|
|
@@ -77,8 +77,6 @@ def make_update_fn(m_comp, cat_comp, cs_comp, ar_comp, width_comp, height_comp,
|
|
| 77 |
if pid_acc: updates[pid_acc] = gr.update(visible=('pid' in enabled_chains))
|
| 78 |
if vae_acc: updates[vae_acc] = gr.update(visible=('vae' in enabled_chains))
|
| 79 |
|
| 80 |
-
if cs_comp:
|
| 81 |
-
updates[cs_comp] = gr.update(visible=(arch_model_type == "sd15"))
|
| 82 |
if guidance_comp:
|
| 83 |
updates[guidance_comp] = gr.update(visible=(arch_model_type == "flux1"))
|
| 84 |
|
|
@@ -148,7 +146,7 @@ def make_update_fn(m_comp, cat_comp, cs_comp, ar_comp, width_comp, height_comp,
|
|
| 148 |
return update_fn
|
| 149 |
|
| 150 |
|
| 151 |
-
def make_model_change_fn(cat_comp_ref,
|
| 152 |
def change_fn(*args):
|
| 153 |
model_name = args[0]
|
| 154 |
idx = 1
|
|
@@ -213,8 +211,6 @@ def make_model_change_fn(cat_comp_ref, cs_comp, ar_comp, width_comp, height_comp
|
|
| 213 |
if pid_acc: updates[pid_acc] = gr.update(visible=('pid' in enabled_chains))
|
| 214 |
if vae_acc: updates[vae_acc] = gr.update(visible=('vae' in enabled_chains))
|
| 215 |
|
| 216 |
-
if cs_comp:
|
| 217 |
-
updates[cs_comp] = gr.update(visible=(arch_model_type == "sd15"))
|
| 218 |
if guidance_comp:
|
| 219 |
updates[guidance_comp] = gr.update(visible=(arch_model_type == "flux1"))
|
| 220 |
|
|
|
|
| 17 |
load_ipadapter_config
|
| 18 |
)
|
| 19 |
|
| 20 |
+
def make_update_fn(m_comp, cat_comp, ar_comp, width_comp, height_comp, cn_types, cn_series, cn_filepaths, anima_cn_types, anima_cn_series, anima_cn_filepaths, diffsynth_cn_types, diffsynth_cn_series, diffsynth_cn_filepaths, krea2_cn_types, krea2_cn_series, krea2_cn_filepaths, ipa_preset, lora_acc, cn_acc, anima_cn_acc, diffsynth_cn_acc, krea2_cn_acc, ipa_acc, sd3_ipa_acc, flux1_ipa_acc, style_acc, embed_acc, cond_acc, ref_latent_acc, hidream_o1_ref_acc, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp, pid_acc=None, vae_acc=None, joyai_ref_acc=None, krea2_identity_edit_acc=None, krea2_reference_edit_acc=None, qwen_image_edit_acc=None, boogu_edit_acc=None, ref_img_acc=None):
|
| 21 |
def update_fn(*args):
|
| 22 |
arch = args[0]
|
| 23 |
category = args[1]
|
|
|
|
| 77 |
if pid_acc: updates[pid_acc] = gr.update(visible=('pid' in enabled_chains))
|
| 78 |
if vae_acc: updates[vae_acc] = gr.update(visible=('vae' in enabled_chains))
|
| 79 |
|
|
|
|
|
|
|
| 80 |
if guidance_comp:
|
| 81 |
updates[guidance_comp] = gr.update(visible=(arch_model_type == "flux1"))
|
| 82 |
|
|
|
|
| 146 |
return update_fn
|
| 147 |
|
| 148 |
|
| 149 |
+
def make_model_change_fn(cat_comp_ref, ar_comp, width_comp, height_comp, cn_types, cn_series, cn_filepaths, anima_cn_types, anima_cn_series, anima_cn_filepaths, diffsynth_cn_types, diffsynth_cn_series, diffsynth_cn_filepaths, krea2_cn_types, krea2_cn_series, krea2_cn_filepaths, arch_comp_ref, ipa_preset, lora_acc, cn_acc, anima_cn_acc, diffsynth_cn_acc, krea2_cn_acc, ipa_acc, sd3_ipa_acc, flux1_ipa_acc, style_acc, embed_acc, cond_acc, ref_latent_acc, hidream_o1_ref_acc, guidance_comp, prompt_comp, neg_prompt_comp, steps_comp, cfg_comp, sampler_comp, scheduler_comp, pid_acc=None, vae_acc=None, joyai_ref_acc=None, krea2_identity_edit_acc=None, krea2_reference_edit_acc=None, qwen_image_edit_acc=None, boogu_edit_acc=None, ref_img_acc=None):
|
| 150 |
def change_fn(*args):
|
| 151 |
model_name = args[0]
|
| 152 |
idx = 1
|
|
|
|
| 211 |
if pid_acc: updates[pid_acc] = gr.update(visible=('pid' in enabled_chains))
|
| 212 |
if vae_acc: updates[vae_acc] = gr.update(visible=('vae' in enabled_chains))
|
| 213 |
|
|
|
|
|
|
|
| 214 |
if guidance_comp:
|
| 215 |
updates[guidance_comp] = gr.update(visible=(arch_model_type == "flux1"))
|
| 216 |
|
ui/events/main.py
CHANGED
|
@@ -37,7 +37,6 @@ def attach_event_handlers(ui_components, demo):
|
|
| 37 |
arch_comp = ui_components.get(f'model_arch_{prefix}')
|
| 38 |
cat_comp = ui_components.get(f'model_cat_{prefix}')
|
| 39 |
model_comp = ui_components.get(f'base_model_{prefix}')
|
| 40 |
-
clip_skip_comp = ui_components.get(f'clip_skip_{prefix}') or ui_components.get(f'{prefix}_clip_skip')
|
| 41 |
guidance_comp = ui_components.get(f'guidance_{prefix}') or ui_components.get(f'{prefix}_guidance')
|
| 42 |
aspect_ratio_comp = ui_components.get(f'aspect_ratio_{prefix}') or ui_components.get(f'{prefix}_aspect_ratio_dropdown')
|
| 43 |
width_comp = ui_components.get(f'width_{prefix}') or ui_components.get(f'{prefix}_width')
|
|
@@ -95,7 +94,6 @@ def attach_event_handlers(ui_components, demo):
|
|
| 95 |
|
| 96 |
if arch_comp and cat_comp and model_comp:
|
| 97 |
outputs = [model_comp, cat_comp]
|
| 98 |
-
if clip_skip_comp: outputs.append(clip_skip_comp)
|
| 99 |
if guidance_comp: outputs.append(guidance_comp)
|
| 100 |
if aspect_ratio_comp: outputs.append(aspect_ratio_comp)
|
| 101 |
outputs.extend(cn_types_list + cn_series_list + cn_filepaths_list)
|
|
@@ -128,7 +126,7 @@ def attach_event_handlers(ui_components, demo):
|
|
| 128 |
outputs.extend(valid_extra_comps)
|
| 129 |
|
| 130 |
update_fn = make_update_fn(
|
| 131 |
-
model_comp, cat_comp,
|
| 132 |
cn_types_list, cn_series_list, cn_filepaths_list,
|
| 133 |
anima_cn_types_list, anima_cn_series_list, anima_cn_filepaths_list,
|
| 134 |
diffsynth_cn_types_list, diffsynth_cn_series_list, diffsynth_cn_filepaths_list,
|
|
@@ -147,7 +145,6 @@ def attach_event_handlers(ui_components, demo):
|
|
| 147 |
outputs2 = []
|
| 148 |
if arch_comp: outputs2.append(arch_comp)
|
| 149 |
if cat_comp: outputs2.append(cat_comp)
|
| 150 |
-
if clip_skip_comp: outputs2.append(clip_skip_comp)
|
| 151 |
if guidance_comp: outputs2.append(guidance_comp)
|
| 152 |
if aspect_ratio_comp: outputs2.append(aspect_ratio_comp)
|
| 153 |
outputs2.extend(cn_types_list + cn_series_list + cn_filepaths_list)
|
|
@@ -185,7 +182,7 @@ def attach_event_handlers(ui_components, demo):
|
|
| 185 |
if cat_comp: inputs2.append(cat_comp)
|
| 186 |
if aspect_ratio_comp: inputs2.append(aspect_ratio_comp)
|
| 187 |
change_fn = make_model_change_fn(
|
| 188 |
-
cat_comp,
|
| 189 |
cn_types_list, cn_series_list, cn_filepaths_list,
|
| 190 |
anima_cn_types_list, anima_cn_series_list, anima_cn_filepaths_list,
|
| 191 |
diffsynth_cn_types_list, diffsynth_cn_series_list, diffsynth_cn_filepaths_list,
|
|
|
|
| 37 |
arch_comp = ui_components.get(f'model_arch_{prefix}')
|
| 38 |
cat_comp = ui_components.get(f'model_cat_{prefix}')
|
| 39 |
model_comp = ui_components.get(f'base_model_{prefix}')
|
|
|
|
| 40 |
guidance_comp = ui_components.get(f'guidance_{prefix}') or ui_components.get(f'{prefix}_guidance')
|
| 41 |
aspect_ratio_comp = ui_components.get(f'aspect_ratio_{prefix}') or ui_components.get(f'{prefix}_aspect_ratio_dropdown')
|
| 42 |
width_comp = ui_components.get(f'width_{prefix}') or ui_components.get(f'{prefix}_width')
|
|
|
|
| 94 |
|
| 95 |
if arch_comp and cat_comp and model_comp:
|
| 96 |
outputs = [model_comp, cat_comp]
|
|
|
|
| 97 |
if guidance_comp: outputs.append(guidance_comp)
|
| 98 |
if aspect_ratio_comp: outputs.append(aspect_ratio_comp)
|
| 99 |
outputs.extend(cn_types_list + cn_series_list + cn_filepaths_list)
|
|
|
|
| 126 |
outputs.extend(valid_extra_comps)
|
| 127 |
|
| 128 |
update_fn = make_update_fn(
|
| 129 |
+
model_comp, cat_comp, aspect_ratio_comp, width_comp, height_comp,
|
| 130 |
cn_types_list, cn_series_list, cn_filepaths_list,
|
| 131 |
anima_cn_types_list, anima_cn_series_list, anima_cn_filepaths_list,
|
| 132 |
diffsynth_cn_types_list, diffsynth_cn_series_list, diffsynth_cn_filepaths_list,
|
|
|
|
| 145 |
outputs2 = []
|
| 146 |
if arch_comp: outputs2.append(arch_comp)
|
| 147 |
if cat_comp: outputs2.append(cat_comp)
|
|
|
|
| 148 |
if guidance_comp: outputs2.append(guidance_comp)
|
| 149 |
if aspect_ratio_comp: outputs2.append(aspect_ratio_comp)
|
| 150 |
outputs2.extend(cn_types_list + cn_series_list + cn_filepaths_list)
|
|
|
|
| 182 |
if cat_comp: inputs2.append(cat_comp)
|
| 183 |
if aspect_ratio_comp: inputs2.append(aspect_ratio_comp)
|
| 184 |
change_fn = make_model_change_fn(
|
| 185 |
+
cat_comp, aspect_ratio_comp, width_comp, height_comp,
|
| 186 |
cn_types_list, cn_series_list, cn_filepaths_list,
|
| 187 |
anima_cn_types_list, anima_cn_series_list, anima_cn_filepaths_list,
|
| 188 |
diffsynth_cn_types_list, diffsynth_cn_series_list, diffsynth_cn_filepaths_list,
|
ui/events/run_handlers.py
CHANGED
|
@@ -13,8 +13,6 @@ def create_run_event(prefix: str, task_type: str, ui_components: dict):
|
|
| 13 |
'sampler': ui_components.get(f'sampler_{prefix}') or ui_components.get(f'{prefix}_sampler_name'),
|
| 14 |
'scheduler': ui_components.get(f'scheduler_{prefix}') or ui_components.get(f'{prefix}_scheduler'),
|
| 15 |
'zero_gpu_duration': ui_components.get(f'zero_gpu_{prefix}'),
|
| 16 |
-
|
| 17 |
-
'clip_skip': ui_components.get(f'clip_skip_{prefix}'),
|
| 18 |
'guidance': ui_components.get(f'guidance_{prefix}'),
|
| 19 |
'task_type': gr.State(task_type)
|
| 20 |
}
|
|
|
|
| 13 |
'sampler': ui_components.get(f'sampler_{prefix}') or ui_components.get(f'{prefix}_sampler_name'),
|
| 14 |
'scheduler': ui_components.get(f'scheduler_{prefix}') or ui_components.get(f'{prefix}_scheduler'),
|
| 15 |
'zero_gpu_duration': ui_components.get(f'zero_gpu_{prefix}'),
|
|
|
|
|
|
|
| 16 |
'guidance': ui_components.get(f'guidance_{prefix}'),
|
| 17 |
'task_type': gr.State(task_type)
|
| 18 |
}
|
ui/shared/hires_fix_ui.py
CHANGED
|
@@ -77,7 +77,6 @@ def create_ui():
|
|
| 77 |
components[f'seed_{prefix}'] = gr.Number(label="Seed (-1 for random)", value=-1, precision=0)
|
| 78 |
components[f'batch_size_{prefix}'] = gr.Slider(label="Batch Size", minimum=1, maximum=16, step=1, value=1)
|
| 79 |
with gr.Row():
|
| 80 |
-
components[f'clip_skip_{prefix}'] = gr.Slider(label="Clip Skip", minimum=1, maximum=2, step=1, value=1, visible=False, interactive=True)
|
| 81 |
components[f'guidance_{prefix}'] = gr.Slider(label="Guidance (FLUX)", minimum=1.0, maximum=10.0, step=0.1, value=3.5, visible=False, interactive=True)
|
| 82 |
components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60s, Max: 120s", info="Optional: Set how long to reserve the GPU.")
|
| 83 |
|
|
|
|
| 77 |
components[f'seed_{prefix}'] = gr.Number(label="Seed (-1 for random)", value=-1, precision=0)
|
| 78 |
components[f'batch_size_{prefix}'] = gr.Slider(label="Batch Size", minimum=1, maximum=16, step=1, value=1)
|
| 79 |
with gr.Row():
|
|
|
|
| 80 |
components[f'guidance_{prefix}'] = gr.Slider(label="Guidance (FLUX)", minimum=1.0, maximum=10.0, step=0.1, value=3.5, visible=False, interactive=True)
|
| 81 |
components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60s, Max: 120s", info="Optional: Set how long to reserve the GPU.")
|
| 82 |
|
ui/shared/img2img_ui.py
CHANGED
|
@@ -61,7 +61,6 @@ def create_ui():
|
|
| 61 |
components[f'seed_{prefix}'] = gr.Number(label="Seed (-1 for random)", value=-1, precision=0)
|
| 62 |
components[f'batch_size_{prefix}'] = gr.Slider(label="Batch Size", minimum=1, maximum=16, step=1, value=1)
|
| 63 |
with gr.Row():
|
| 64 |
-
components[f'clip_skip_{prefix}'] = gr.Slider(label="Clip Skip", minimum=1, maximum=2, step=1, value=1, visible=False, interactive=True)
|
| 65 |
components[f'guidance_{prefix}'] = gr.Slider(label="Guidance (FLUX)", minimum=1.0, maximum=10.0, step=0.1, value=3.5, visible=False, interactive=True)
|
| 66 |
components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60s, Max: 120s", info="Optional: Set how long to reserve the GPU. Longer jobs may need more time.")
|
| 67 |
|
|
|
|
| 61 |
components[f'seed_{prefix}'] = gr.Number(label="Seed (-1 for random)", value=-1, precision=0)
|
| 62 |
components[f'batch_size_{prefix}'] = gr.Slider(label="Batch Size", minimum=1, maximum=16, step=1, value=1)
|
| 63 |
with gr.Row():
|
|
|
|
| 64 |
components[f'guidance_{prefix}'] = gr.Slider(label="Guidance (FLUX)", minimum=1.0, maximum=10.0, step=0.1, value=3.5, visible=False, interactive=True)
|
| 65 |
components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60s, Max: 120s", info="Optional: Set how long to reserve the GPU. Longer jobs may need more time.")
|
| 66 |
|
ui/shared/inpaint_ui.py
CHANGED
|
@@ -87,7 +87,6 @@ def create_ui():
|
|
| 87 |
components[f'seed_{prefix}'] = gr.Number(label="Seed (-1 for random)", value=-1, precision=0)
|
| 88 |
components[f'batch_size_{prefix}'] = gr.Slider(label="Batch Size", minimum=1, maximum=16, step=1, value=1)
|
| 89 |
with gr.Row():
|
| 90 |
-
components[f'clip_skip_{prefix}'] = gr.Slider(label="Clip Skip", minimum=1, maximum=2, step=1, value=1, visible=False, interactive=True)
|
| 91 |
components[f'guidance_{prefix}'] = gr.Slider(label="Guidance (FLUX)", minimum=1.0, maximum=10.0, step=0.1, value=3.5, visible=False, interactive=True)
|
| 92 |
components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60s, Max: 120s", info="Optional: Set how long to reserve the GPU.")
|
| 93 |
|
|
|
|
| 87 |
components[f'seed_{prefix}'] = gr.Number(label="Seed (-1 for random)", value=-1, precision=0)
|
| 88 |
components[f'batch_size_{prefix}'] = gr.Slider(label="Batch Size", minimum=1, maximum=16, step=1, value=1)
|
| 89 |
with gr.Row():
|
|
|
|
| 90 |
components[f'guidance_{prefix}'] = gr.Slider(label="Guidance (FLUX)", minimum=1.0, maximum=10.0, step=0.1, value=3.5, visible=False, interactive=True)
|
| 91 |
components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60s, Max: 120s", info="Optional: Set how long to reserve the GPU.")
|
| 92 |
|
ui/shared/outpaint_ui.py
CHANGED
|
@@ -73,7 +73,6 @@ def create_ui():
|
|
| 73 |
components[f'seed_{prefix}'] = gr.Number(label="Seed (-1 for random)", value=-1, precision=0)
|
| 74 |
components[f'batch_size_{prefix}'] = gr.Slider(label="Batch Size", minimum=1, maximum=16, step=1, value=1)
|
| 75 |
with gr.Row():
|
| 76 |
-
components[f'clip_skip_{prefix}'] = gr.Slider(label="Clip Skip", minimum=1, maximum=2, step=1, value=1, visible=False, interactive=True)
|
| 77 |
components[f'guidance_{prefix}'] = gr.Slider(label="Guidance (FLUX)", minimum=1.0, maximum=10.0, step=0.1, value=3.5, visible=False, interactive=True)
|
| 78 |
components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60s, Max: 120s", info="Optional: Set how long to reserve the GPU.")
|
| 79 |
|
|
|
|
| 73 |
components[f'seed_{prefix}'] = gr.Number(label="Seed (-1 for random)", value=-1, precision=0)
|
| 74 |
components[f'batch_size_{prefix}'] = gr.Slider(label="Batch Size", minimum=1, maximum=16, step=1, value=1)
|
| 75 |
with gr.Row():
|
|
|
|
| 76 |
components[f'guidance_{prefix}'] = gr.Slider(label="Guidance (FLUX)", minimum=1.0, maximum=10.0, step=0.1, value=3.5, visible=False, interactive=True)
|
| 77 |
components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60s, Max: 120s", info="Optional: Set how long to reserve the GPU.")
|
| 78 |
|
ui/shared/ui_components.py
CHANGED
|
@@ -114,7 +114,6 @@ def create_base_parameter_ui(prefix, defaults=None):
|
|
| 114 |
components[f'seed_{prefix}'] = gr.Number(label="Seed (-1 for random)", value=-1, precision=0)
|
| 115 |
components[f'batch_size_{prefix}'] = gr.Slider(label="Batch Size", minimum=1, maximum=16, step=1, value=1)
|
| 116 |
with gr.Row():
|
| 117 |
-
components[f'clip_skip_{prefix}'] = gr.Slider(label="Clip Skip", minimum=1, maximum=2, step=1, value=1, visible=False, interactive=True)
|
| 118 |
components[f'guidance_{prefix}'] = gr.Slider(label="Guidance (FLUX)", minimum=1.0, maximum=10.0, step=0.1, value=3.5, visible=False, interactive=True)
|
| 119 |
components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60s, Max: 120s", info="Optional: Set how long to reserve the GPU.")
|
| 120 |
|
|
|
|
| 114 |
components[f'seed_{prefix}'] = gr.Number(label="Seed (-1 for random)", value=-1, precision=0)
|
| 115 |
components[f'batch_size_{prefix}'] = gr.Slider(label="Batch Size", minimum=1, maximum=16, step=1, value=1)
|
| 116 |
with gr.Row():
|
|
|
|
| 117 |
components[f'guidance_{prefix}'] = gr.Slider(label="Guidance (FLUX)", minimum=1.0, maximum=10.0, step=0.1, value=3.5, visible=False, interactive=True)
|
| 118 |
components[f'zero_gpu_{prefix}'] = gr.Number(label="ZeroGPU Duration (s)", value=None, placeholder="Default: 60s, Max: 120s", info="Optional: Set how long to reserve the GPU.")
|
| 119 |
|
yaml/chain_features.yaml
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
lora:
|
| 5 |
chains: lora
|
| 6 |
display_name: "LoRA Fine-tuning Injector"
|
| 7 |
-
description: "Injects LoRA weights into UNet/DiT model and CLIP text encoder for custom style, character, or domain adaptation."
|
| 8 |
supported_tasks:
|
| 9 |
- txt2img
|
| 10 |
- img2img
|
|
@@ -12,17 +12,17 @@ lora:
|
|
| 12 |
- outpaint
|
| 13 |
- hires_fix
|
| 14 |
max_count: 5
|
| 15 |
-
usage_guideline: "Specify source ('Civitai' or 'Hugging Face')
|
| 16 |
parameters_schema:
|
| 17 |
type: object
|
| 18 |
properties:
|
| 19 |
source:
|
| 20 |
type: string
|
| 21 |
enum: ["Civitai", "Hugging Face"]
|
| 22 |
-
description: "Download source for the LoRA model. Use 'Civitai' to download by Version ID, or 'Hugging Face' to download by repo path."
|
| 23 |
lora_value:
|
| 24 |
type: string
|
| 25 |
-
description: "For Civitai: the Version ID (
|
| 26 |
scale:
|
| 27 |
type: number
|
| 28 |
default: 1.0
|
|
|
|
| 4 |
lora:
|
| 5 |
chains: lora
|
| 6 |
display_name: "LoRA Fine-tuning Injector"
|
| 7 |
+
description: "Injects LoRA weights into UNet/DiT model and CLIP text encoder for custom style, character, or domain adaptation. Note: For Civitai, specify the Version ID (modelVersionId) instead of the main Model ID."
|
| 8 |
supported_tasks:
|
| 9 |
- txt2img
|
| 10 |
- img2img
|
|
|
|
| 12 |
- outpaint
|
| 13 |
- hires_fix
|
| 14 |
max_count: 5
|
| 15 |
+
usage_guideline: "Specify source ('Civitai' or 'Hugging Face'). For Civitai, provide lora_value as the Version ID (modelVersionId). For Hugging Face, provide HF repo file path. Scale (0.0~2.0) controls weight strength."
|
| 16 |
parameters_schema:
|
| 17 |
type: object
|
| 18 |
properties:
|
| 19 |
source:
|
| 20 |
type: string
|
| 21 |
enum: ["Civitai", "Hugging Face"]
|
| 22 |
+
description: "Download source for the LoRA model. Use 'Civitai' to download by Version ID (modelVersionId), or 'Hugging Face' to download by repo file path."
|
| 23 |
lora_value:
|
| 24 |
type: string
|
| 25 |
+
description: "For Civitai: the Version ID (modelVersionId). For Hugging Face: repo_id/filename.extension or repo_id/folder_path/filename.extension."
|
| 26 |
scale:
|
| 27 |
type: number
|
| 28 |
default: 1.0
|