💬 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:
@@ -13,3 +13,4 @@ wheels/
|
||||
.coverage
|
||||
htmlcov/
|
||||
coverage.xml
|
||||
models.db
|
||||
|
||||
+13
-20
@@ -1218,12 +1218,7 @@ def comfy_generate( # noqa: PLR0915
|
||||
truncated = enhanced_negative[:80] + "..." if len(enhanced_negative) > 80 else enhanced_negative # noqa: PLR2004
|
||||
console.print(f"[dim]Enhanced negative: {truncated}[/dim]")
|
||||
|
||||
for i in range(count):
|
||||
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]")
|
||||
|
||||
# Use native ComfyUI batching - single workflow generates all images
|
||||
result = generate_image(
|
||||
prompt=enhanced_prompt,
|
||||
url=url,
|
||||
@@ -1233,34 +1228,32 @@ def comfy_generate( # noqa: PLR0915
|
||||
height=height,
|
||||
steps=steps,
|
||||
cfg=cfg,
|
||||
seed=current_seed,
|
||||
seed=base_seed,
|
||||
sampler=sampler,
|
||||
scheduler=scheduler,
|
||||
console=console if not json_output else None,
|
||||
lora_name=lora,
|
||||
lora_strength=lora_strength,
|
||||
batch_size=count,
|
||||
)
|
||||
|
||||
if not result:
|
||||
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:
|
||||
console.print(f"[red]Generation {i + 1} failed[/red]")
|
||||
continue
|
||||
|
||||
if not result.success:
|
||||
console.print("[red]Generation failed[/red]")
|
||||
elif not result.success:
|
||||
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:
|
||||
console.print(f"[red]Generation {i + 1} failed[/red]")
|
||||
console.print("[red]Generation failed[/red]")
|
||||
for node_id, errors in result.node_errors.items():
|
||||
console.print(f" [yellow]Node {node_id}:[/yellow] {errors}")
|
||||
continue
|
||||
|
||||
# Save output if requested
|
||||
else:
|
||||
# Save all output images
|
||||
for i, img_path in enumerate(result.images):
|
||||
saved_path: Path | None = None
|
||||
if output and result.images:
|
||||
img_path = result.images[0]
|
||||
if output:
|
||||
img_data = get_image(str(img_path), url=url)
|
||||
if img_data:
|
||||
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,
|
||||
"index": i,
|
||||
"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,
|
||||
}
|
||||
)
|
||||
|
||||
+7
-1
@@ -596,6 +596,7 @@ def _build_workflow(
|
||||
scheduler: str = "normal",
|
||||
lora_name: str | None = None,
|
||||
lora_strength: float = 1.0,
|
||||
batch_size: int = 1,
|
||||
) -> dict[str, Any]:
|
||||
"""Build a text-to-image workflow from parameters.
|
||||
|
||||
@@ -612,6 +613,7 @@ def _build_workflow(
|
||||
scheduler: Scheduler name
|
||||
lora_name: LoRA model filename (optional)
|
||||
lora_strength: LoRA strength (default 1.0)
|
||||
batch_size: Number of images to generate in one workflow (default 1)
|
||||
|
||||
Returns:
|
||||
ComfyUI workflow dict
|
||||
@@ -632,9 +634,10 @@ def _build_workflow(
|
||||
if model:
|
||||
workflow["4"]["inputs"]["ckpt_name"] = model
|
||||
|
||||
# Set dimensions
|
||||
# Set dimensions and batch size
|
||||
workflow["5"]["inputs"]["width"] = width
|
||||
workflow["5"]["inputs"]["height"] = height
|
||||
workflow["5"]["inputs"]["batch_size"] = batch_size
|
||||
|
||||
# Set prompts
|
||||
workflow["6"]["inputs"]["text"] = prompt
|
||||
@@ -679,6 +682,7 @@ def generate_image(
|
||||
timeout: float = 600.0,
|
||||
lora_name: str | None = None,
|
||||
lora_strength: float = 1.0,
|
||||
batch_size: int = 1,
|
||||
) -> GenerationResult | None:
|
||||
"""Generate an image using a simple text-to-image workflow.
|
||||
|
||||
@@ -699,6 +703,7 @@ def generate_image(
|
||||
timeout: Maximum wait time in seconds
|
||||
lora_name: LoRA model filename (optional)
|
||||
lora_strength: LoRA strength (default 1.0)
|
||||
batch_size: Number of images to generate in one workflow (default 1)
|
||||
|
||||
Returns:
|
||||
GenerationResult with image paths, or None if generation failed
|
||||
@@ -731,6 +736,7 @@ def generate_image(
|
||||
scheduler=scheduler,
|
||||
lora_name=lora_name,
|
||||
lora_strength=lora_strength,
|
||||
batch_size=batch_size,
|
||||
)
|
||||
|
||||
# Run workflow
|
||||
|
||||
Reference in New Issue
Block a user