0
# Model Management
1
2
Complete model lifecycle management including loading, switching, and querying available models, samplers, schedulers, and other resources. These functions provide essential model discovery and configuration capabilities.
3
4
## Capabilities
5
6
### Model Discovery
7
8
Retrieve information about available models and resources installed in the WebUI instance.
9
10
```python { .api }
11
def get_sd_models() -> List[Dict]:
12
"""
13
Get list of available Stable Diffusion models.
14
15
Returns:
16
List of model dictionaries containing:
17
- title: Model display name
18
- model_name: Internal model name
19
- hash: Model hash
20
- sha256: SHA256 hash
21
- filename: Model file path
22
- config: Model configuration file
23
"""
24
25
def get_samplers() -> List[Dict]:
26
"""
27
Get list of available sampling methods.
28
29
Returns:
30
List of sampler dictionaries containing:
31
- name: Sampler name
32
- aliases: Alternative names
33
- options: Sampler-specific options
34
"""
35
36
def get_schedulers() -> List[Dict]:
37
"""
38
Get list of available schedulers.
39
40
Returns:
41
List of scheduler dictionaries containing:
42
- name: Scheduler name
43
- label: Display label
44
- aliases: Alternative names
45
"""
46
47
def get_upscalers() -> List[Dict]:
48
"""
49
Get list of available upscaling models.
50
51
Returns:
52
List of upscaler dictionaries containing:
53
- name: Upscaler name
54
- model_name: Internal model name
55
- model_path: Path to model file
56
- model_url: Download URL (if available)
57
- scale: Upscaling factor
58
"""
59
60
def get_sd_vae() -> List[Dict]:
61
"""
62
Get list of available VAE models.
63
64
Returns:
65
List of VAE dictionaries containing:
66
- model_name: VAE model name
67
- filename: VAE file path
68
"""
69
70
def get_loras() -> List[Dict]:
71
"""
72
Get list of available LoRA models.
73
74
Returns:
75
List of LoRA dictionaries containing LoRA metadata
76
"""
77
78
def get_hypernetworks() -> List[Dict]:
79
"""
80
Get list of available Hypernetwork models.
81
82
Returns:
83
List of hypernetwork dictionaries
84
"""
85
86
def get_face_restorers() -> List[Dict]:
87
"""
88
Get list of available face restoration models.
89
90
Returns:
91
List of face restorer dictionaries
92
"""
93
94
def get_realesrgan_models() -> List[Dict]:
95
"""
96
Get list of available Real-ESRGAN models.
97
98
Returns:
99
List of Real-ESRGAN model dictionaries
100
"""
101
102
def get_prompt_styles() -> List[Dict]:
103
"""
104
Get list of available prompt styles.
105
106
Returns:
107
List of style dictionaries containing:
108
- name: Style name
109
- prompt: Style prompt template
110
- negative_prompt: Style negative prompt template
111
"""
112
113
def get_embeddings() -> List[Dict]:
114
"""
115
Get list of available textual inversions/embeddings.
116
117
Returns:
118
List of embedding dictionaries
119
"""
120
121
def get_latent_upscale_modes() -> List[Dict]:
122
"""
123
Get list of available latent upscaling modes.
124
125
Returns:
126
List of latent upscale mode dictionaries containing:
127
- name: Mode name
128
- description: Mode description
129
"""
130
131
def get_artist_categories() -> List[Dict]:
132
"""
133
Get artist categories (deprecated).
134
135
Returns:
136
List of artist category dictionaries
137
138
Note: This method is deprecated but still available for backwards compatibility.
139
"""
140
141
def get_artists() -> List[Dict]:
142
"""
143
Get list of artists (deprecated).
144
145
Returns:
146
List of artist dictionaries
147
148
Note: This method is deprecated but still available for backwards compatibility.
149
"""
150
```
151
152
### Model Control
153
154
Switch between models and refresh model lists.
155
156
```python { .api }
157
def refresh_checkpoints() -> None:
158
"""
159
Refresh the list of available checkpoints/models.
160
161
Forces WebUI to rescan the models directory and update
162
the available model list.
163
"""
164
165
def util_set_model(name: str) -> None:
166
"""
167
Set the active Stable Diffusion model with fuzzy matching.
168
169
Parameters:
170
- name: Model name (supports partial matching)
171
172
Uses fuzzy string matching to find the best match among
173
available models if exact name not found.
174
"""
175
176
def util_get_current_model() -> str:
177
"""
178
Get the currently active Stable Diffusion model name.
179
180
Returns:
181
String containing the current model name
182
"""
183
```
184
185
### Utility Functions
186
187
Helper functions for common model management tasks.
188
189
```python { .api }
190
def util_get_model_names() -> List[str]:
191
"""
192
Get sorted list of available model names.
193
194
Returns:
195
Sorted list of model names for easy selection
196
"""
197
198
def util_get_sampler_names() -> List[str]:
199
"""
200
Get sorted list of available sampler names.
201
202
Returns:
203
Sorted list of sampler names
204
"""
205
206
def util_get_scheduler_names() -> List[str]:
207
"""
208
Get sorted list of available scheduler names.
209
210
Returns:
211
Sorted list of scheduler names
212
"""
213
```
214
215
### Prompt Generation
216
217
AI-powered prompt generation using specialized models for creative prompt enhancement and expansion.
218
219
```python { .api }
220
def list_prompt_gen_models() -> List[str]:
221
"""
222
Get list of available prompt generation models.
223
224
Returns:
225
List of model names for prompt generation, such as:
226
- "AUTOMATIC/promptgen-lexart"
227
- "AUTOMATIC/promptgen-majinai-safe"
228
- "AUTOMATIC/promptgen-majinai-unsafe"
229
"""
230
231
def prompt_gen(
232
text: str,
233
model_name: str = "AUTOMATIC/promptgen-lexart",
234
batch_count: int = 1,
235
batch_size: int = 1,
236
min_length: int = 20,
237
max_length: int = 150,
238
num_beams: int = 1,
239
temperature: float = 1.0,
240
repetition_penalty: float = 1.0,
241
length_preference: float = 1.0,
242
sampling_mode: str = "Top K",
243
top_k: int = 12,
244
top_p: float = 0.15
245
) -> List[str]:
246
"""
247
Generate enhanced prompts using AI models.
248
249
Parameters:
250
- text: Base text to expand into a full prompt
251
- model_name: Prompt generation model to use
252
- batch_count: Number of batches to generate
253
- batch_size: Number of prompts per batch
254
- min_length: Minimum prompt length
255
- max_length: Maximum prompt length
256
- num_beams: Number of beams for beam search
257
- temperature: Sampling temperature (higher = more creative)
258
- repetition_penalty: Penalty for repeated words
259
- length_preference: Preference for longer prompts
260
- sampling_mode: Sampling method ("Top K", "Top P", "Typical P")
261
- top_k: Top-K sampling parameter
262
- top_p: Top-P (nucleus) sampling parameter
263
264
Returns:
265
List of generated prompts
266
"""
267
```
268
269
**Usage Examples:**
270
271
```python
272
import webuiapi
273
274
api = webuiapi.WebUIApi()
275
276
# Discover available models
277
models = api.get_sd_models()
278
for model in models:
279
print(f"Model: {model['title']}")
280
print(f"Filename: {model['filename']}")
281
print(f"Hash: {model['hash']}")
282
print("---")
283
284
# Get current model
285
current_model = api.util_get_current_model()
286
print(f"Current model: {current_model}")
287
288
# Switch to a different model (with fuzzy matching)
289
api.util_set_model("realistic_vision") # Matches "realisticVisionV40_v40VAE.safetensors"
290
291
# Get available samplers and schedulers
292
samplers = api.get_samplers()
293
sampler_names = [s['name'] for s in samplers]
294
print(f"Available samplers: {sampler_names}")
295
296
schedulers = api.get_schedulers()
297
scheduler_names = [s['name'] for s in schedulers]
298
print(f"Available schedulers: {scheduler_names}")
299
300
# Check upscaling options
301
upscalers = api.get_upscalers()
302
upscaler_names = [u['name'] for u in upscalers]
303
print(f"Available upscalers: {upscaler_names}")
304
305
# Refresh model list after adding new models
306
api.refresh_checkpoints()
307
308
# Use utility functions for easy access
309
model_names = api.util_get_model_names()
310
print(f"All available models: {model_names}")
311
312
# Generate enhanced prompts
313
available_prompt_models = api.list_prompt_gen_models()
314
print(f"Available prompt models: {available_prompt_models}")
315
316
prompts = api.prompt_gen(
317
text="a beautiful cat",
318
model_name="AUTOMATIC/promptgen-lexart",
319
batch_size=3,
320
temperature=1.2,
321
max_length=100
322
)
323
print("Generated prompts:")
324
for i, prompt in enumerate(prompts):
325
print(f"{i+1}: {prompt}")
326
```
327
328
## Types
329
330
```python { .api }
331
class Upscaler(str, Enum):
332
"""Enumeration of standard upscaling algorithms."""
333
none = "None"
334
Lanczos = "Lanczos"
335
Nearest = "Nearest"
336
LDSR = "LDSR"
337
BSRGAN = "BSRGAN"
338
ESRGAN_4x = "R-ESRGAN 4x+"
339
R_ESRGAN_General_4xV3 = "R-ESRGAN General 4xV3"
340
ScuNET_GAN = "ScuNET GAN"
341
ScuNET_PSNR = "ScuNET PSNR"
342
SwinIR_4x = "SwinIR 4x"
343
344
class HiResUpscaler(str, Enum):
345
"""Enumeration of high-resolution upscaling methods."""
346
none = "None"
347
Latent = "Latent"
348
LatentAntialiased = "Latent (antialiased)"
349
LatentBicubic = "Latent (bicubic)"
350
LatentBicubicAntialiased = "Latent (bicubic antialiased)"
351
LatentNearest = "Latent (nearest)"
352
LatentNearestExact = "Latent (nearest-exact)"
353
Lanczos = "Lanczos"
354
Nearest = "Nearest"
355
ESRGAN_4x = "R-ESRGAN 4x+"
356
LDSR = "LDSR"
357
ScuNET_GAN = "ScuNET GAN"
358
ScuNET_PSNR = "ScuNET PSNR"
359
SwinIR_4x = "SwinIR 4x"
360
```