CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-webuiapi

Python API client for AUTOMATIC1111/stable-diffusion-webui enabling programmatic Stable Diffusion image generation

Overview
Eval results
Files

extensions.mddocs/

Extensions

Integration with popular WebUI extensions including ADetailer for face enhancement, AnimateDiff for video generation, face swapping capabilities, and specialized processing tools. These extensions provide advanced functionality beyond basic image generation.

Capabilities

ADetailer (After Detailer)

Automatic detection and enhancement of faces, hands, and other objects with dedicated inpainting models.

class ADetailer:
    """Configuration for ADetailer face/object enhancement."""
    
    def __init__(
        self,
        ad_model: str = "None",
        ad_confidence: float = 0.3,
        ad_mask_k_largest: int = 0,
        ad_mask_min_ratio: float = 0.0,
        ad_mask_max_ratio: float = 1.0,
        ad_x_offset: int = 0,
        ad_y_offset: int = 0,
        ad_dilate_erode: int = 4,
        ad_mask_merge_invert: str = "None",
        ad_mask_blur: int = 4,
        ad_denoising_strength: float = 0.4,
        ad_inpaint_only_masked: bool = True,
        ad_inpaint_only_masked_padding: int = 32,
        ad_use_inpaint_width_height: bool = False,
        ad_inpaint_width: int = 512,
        ad_inpaint_height: int = 512,
        ad_use_steps: bool = False,
        ad_steps: int = 28,
        ad_use_cfg_scale: bool = False,
        ad_cfg_scale: float = 7.0,
        ad_use_checkpoint: bool = False,
        ad_checkpoint: str = "Use same checkpoint",
        ad_use_vae: bool = False,
        ad_vae: str = "Use same VAE",
        ad_use_sampler: bool = False,
        ad_sampler: str = "DPM++ 2M Karras",
        ad_use_noise_multiplier: bool = False,
        ad_noise_multiplier: float = 1.0,
        ad_use_clip_skip: bool = False,
        ad_clip_skip: int = 1,
        ad_restore_face: bool = False,
        ad_controlnet_model: str = "None",
        ad_controlnet_module: str = "None",
        ad_controlnet_weight: float = 1.0,
        ad_controlnet_guidance_start: float = 0.0,
        ad_controlnet_guidance_end: float = 1.0,
        **kwargs
    ):
        """
        Initialize After Detailer configuration.

        Parameters:
        - ad_model: Detection model ("face_yolov8n.pt", "hand_yolov8n.pt", etc.)
        - ad_confidence: Detection confidence threshold (0.0-1.0)
        - ad_mask_k_largest: Keep only K largest detections (0 = all)
        - ad_mask_min_ratio: Minimum mask area ratio
        - ad_mask_max_ratio: Maximum mask area ratio
        - ad_x_offset, ad_y_offset: Mask position adjustments
        - ad_dilate_erode: Mask dilation/erosion amount
        - ad_mask_merge_invert: Mask merge mode ("None", "Merge", "Merge and Invert")
        - ad_mask_blur: Mask edge blur amount
        - ad_denoising_strength: Inpainting strength (0.0-1.0)
        - ad_inpaint_only_masked: Inpaint only masked area
        - ad_inpaint_only_masked_padding: Padding around masked area
        - ad_use_inpaint_width_height: Use custom inpainting dimensions
        - ad_inpaint_width, ad_inpaint_height: Custom inpainting dimensions
        - ad_use_steps: Override generation steps
        - ad_steps: Custom step count
        - ad_use_cfg_scale: Override CFG scale
        - ad_cfg_scale: Custom CFG scale
        - ad_use_checkpoint: Use different checkpoint for inpainting
        - ad_checkpoint: Checkpoint name for inpainting
        - ad_use_vae: Use different VAE
        - ad_vae: VAE name
        - ad_use_sampler: Use different sampler
        - ad_sampler: Sampler name for inpainting
        - ad_use_noise_multiplier: Override noise multiplier
        - ad_noise_multiplier: Noise multiplier value
        - ad_use_clip_skip: Override CLIP skip
        - ad_clip_skip: CLIP skip value
        - ad_restore_face: Apply face restoration
        - ad_controlnet_model: ControlNet model for inpainting
        - ad_controlnet_module: ControlNet module for inpainting
        - ad_controlnet_weight: ControlNet weight
        - ad_controlnet_guidance_start: ControlNet guidance start
        - ad_controlnet_guidance_end: ControlNet guidance end
        """

    def to_dict(self) -> Dict:
        """Convert to dictionary format for API submission."""

AnimateDiff

Video and animation generation capabilities for creating animated sequences.

class AnimateDiff:
    """Configuration for AnimateDiff video generation."""
    
    def __init__(
        self,
        model: str = "mm_sd15_v3.safetensors",
        fps: int = 8,
        video_length: int = 16,
        closed_loop: str = "N",
        batch_size: int = 16,
        stride: int = 1,
        overlap: int = 4,
        format: str = "GIF",
        interp: str = "Off",
        interp_x: int = 10,
        video_source_path: str = "",
        video_path: str = "",
        latent_power: float = 1.0,
        latent_scale: float = 1.0,
        last_frame: str = None,
        latent_power_last: float = 1.0,
        latent_scale_last: float = 1.0,
        request_id: str = "",
        enable: bool = True,
        **kwargs
    ):
        """
        Initialize AnimateDiff configuration.

        Parameters:
        - model: AnimateDiff model name ("mm_sd_v14.ckpt", "mm_sd_v15.ckpt", etc.)
        - fps: Output video frame rate
        - video_length: Number of frames to generate
        - closed_loop: Loop mode ("N", "R+P", "R-P", "A")
        - batch_size: Batch size for processing
        - stride: Frame stride for processing
        - overlap: Frame overlap amount
        - format: Output format ("GIF", "MP4", "PNG", "TXT")
        - interp: Interpolation mode ("Off", "FILM")
        - interp_x: Interpolation multiplier
        - video_source_path: Source video path for img2vid
        - video_path: Output video path
        - latent_power: Latent space power adjustment
        - latent_scale: Latent space scale adjustment
        - last_frame: Last frame handling
        - latent_power_last: Last frame latent power
        - latent_scale_last: Last frame latent scale
        - request_id: Request identifier
        - enable: Enable AnimateDiff processing
        """

    def to_dict(self, is_img2img: bool = False) -> Dict:
        """Convert to dictionary format for API submission."""

Face Swapping Extensions

Advanced face swapping capabilities using ReActor and Roop extensions.

class ReActor:
    """Configuration for ReActor face swapping extension."""
    
    def __init__(
        self,
        image: str = "",
        source_faces_index: List[int] = None,
        target_faces_index: List[int] = None,
        model: str = "inswapper_128.onnx",
        face_restorer: str = "CodeFormer",
        face_restorer_visibility: float = 1.0,
        face_restorer_weight: float = 0.5,
        upscaler: str = "None",
        upscaler_scale: float = 1.0,
        upscaler_visibility: float = 1.0,
        swap_in_source: bool = True,
        swap_in_generated: bool = True,
        console_log: bool = False,
        gender_detect_source: int = 0,
        gender_detect_target: int = 0,
        save_original: bool = False,
        codeformer_weight: float = 0.8,
        source_hash_check: bool = True,
        target_hash_check: bool = False,
        system: str = "CUDA",
        device: str = "CUDA",
        mask_face: bool = False,
        select_source: int = 0,
        face_model: str = None,
        source_folder: str = None,
        **kwargs
    ):
        """
        Initialize ReActor face swapping configuration.

        Parameters:
        - image: Source face image path or base64
        - source_faces_index: List of source face indices to use
        - target_faces_index: List of target face indices to replace
        - model: Face swapping model ("inswapper_128.onnx", etc.)
        - face_restorer: Face restoration model ("CodeFormer", "GFPGAN")
        - face_restorer_visibility: Face restorer strength (0.0-1.0)
        - face_restorer_weight: Face restorer blend weight
        - upscaler: Post-processing upscaler
        - upscaler_scale: Upscaling factor
        - upscaler_visibility: Upscaler blend strength
        - swap_in_source: Apply swapping to source image
        - swap_in_generated: Apply swapping to generated images
        - console_log: Enable console logging
        - gender_detect_source: Source gender detection (0=No, 1=Female, 2=Male)
        - gender_detect_target: Target gender detection
        - save_original: Save original before swapping
        - codeformer_weight: CodeFormer processing weight
        - source_hash_check: Verify source face hash
        - target_hash_check: Verify target face hash
        - system: Processing system ("CUDA", "CPU")
        - device: Processing device
        - mask_face: Apply face masking
        - select_source: Source selection mode
        - face_model: Specific face model to use
        - source_folder: Source images folder path
        """

    def to_dict(self) -> List:
        """Convert to list format for API submission."""

class Roop:
    """Configuration for Roop face swapping extension."""
    
    def __init__(
        self,
        image: str = "",
        faces_index: str = "0",
        model: str = "inswapper_128.onnx",
        face_restorer: str = "CodeFormer",
        face_restorer_visibility: float = 1.0,
        codeformer_weight: float = 0.8,
        swap_in_source: bool = True,
        swap_in_generated: bool = True,
        console_log: bool = False,
        gender_detect: int = 0,
        source_hash_check: bool = True,
        target_hash_check: bool = False,
        **kwargs
    ):
        """
        Initialize Roop face swapping configuration.

        Similar to ReActor but with simplified interface.
        """

    def to_dict(self) -> List:
        """Convert to list format for API submission."""

Self Attention Guidance (SAG)

Improve image quality and coherence using Self Attention Guidance.

class Sag:
    """Configuration for Self Attention Guidance."""
    
    def __init__(
        self,
        sag_scale: float = 0.75,
        sag_mask_threshold: float = 1.0,
        sag_tensor_dtype: str = "fp16"
    ):
        """
        Initialize SAG configuration.

        Parameters:
        - sag_scale: SAG guidance scale (0.0-1.0)
        - sag_mask_threshold: Mask threshold for attention
        - sag_tensor_dtype: Tensor precision ("fp16", "fp32")
        """

    def to_dict(self) -> List:
        """Convert to list format for API submission."""

Usage Examples:

import webuiapi
from PIL import Image

api = webuiapi.WebUIApi()

# ADetailer for automatic face enhancement
adetailer_config = webuiapi.ADetailer(
    ad_model="None",
    ad_confidence=0.3,
    ad_denoising_strength=0.4,
    ad_inpaint_only_masked=True,
    ad_use_steps=True,
    ad_steps=20,
    ad_restore_face=True
)

# Generate portrait with automatic face enhancement
result = api.txt2img(
    prompt="professional headshot, detailed face, studio lighting",
    width=512,
    height=768,
    alwayson_scripts={
        "ADetailer": adetailer_config.to_dict()
    }
)

result.image.save("enhanced_portrait.png")

# AnimateDiff for video generation
animatediff_config = webuiapi.AnimateDiff(
    model="mm_sd_v15.ckpt",
    fps=12,
    video_length=24,
    format="MP4",
    enable=True
)

# Generate animated sequence
result = api.txt2img(
    prompt="a cat walking, smooth animation, high quality",
    width=512,
    height=512,
    batch_size=1,
    alwayson_scripts={
        "AnimateDiff": animatediff_config.to_dict()
    }
)

# Face swapping with ReActor
source_face = Image.open("source_face.jpg")
source_b64 = webuiapi.raw_b64_img(source_face)

reactor_config = webuiapi.ReActor(
    image=source_b64,
    source_faces_index=[0],
    target_faces_index=[0],
    face_restorer="CodeFormer",
    face_restorer_visibility=0.8,
    swap_in_generated=True
)

# Generate image with face swap
result = api.txt2img(
    prompt="person in medieval costume, detailed face",
    width=512,
    height=768,
    alwayson_scripts={
        "ReActor": reactor_config.to_dict()
    }
)

result.image.save("face_swapped.png")

# Combine multiple extensions
adetailer_config = webuiapi.ADetailer(
    ad_model="None",
    ad_denoising_strength=0.3
)

sag_config = webuiapi.Sag(
    sag_scale=0.75,
    sag_mask_threshold=1.0
)

# Generate with multiple extensions
result = api.txt2img(
    prompt="cinematic portrait, dramatic lighting",
    width=768,
    height=768,
    steps=30,
    alwayson_scripts={
        "ADetailer": adetailer_config.to_dict(),
        "SAG": sag_config.to_dict()
    }
)

result.image.save("multi_extension_result.png")

Extension Interface Classes

Model Keywords Interface

class ModelKeywordInterface:
    """Interface for model keyword generation."""
    
    def get_keywords(self, model_name: str) -> ModelKeywordResult:
        """Get keywords associated with a model."""

class ModelKeywordResult:
    """Result from model keyword lookup."""
    keywords: List[str]  # Associated keywords
    model: str  # Model name
    oldhash: str  # Model hash
    match_source: str  # Source of keyword match

Specialized Processing Interfaces

class RemBGInterface:
    """Background removal interface."""
    
    def rembg(
        self,
        input_image: str,
        model: str = "u2net",
        return_mask: bool = False,
        alpha_matting: bool = False
    ) -> Dict:
        """Remove background from image."""

class InstructPix2PixInterface:
    """InstructPix2Pix instruction-based editing."""
    
    def img2img(
        self,
        prompt: str,
        images: List[Image.Image],
        **kwargs
    ) -> WebUIApiResult:
        """Edit images using natural language instructions."""

Types

class ADetailer:
    """ADetailer configuration with 40+ parameters for face/object enhancement."""

class AnimateDiff:
    """AnimateDiff configuration for video generation with timing and quality controls."""

class ReActor:
    """ReActor face swapping configuration with advanced options."""

class Roop:
    """Roop face swapping configuration with simplified interface."""

class Sag:
    """Self Attention Guidance configuration for improved coherence."""

Install with Tessl CLI

npx tessl i tessl/pypi-webuiapi

docs

configuration.md

controlnet.md

extensions.md

image-generation.md

image-processing.md

index.md

interfaces.md

model-management.md

tile.json