Usage - pk5ls20/sd-webui-controlnet-fastload GitHub Wiki
Use whatever you want.
You can adjust preferences in settings or enable function
isEnabledManualSend
By integrating with /sdapi/v1/*2img
, you can only get the processed image itself
You should confine /sdapi/v1/*2img
with /controlnetFastload/fetch
mentioned below to get the ControlNet data
This is the example to work with /sdapi/v1/txt2img
:
{
"prompt": "1girl",
"batch_size": 1,
"steps": 20,
"cfg_scale": 7,
"alwayson_scripts": {
"controlnet fastload": {
"args": [
{
"mode": "Load & Save",
"filepath": "D:\\stable-diffusion-webui\\outputs\\txt2img-images\\2023-08-07\\00006-1269320983.cni",
"overwritePriority": "ControlNet Plugin First"
}
]
}
}
}
In "args"
, pass:
-
mode
: How the extension works, you can pass one of theLoad
,Save
,Load & Save
-
filepath
: The filepath you need to upload -
overwritePriority
: Determine the priority of the native ControlNet extension and this extension, you can pass one of theControlNet Plugin First
,ControlNet First
Used to obtain the generated Controlnet data after a certain txt2img and img2img generation, Body of the route accepts a JSON object with the following property:
-
ControlNetID
: An ID to identify a specific txt2img or img2img generation, see the example below for details -
returnType
: Decide whether to return embedded images or separate .cni files, you can pass one of theExtra .cni file
,Embed photo
,Both
-
extraPicBase64
: [Optional] Pass the base64 of original generate image when returnType isEmbed photo
orBoth
Here's an example use both txt2img
and /controlnetFastload/fetch
import json
import requests
def txt2img_main():
# Add the "controlnet fastload" in "alwayson_scripts" to activate the extension.
json_ = {
"prompt": "1girl",
"negative_prompt": "",
"batch_size": 1,
"steps": 20,
"cfg_scale": 7,
"alwayson_scripts": {
"controlnet fastload": {
"args": [
{
"mode": "Load & Save",
"filepath": "D:\\stable-diffusion-webui\outputs\\txt2img-images\\2023-08-07\\00006-1269320983"
".cni",
"overwritePriority": "Plugin first",
}
]
}
}
}
response = requests.post(url="http://localhost:1819/sdapi/v1/txt2img", json=json_) # replace with your url
pic_base64_txt2img = response.json()['images'][0]
info = json.loads(response.json()['info'])
# Here we get the ControlNetID corresponding to this time txt2ing, prepare for the next step to extract Controlnet Data
ControlNetID_txt2img = info['extra_generation_params']['ControlNetID']
return pic_base64_txt2img, ControlNetID_txt2img
def controlNetFastload_Load(pic_base64_load, ControlNetIDLoad):
json__ = {
"ControlNetID": ControlNetIDLoad,
"returnType": "Extra .cni file",
"extraPicBase64": pic_base64_load
}
response = requests.post(url="http://localhost:1819/controlnetFastload/fetch", json=json__) # replace with your url
return response.json() # Here returns Controlnet Data encapsulated in Base64
if __name__ == '__main__':
pic_base64_, ControlNetID_ = txt2img_main()
print(controlNetFastload_Load(pic_base64_, ControlNetID_))
Used to obtain information in Controlnet Data files, Body of the route accepts a JSON object with the following property:
-
filepath
: The file address of the uploaded file -
except_type
: The image data format expected to be returned, you can pass one of thenparray
,base64
Get the current API version
Due to security reasons such as remote host access, you can add access restrictions to the Controlnet Fastload Filter tab via set Environment variables
Name | Description |
---|---|
CONTROLNET_FASTLOAD_FILTER_ACCESS_CONTROL | Determine the level of directory reading by the plugin when remote access is enabled. 0 - Cannot read any directories. 1 - Can only read the specific directories 'txt2img' and 'img2img'. 2 - Can read any directory. Default is 2 |
CONTROLNET_FASTLOAD_FILTER_ACCESS_TOKEN | A token with the highest privileges when accessing remotely. |