Crates.io | sdwebuiapi |
lib.rs | sdwebuiapi |
version | 0.0.6 |
source | src |
created_at | 2023-10-03 10:52:46.648637 |
updated_at | 2023-12-03 10:59:51.749968 |
description | A library for interacting with openapi of AUTOMATIC1111/stable-diffusion-webui |
homepage | |
repository | https://github.com/web3nomad/sdwebui-gateway |
max_upload_size | |
id | 990940 |
size | 17,396 |
A Rust library for interacting with openapi of AUTOMATIC1111/stable-diffusion-webui.
Supports txt2img API calls, with controlnet 2.0 support and lora support.
The parameters for API calls are based on the documentation at http://localhost:7860/docs and have been successfully tested on webui 1.5.
cargo add sdwebuiapi
webuiapi_demo.ipynb contains example code with original images. Images are compressed as jpeg in this document.
let api_auth = Some(sdwebuiapi::OpenApiV1Auth {
username: "username set in webui's --api-auth arg",
password: "password set in webui's --api-auth arg",
});
// or `let api_auth = None` if webui is not protected by api_auth
let client = sdwebuiapi::Client::new("http://localhost:7860", api_auth);
let mut payload = sdwebuiapi::TextToImagePayload {
prompt: "a cyberpunk cat".to_owned(),
..Default::default()
};
payload.set_base_model("v1-5-pruned-emaonly.safetensors [6ce0161689]");
let response: sdwebuiapi::TextToImageResponse = client.txt2img(payload).await;
// the generated image is in base64 format
let raw_b64_str: &str = &response.images[0];
encode image to base64, controlnet accepts raw base64 png image string, without headers
let input_image = std::fs::read("input-image.png").unwrap();
let raw_b64_str = data_encoding::BASE64.encode(&input_image);
build txt2img params
let controlnet_payload = sdwebuiapi::ControlnetPayload {
input_image: raw_b64_str.clone(),
model: "control_v11p_sd15_canny [d14c016b]".to_owned(),
module: "canny".to_owned(),
..Default::default()
};
let lora_paylod = sdwebuiapi::LoraPayload {
name: "add_detail".to_owned(),
weight: 1.0
};
let mut payload = sdwebuiapi::TextToImagePayload {
prompt: "a cyberpunk cat".to_owned(),
..Default::default()
};
payload
.set_base_model("v1-5-pruned-emaonly.safetensors [6ce0161689]")
.add_loras(&vec![lora_paylod])
.add_controlnet_units(&vec![controlnet_payload]);
generate image
let response = client.txt2img(payload).await;