Files
vnassets/vnassets/cli.py
Michele Rossi 9564202e6d feat: add ComfyUI-style prompt weighting via compel
- Support (word:weight), [word], ((nested)) syntax
- Support BREAK for conditioning chunking (.and() translation)
- Use CompelForSDXL (modern API, avoids deprecation)
- Add --raw flag to bypass weighting and fall back to plain encoding
- Update README with Prompt Syntax section and examples
- Add docs/comfyui-prompt-style.md with design doc
2026-07-07 16:16:54 +02:00

82 lines
2.7 KiB
Python

"""VNAsset — Visual Novel Asset Pipeline CLI."""
import click
from .edit import edit
from .generate import generate
def _parse_seed(ctx, param, value):
if value is None or value == "":
return None
if value.lower() == "random":
return None
try:
return int(value)
except ValueError:
raise click.BadParameter("seed must be an integer or 'random'")
@click.group()
def main():
"""VNAsset — fast CLI pipeline for visual novel image assets."""
@main.command()
@click.option("--checkpoint", required=True, help="Path to SDXL checkpoint (.safetensors)")
@click.option("--prompt", required=True, help="Positive prompt")
@click.option("--negative-prompt", default="", help="Negative prompt")
@click.option("--width", default=1024, type=int)
@click.option("--height", default=1024, type=int)
@click.option("--steps", default=20, type=int)
@click.option("--cfg", default=4.5, type=float)
@click.option(
"--seed", default="random", callback=_parse_seed,
help="RNG seed (integer or 'random')",
)
@click.option("--output", default="output.png", help="Output image path")
@click.option(
"--raw", is_flag=True,
help="Disable ComfyUI-style prompt weighting (use plain diffusers encoding)",
)
def generate_cmd(checkpoint, prompt, negative_prompt, width, height, steps, cfg, seed, output, raw):
"""Generate an image from an SDXL checkpoint."""
generate(
checkpoint_path=checkpoint,
prompt=prompt,
negative_prompt=negative_prompt,
width=width,
height=height,
steps=steps,
cfg=cfg,
seed=seed,
output_path=output,
raw=raw,
)
@main.command()
@click.option("--model", required=True, help="Path to Qwen Image Edit diffusion model (.safetensors)")
@click.option("--input", "input_path", required=True, help="Input image to edit")
@click.option("--prompt", required=True, help="Edit instruction")
@click.option("--steps", default=20, type=int, help="Inference steps")
@click.option("--cfg", default=4.0, type=float, help="CFG scale")
@click.option(
"--seed", default="random", callback=_parse_seed,
help="RNG seed (integer or 'random')",
)
@click.option("--output", default="output.png", help="Output image path")
@click.option("--lora", "lora_path", default=None,
help="Path to LoRA .safetensors (e.g. Lightning 4-step LoRA)")
def edit_cmd(model, input_path, prompt, steps, cfg, seed, output, lora_path):
"""Edit an image using Qwen Image Edit."""
edit(
model_path=model,
input_path=input_path,
prompt=prompt,
steps=steps,
cfg=cfg,
seed=seed,
output_path=output,
lora_path=lora_path,
)