💬 Commit message: Update 2026-02-21 05:21:26, 3 files, 126 lines

📁 Files changed: 3
📝 Lines changed: 126

  • .gitignore
  • cli.py
  • comfyui.py
This commit is contained in:
Adam Ladachowski
2026-02-21 05:21:26 +01:00
parent 5da4005c4a
commit 987ce1a3a1
3 changed files with 62 additions and 62 deletions
+1
View File
@@ -13,3 +13,4 @@ wheels/
.coverage .coverage
htmlcov/ htmlcov/
coverage.xml coverage.xml
models.db
+13 -20
View File
@@ -1218,12 +1218,7 @@ def comfy_generate( # noqa: PLR0915
truncated = enhanced_negative[:80] + "..." if len(enhanced_negative) > 80 else enhanced_negative # noqa: PLR2004 truncated = enhanced_negative[:80] + "..." if len(enhanced_negative) > 80 else enhanced_negative # noqa: PLR2004
console.print(f"[dim]Enhanced negative: {truncated}[/dim]") console.print(f"[dim]Enhanced negative: {truncated}[/dim]")
for i in range(count): # Use native ComfyUI batching - single workflow generates all images
current_seed = base_seed + i if seed >= 0 else -1 # Increment seed or use random each time
if count > 1 and not json_output:
console.print(f"\n[cyan]Generating image {i + 1}/{count}...[/cyan]")
result = generate_image( result = generate_image(
prompt=enhanced_prompt, prompt=enhanced_prompt,
url=url, url=url,
@@ -1233,34 +1228,32 @@ def comfy_generate( # noqa: PLR0915
height=height, height=height,
steps=steps, steps=steps,
cfg=cfg, cfg=cfg,
seed=current_seed, seed=base_seed,
sampler=sampler, sampler=sampler,
scheduler=scheduler, scheduler=scheduler,
console=console if not json_output else None, console=console if not json_output else None,
lora_name=lora, lora_name=lora,
lora_strength=lora_strength, lora_strength=lora_strength,
batch_size=count,
) )
if not result: if not result:
if json_output: if json_output:
all_results.append({"success": False, "index": i, "errors": {"generation": "Failed to generate"}}) all_results.append({"success": False, "index": 0, "errors": {"generation": "Failed to generate"}})
else: else:
console.print(f"[red]Generation {i + 1} failed[/red]") console.print("[red]Generation failed[/red]")
continue elif not result.success:
if not result.success:
if json_output: if json_output:
all_results.append({"success": False, "index": i, "errors": result.node_errors}) all_results.append({"success": False, "index": 0, "errors": result.node_errors})
else: else:
console.print(f"[red]Generation {i + 1} failed[/red]") console.print("[red]Generation failed[/red]")
for node_id, errors in result.node_errors.items(): for node_id, errors in result.node_errors.items():
console.print(f" [yellow]Node {node_id}:[/yellow] {errors}") console.print(f" [yellow]Node {node_id}:[/yellow] {errors}")
continue else:
# Save all output images
# Save output if requested for i, img_path in enumerate(result.images):
saved_path: Path | None = None saved_path: Path | None = None
if output and result.images: if output:
img_path = result.images[0]
img_data = get_image(str(img_path), url=url) img_data = get_image(str(img_path), url=url)
if img_data: if img_data:
save_path = output if count == 1 else output.parent / f"{output.stem}_{i + 1:03d}{output.suffix}" save_path = output if count == 1 else output.parent / f"{output.stem}_{i + 1:03d}{output.suffix}"
@@ -1277,7 +1270,7 @@ def comfy_generate( # noqa: PLR0915
"success": True, "success": True,
"index": i, "index": i,
"prompt_id": result.prompt_id, "prompt_id": result.prompt_id,
"images": [str(img) for img in result.images], "image": str(img_path),
"saved": str(saved_path) if saved_path else None, "saved": str(saved_path) if saved_path else None,
} }
) )
+7 -1
View File
@@ -596,6 +596,7 @@ def _build_workflow(
scheduler: str = "normal", scheduler: str = "normal",
lora_name: str | None = None, lora_name: str | None = None,
lora_strength: float = 1.0, lora_strength: float = 1.0,
batch_size: int = 1,
) -> dict[str, Any]: ) -> dict[str, Any]:
"""Build a text-to-image workflow from parameters. """Build a text-to-image workflow from parameters.
@@ -612,6 +613,7 @@ def _build_workflow(
scheduler: Scheduler name scheduler: Scheduler name
lora_name: LoRA model filename (optional) lora_name: LoRA model filename (optional)
lora_strength: LoRA strength (default 1.0) lora_strength: LoRA strength (default 1.0)
batch_size: Number of images to generate in one workflow (default 1)
Returns: Returns:
ComfyUI workflow dict ComfyUI workflow dict
@@ -632,9 +634,10 @@ def _build_workflow(
if model: if model:
workflow["4"]["inputs"]["ckpt_name"] = model workflow["4"]["inputs"]["ckpt_name"] = model
# Set dimensions # Set dimensions and batch size
workflow["5"]["inputs"]["width"] = width workflow["5"]["inputs"]["width"] = width
workflow["5"]["inputs"]["height"] = height workflow["5"]["inputs"]["height"] = height
workflow["5"]["inputs"]["batch_size"] = batch_size
# Set prompts # Set prompts
workflow["6"]["inputs"]["text"] = prompt workflow["6"]["inputs"]["text"] = prompt
@@ -679,6 +682,7 @@ def generate_image(
timeout: float = 600.0, timeout: float = 600.0,
lora_name: str | None = None, lora_name: str | None = None,
lora_strength: float = 1.0, lora_strength: float = 1.0,
batch_size: int = 1,
) -> GenerationResult | None: ) -> GenerationResult | None:
"""Generate an image using a simple text-to-image workflow. """Generate an image using a simple text-to-image workflow.
@@ -699,6 +703,7 @@ def generate_image(
timeout: Maximum wait time in seconds timeout: Maximum wait time in seconds
lora_name: LoRA model filename (optional) lora_name: LoRA model filename (optional)
lora_strength: LoRA strength (default 1.0) lora_strength: LoRA strength (default 1.0)
batch_size: Number of images to generate in one workflow (default 1)
Returns: Returns:
GenerationResult with image paths, or None if generation failed GenerationResult with image paths, or None if generation failed
@@ -731,6 +736,7 @@ def generate_image(
scheduler=scheduler, scheduler=scheduler,
lora_name=lora_name, lora_name=lora_name,
lora_strength=lora_strength, lora_strength=lora_strength,
batch_size=batch_size,
) )
# Run workflow # Run workflow