💬 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
|
.coverage
|
||||||
htmlcov/
|
htmlcov/
|
||||||
coverage.xml
|
coverage.xml
|
||||||
|
models.db
|
||||||
|
|||||||
+54
-61
@@ -1218,69 +1218,62 @@ 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
|
result = generate_image(
|
||||||
|
prompt=enhanced_prompt,
|
||||||
|
url=url,
|
||||||
|
negative_prompt=enhanced_negative,
|
||||||
|
model=model,
|
||||||
|
width=width,
|
||||||
|
height=height,
|
||||||
|
steps=steps,
|
||||||
|
cfg=cfg,
|
||||||
|
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 count > 1 and not json_output:
|
if not result:
|
||||||
console.print(f"\n[cyan]Generating image {i + 1}/{count}...[/cyan]")
|
if json_output:
|
||||||
|
all_results.append({"success": False, "index": 0, "errors": {"generation": "Failed to generate"}})
|
||||||
|
else:
|
||||||
|
console.print("[red]Generation failed[/red]")
|
||||||
|
elif not result.success:
|
||||||
|
if json_output:
|
||||||
|
all_results.append({"success": False, "index": 0, "errors": result.node_errors})
|
||||||
|
else:
|
||||||
|
console.print("[red]Generation failed[/red]")
|
||||||
|
for node_id, errors in result.node_errors.items():
|
||||||
|
console.print(f" [yellow]Node {node_id}:[/yellow] {errors}")
|
||||||
|
else:
|
||||||
|
# Save all output images
|
||||||
|
for i, img_path in enumerate(result.images):
|
||||||
|
saved_path: Path | None = None
|
||||||
|
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}"
|
||||||
|
save_path.write_bytes(img_data)
|
||||||
|
saved_path = save_path
|
||||||
|
all_saved.append(save_path)
|
||||||
|
if not json_output:
|
||||||
|
console.print(f"[green]Saved:[/green] {save_path}")
|
||||||
|
elif not json_output:
|
||||||
|
console.print(f"[yellow]Could not download image: {img_path}[/yellow]")
|
||||||
|
|
||||||
result = generate_image(
|
all_results.append(
|
||||||
prompt=enhanced_prompt,
|
{
|
||||||
url=url,
|
"success": True,
|
||||||
negative_prompt=enhanced_negative,
|
"index": i,
|
||||||
model=model,
|
"prompt_id": result.prompt_id,
|
||||||
width=width,
|
"image": str(img_path),
|
||||||
height=height,
|
"saved": str(saved_path) if saved_path else None,
|
||||||
steps=steps,
|
}
|
||||||
cfg=cfg,
|
)
|
||||||
seed=current_seed,
|
|
||||||
sampler=sampler,
|
|
||||||
scheduler=scheduler,
|
|
||||||
console=console if not json_output else None,
|
|
||||||
lora_name=lora,
|
|
||||||
lora_strength=lora_strength,
|
|
||||||
)
|
|
||||||
|
|
||||||
if not result:
|
|
||||||
if json_output:
|
|
||||||
all_results.append({"success": False, "index": i, "errors": {"generation": "Failed to generate"}})
|
|
||||||
else:
|
|
||||||
console.print(f"[red]Generation {i + 1} failed[/red]")
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not result.success:
|
|
||||||
if json_output:
|
|
||||||
all_results.append({"success": False, "index": i, "errors": result.node_errors})
|
|
||||||
else:
|
|
||||||
console.print(f"[red]Generation {i + 1} 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
|
|
||||||
saved_path: Path | None = None
|
|
||||||
if output and result.images:
|
|
||||||
img_path = result.images[0]
|
|
||||||
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}"
|
|
||||||
save_path.write_bytes(img_data)
|
|
||||||
saved_path = save_path
|
|
||||||
all_saved.append(save_path)
|
|
||||||
if not json_output:
|
|
||||||
console.print(f"[green]Saved:[/green] {save_path}")
|
|
||||||
elif not json_output:
|
|
||||||
console.print(f"[yellow]Could not download image: {img_path}[/yellow]")
|
|
||||||
|
|
||||||
all_results.append(
|
|
||||||
{
|
|
||||||
"success": True,
|
|
||||||
"index": i,
|
|
||||||
"prompt_id": result.prompt_id,
|
|
||||||
"images": [str(img) for img in result.images],
|
|
||||||
"saved": str(saved_path) if saved_path else None,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
if json_output:
|
if json_output:
|
||||||
console.print_json(
|
console.print_json(
|
||||||
|
|||||||
+7
-1
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user