forked from huchenlei/sd-forge-ic-light
-
Notifications
You must be signed in to change notification settings - Fork 5
API
Haoming edited this page Apr 29, 2025
·
3 revisions
To use IC-Light via API, add an "IC Light" object to the "alwayson_scripts" array in your payload, with the following 13 values:
-
enable: (
bool) Enable 💀 -
model_type: (
str) Thefc/fbcmodel name on disk (without extension) -
input_fg: (
str) The subject image (fortxt2img) or the lighting image (forimg2img) in base64 format -
uploaded_bg: (
str) The background image specifically for thefbcmode intxt2img -
remove_bg: (
bool) Enable to remove the background from theinput_fg -
rembg_model: (
str) Therembgmodel name- see here for the list of all models
-
foreground_threshold: (
int) refer to rembg for what this does... -
background_threshold: (
int) refer to rembg for what this does... -
erode_size: (
int) refer to rembg for what this does... -
detail_transfer: (
bool) Enable to transfer details usingDoG -
detail_transfer_raw: (
bool) Enable to use the rawinput_fgto transfer details -
detail_transfer_blur_radius: (
int) Blur radius forDoG -
reinforce_fg: (
bool) Enable to additionally paste the input image onto theinput_fg, specifically forimg2img
Example Script
from PIL import Image
import requests
import base64
import io
def img2base64(image: Image.Image) -> str:
with io.BytesIO() as output_bytes:
image.save(output_bytes, format="JPEG", quality=100, optimize=True)
bytes_data = output_bytes.getvalue()
return base64.b64encode(bytes_data).decode("utf-8")
image = Image.open("./subject_input.jpg")
subject = img2base64(image)
payload = {
"prompt": "high quality, best quality, a photo of a gentleman in suit, standing under sunset",
"negative_prompt": "worst quality, bad quality, low quality",
"sampler_name": "DPM++ 2M Karras",
"steps": 32,
"width": 512,
"height": 512,
"cfg_scale": 7.5,
"alwayson_scripts": {
"IC Light": {
"args": [
True,
"IC-Light-SD15-FC-fp8",
subject,
None,
True,
"u2net_human_seg",
225,
16,
16,
False,
False,
3,
False,
]
}
},
}
url = "http://127.0.0.1:7860"
response = requests.post(url=f"{url}/sdapi/v1/txt2img", json=payload)
r = response.json()
with open("./api_output.png", "wb") as f:
f.write(base64.b64decode(r["images"][0]))Buy me a coffee~ ☕