0
# Extensions
1
2
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.
3
4
## Capabilities
5
6
### ADetailer (After Detailer)
7
8
Automatic detection and enhancement of faces, hands, and other objects with dedicated inpainting models.
9
10
```python { .api }
11
class ADetailer:
12
"""Configuration for ADetailer face/object enhancement."""
13
14
def __init__(
15
self,
16
ad_model: str = "None",
17
ad_confidence: float = 0.3,
18
ad_mask_k_largest: int = 0,
19
ad_mask_min_ratio: float = 0.0,
20
ad_mask_max_ratio: float = 1.0,
21
ad_x_offset: int = 0,
22
ad_y_offset: int = 0,
23
ad_dilate_erode: int = 4,
24
ad_mask_merge_invert: str = "None",
25
ad_mask_blur: int = 4,
26
ad_denoising_strength: float = 0.4,
27
ad_inpaint_only_masked: bool = True,
28
ad_inpaint_only_masked_padding: int = 32,
29
ad_use_inpaint_width_height: bool = False,
30
ad_inpaint_width: int = 512,
31
ad_inpaint_height: int = 512,
32
ad_use_steps: bool = False,
33
ad_steps: int = 28,
34
ad_use_cfg_scale: bool = False,
35
ad_cfg_scale: float = 7.0,
36
ad_use_checkpoint: bool = False,
37
ad_checkpoint: str = "Use same checkpoint",
38
ad_use_vae: bool = False,
39
ad_vae: str = "Use same VAE",
40
ad_use_sampler: bool = False,
41
ad_sampler: str = "DPM++ 2M Karras",
42
ad_use_noise_multiplier: bool = False,
43
ad_noise_multiplier: float = 1.0,
44
ad_use_clip_skip: bool = False,
45
ad_clip_skip: int = 1,
46
ad_restore_face: bool = False,
47
ad_controlnet_model: str = "None",
48
ad_controlnet_module: str = "None",
49
ad_controlnet_weight: float = 1.0,
50
ad_controlnet_guidance_start: float = 0.0,
51
ad_controlnet_guidance_end: float = 1.0,
52
**kwargs
53
):
54
"""
55
Initialize After Detailer configuration.
56
57
Parameters:
58
- ad_model: Detection model ("face_yolov8n.pt", "hand_yolov8n.pt", etc.)
59
- ad_confidence: Detection confidence threshold (0.0-1.0)
60
- ad_mask_k_largest: Keep only K largest detections (0 = all)
61
- ad_mask_min_ratio: Minimum mask area ratio
62
- ad_mask_max_ratio: Maximum mask area ratio
63
- ad_x_offset, ad_y_offset: Mask position adjustments
64
- ad_dilate_erode: Mask dilation/erosion amount
65
- ad_mask_merge_invert: Mask merge mode ("None", "Merge", "Merge and Invert")
66
- ad_mask_blur: Mask edge blur amount
67
- ad_denoising_strength: Inpainting strength (0.0-1.0)
68
- ad_inpaint_only_masked: Inpaint only masked area
69
- ad_inpaint_only_masked_padding: Padding around masked area
70
- ad_use_inpaint_width_height: Use custom inpainting dimensions
71
- ad_inpaint_width, ad_inpaint_height: Custom inpainting dimensions
72
- ad_use_steps: Override generation steps
73
- ad_steps: Custom step count
74
- ad_use_cfg_scale: Override CFG scale
75
- ad_cfg_scale: Custom CFG scale
76
- ad_use_checkpoint: Use different checkpoint for inpainting
77
- ad_checkpoint: Checkpoint name for inpainting
78
- ad_use_vae: Use different VAE
79
- ad_vae: VAE name
80
- ad_use_sampler: Use different sampler
81
- ad_sampler: Sampler name for inpainting
82
- ad_use_noise_multiplier: Override noise multiplier
83
- ad_noise_multiplier: Noise multiplier value
84
- ad_use_clip_skip: Override CLIP skip
85
- ad_clip_skip: CLIP skip value
86
- ad_restore_face: Apply face restoration
87
- ad_controlnet_model: ControlNet model for inpainting
88
- ad_controlnet_module: ControlNet module for inpainting
89
- ad_controlnet_weight: ControlNet weight
90
- ad_controlnet_guidance_start: ControlNet guidance start
91
- ad_controlnet_guidance_end: ControlNet guidance end
92
"""
93
94
def to_dict(self) -> Dict:
95
"""Convert to dictionary format for API submission."""
96
```
97
98
### AnimateDiff
99
100
Video and animation generation capabilities for creating animated sequences.
101
102
```python { .api }
103
class AnimateDiff:
104
"""Configuration for AnimateDiff video generation."""
105
106
def __init__(
107
self,
108
model: str = "mm_sd15_v3.safetensors",
109
fps: int = 8,
110
video_length: int = 16,
111
closed_loop: str = "N",
112
batch_size: int = 16,
113
stride: int = 1,
114
overlap: int = 4,
115
format: str = "GIF",
116
interp: str = "Off",
117
interp_x: int = 10,
118
video_source_path: str = "",
119
video_path: str = "",
120
latent_power: float = 1.0,
121
latent_scale: float = 1.0,
122
last_frame: str = None,
123
latent_power_last: float = 1.0,
124
latent_scale_last: float = 1.0,
125
request_id: str = "",
126
enable: bool = True,
127
**kwargs
128
):
129
"""
130
Initialize AnimateDiff configuration.
131
132
Parameters:
133
- model: AnimateDiff model name ("mm_sd_v14.ckpt", "mm_sd_v15.ckpt", etc.)
134
- fps: Output video frame rate
135
- video_length: Number of frames to generate
136
- closed_loop: Loop mode ("N", "R+P", "R-P", "A")
137
- batch_size: Batch size for processing
138
- stride: Frame stride for processing
139
- overlap: Frame overlap amount
140
- format: Output format ("GIF", "MP4", "PNG", "TXT")
141
- interp: Interpolation mode ("Off", "FILM")
142
- interp_x: Interpolation multiplier
143
- video_source_path: Source video path for img2vid
144
- video_path: Output video path
145
- latent_power: Latent space power adjustment
146
- latent_scale: Latent space scale adjustment
147
- last_frame: Last frame handling
148
- latent_power_last: Last frame latent power
149
- latent_scale_last: Last frame latent scale
150
- request_id: Request identifier
151
- enable: Enable AnimateDiff processing
152
"""
153
154
def to_dict(self, is_img2img: bool = False) -> Dict:
155
"""Convert to dictionary format for API submission."""
156
```
157
158
### Face Swapping Extensions
159
160
Advanced face swapping capabilities using ReActor and Roop extensions.
161
162
```python { .api }
163
class ReActor:
164
"""Configuration for ReActor face swapping extension."""
165
166
def __init__(
167
self,
168
image: str = "",
169
source_faces_index: List[int] = None,
170
target_faces_index: List[int] = None,
171
model: str = "inswapper_128.onnx",
172
face_restorer: str = "CodeFormer",
173
face_restorer_visibility: float = 1.0,
174
face_restorer_weight: float = 0.5,
175
upscaler: str = "None",
176
upscaler_scale: float = 1.0,
177
upscaler_visibility: float = 1.0,
178
swap_in_source: bool = True,
179
swap_in_generated: bool = True,
180
console_log: bool = False,
181
gender_detect_source: int = 0,
182
gender_detect_target: int = 0,
183
save_original: bool = False,
184
codeformer_weight: float = 0.8,
185
source_hash_check: bool = True,
186
target_hash_check: bool = False,
187
system: str = "CUDA",
188
device: str = "CUDA",
189
mask_face: bool = False,
190
select_source: int = 0,
191
face_model: str = None,
192
source_folder: str = None,
193
**kwargs
194
):
195
"""
196
Initialize ReActor face swapping configuration.
197
198
Parameters:
199
- image: Source face image path or base64
200
- source_faces_index: List of source face indices to use
201
- target_faces_index: List of target face indices to replace
202
- model: Face swapping model ("inswapper_128.onnx", etc.)
203
- face_restorer: Face restoration model ("CodeFormer", "GFPGAN")
204
- face_restorer_visibility: Face restorer strength (0.0-1.0)
205
- face_restorer_weight: Face restorer blend weight
206
- upscaler: Post-processing upscaler
207
- upscaler_scale: Upscaling factor
208
- upscaler_visibility: Upscaler blend strength
209
- swap_in_source: Apply swapping to source image
210
- swap_in_generated: Apply swapping to generated images
211
- console_log: Enable console logging
212
- gender_detect_source: Source gender detection (0=No, 1=Female, 2=Male)
213
- gender_detect_target: Target gender detection
214
- save_original: Save original before swapping
215
- codeformer_weight: CodeFormer processing weight
216
- source_hash_check: Verify source face hash
217
- target_hash_check: Verify target face hash
218
- system: Processing system ("CUDA", "CPU")
219
- device: Processing device
220
- mask_face: Apply face masking
221
- select_source: Source selection mode
222
- face_model: Specific face model to use
223
- source_folder: Source images folder path
224
"""
225
226
def to_dict(self) -> List:
227
"""Convert to list format for API submission."""
228
229
class Roop:
230
"""Configuration for Roop face swapping extension."""
231
232
def __init__(
233
self,
234
image: str = "",
235
faces_index: str = "0",
236
model: str = "inswapper_128.onnx",
237
face_restorer: str = "CodeFormer",
238
face_restorer_visibility: float = 1.0,
239
codeformer_weight: float = 0.8,
240
swap_in_source: bool = True,
241
swap_in_generated: bool = True,
242
console_log: bool = False,
243
gender_detect: int = 0,
244
source_hash_check: bool = True,
245
target_hash_check: bool = False,
246
**kwargs
247
):
248
"""
249
Initialize Roop face swapping configuration.
250
251
Similar to ReActor but with simplified interface.
252
"""
253
254
def to_dict(self) -> List:
255
"""Convert to list format for API submission."""
256
```
257
258
### Self Attention Guidance (SAG)
259
260
Improve image quality and coherence using Self Attention Guidance.
261
262
```python { .api }
263
class Sag:
264
"""Configuration for Self Attention Guidance."""
265
266
def __init__(
267
self,
268
sag_scale: float = 0.75,
269
sag_mask_threshold: float = 1.0,
270
sag_tensor_dtype: str = "fp16"
271
):
272
"""
273
Initialize SAG configuration.
274
275
Parameters:
276
- sag_scale: SAG guidance scale (0.0-1.0)
277
- sag_mask_threshold: Mask threshold for attention
278
- sag_tensor_dtype: Tensor precision ("fp16", "fp32")
279
"""
280
281
def to_dict(self) -> List:
282
"""Convert to list format for API submission."""
283
```
284
285
**Usage Examples:**
286
287
```python
288
import webuiapi
289
from PIL import Image
290
291
api = webuiapi.WebUIApi()
292
293
# ADetailer for automatic face enhancement
294
adetailer_config = webuiapi.ADetailer(
295
ad_model="None",
296
ad_confidence=0.3,
297
ad_denoising_strength=0.4,
298
ad_inpaint_only_masked=True,
299
ad_use_steps=True,
300
ad_steps=20,
301
ad_restore_face=True
302
)
303
304
# Generate portrait with automatic face enhancement
305
result = api.txt2img(
306
prompt="professional headshot, detailed face, studio lighting",
307
width=512,
308
height=768,
309
alwayson_scripts={
310
"ADetailer": adetailer_config.to_dict()
311
}
312
)
313
314
result.image.save("enhanced_portrait.png")
315
316
# AnimateDiff for video generation
317
animatediff_config = webuiapi.AnimateDiff(
318
model="mm_sd_v15.ckpt",
319
fps=12,
320
video_length=24,
321
format="MP4",
322
enable=True
323
)
324
325
# Generate animated sequence
326
result = api.txt2img(
327
prompt="a cat walking, smooth animation, high quality",
328
width=512,
329
height=512,
330
batch_size=1,
331
alwayson_scripts={
332
"AnimateDiff": animatediff_config.to_dict()
333
}
334
)
335
336
# Face swapping with ReActor
337
source_face = Image.open("source_face.jpg")
338
source_b64 = webuiapi.raw_b64_img(source_face)
339
340
reactor_config = webuiapi.ReActor(
341
image=source_b64,
342
source_faces_index=[0],
343
target_faces_index=[0],
344
face_restorer="CodeFormer",
345
face_restorer_visibility=0.8,
346
swap_in_generated=True
347
)
348
349
# Generate image with face swap
350
result = api.txt2img(
351
prompt="person in medieval costume, detailed face",
352
width=512,
353
height=768,
354
alwayson_scripts={
355
"ReActor": reactor_config.to_dict()
356
}
357
)
358
359
result.image.save("face_swapped.png")
360
361
# Combine multiple extensions
362
adetailer_config = webuiapi.ADetailer(
363
ad_model="None",
364
ad_denoising_strength=0.3
365
)
366
367
sag_config = webuiapi.Sag(
368
sag_scale=0.75,
369
sag_mask_threshold=1.0
370
)
371
372
# Generate with multiple extensions
373
result = api.txt2img(
374
prompt="cinematic portrait, dramatic lighting",
375
width=768,
376
height=768,
377
steps=30,
378
alwayson_scripts={
379
"ADetailer": adetailer_config.to_dict(),
380
"SAG": sag_config.to_dict()
381
}
382
)
383
384
result.image.save("multi_extension_result.png")
385
```
386
387
## Extension Interface Classes
388
389
### Model Keywords Interface
390
391
```python { .api }
392
class ModelKeywordInterface:
393
"""Interface for model keyword generation."""
394
395
def get_keywords(self, model_name: str) -> ModelKeywordResult:
396
"""Get keywords associated with a model."""
397
398
class ModelKeywordResult:
399
"""Result from model keyword lookup."""
400
keywords: List[str] # Associated keywords
401
model: str # Model name
402
oldhash: str # Model hash
403
match_source: str # Source of keyword match
404
```
405
406
### Specialized Processing Interfaces
407
408
```python { .api }
409
class RemBGInterface:
410
"""Background removal interface."""
411
412
def rembg(
413
self,
414
input_image: str,
415
model: str = "u2net",
416
return_mask: bool = False,
417
alpha_matting: bool = False
418
) -> Dict:
419
"""Remove background from image."""
420
421
class InstructPix2PixInterface:
422
"""InstructPix2Pix instruction-based editing."""
423
424
def img2img(
425
self,
426
prompt: str,
427
images: List[Image.Image],
428
**kwargs
429
) -> WebUIApiResult:
430
"""Edit images using natural language instructions."""
431
```
432
433
## Types
434
435
```python { .api }
436
class ADetailer:
437
"""ADetailer configuration with 40+ parameters for face/object enhancement."""
438
439
class AnimateDiff:
440
"""AnimateDiff configuration for video generation with timing and quality controls."""
441
442
class ReActor:
443
"""ReActor face swapping configuration with advanced options."""
444
445
class Roop:
446
"""Roop face swapping configuration with simplified interface."""
447
448
class Sag:
449
"""Self Attention Guidance configuration for improved coherence."""
450
```