全网最全stable diffusion webui API调用示例,包含controlneth和segment anything的API(附json示例)

全网最全stable diffusion webui API调用示例,包含controlneth和segment anything的API(附json示例)

交流群 100419879
欢迎合作👏🏻 V : 864399407
GitHub:https://github.com/Anning01
BiliBili: https://space.bilibili.com/50125441

txt2img -> /sdapi/v1/txt2img

不带 controlnet

data = {
    "prompt": "提示词",
    "negative_prompt": "反向提示词",
    "seed": -1,  # 随机种子
    "sampler_name": "取样器(之间复制webui的名字就行)",
    "cfg_scale": 7.5,  # 提示词相关性 越大越接近提示词
    "width": 640,  # 宽 (注意要被16整除)
    "height": 360,  # 高 (注意要被16整除)
    "batch_size": 4,  # 批量数量 并行 显存不够会爆显存
    "n_iter": 4,  # 批量数量 队列 显存不够排队一个一个来 和 batch_size 二选一
    "steps": 30,  # 迭代步数
    "return_grid": True,  # 返回网格预览 xl-base 好像没用
    "restore_faces": True,  # 脸部修复
    "send_images": True,  # 是否在响应中返回生成的图像
    "save_images": False,  # 是否保存生成的图像 一般api设置成False
    "do_not_save_samples": False,  # 是否保存samples 一般api设置成False
    "do_not_save_grid": False,  # 是否保存网格的图像 一般api设置成False
    # 下面的很少用
    "enable_hr": True,  # 是否开启高清修复
    "denoising_strength": 0.5,  # 去噪强度 要求enable_hr = True
    "firstphase_width": 0,
    # firstphase_width 和firstphase_height 定义了图像的初始分辨率。在图像生成的第一阶段,这些值决定了图像的大小。如果这些值设置为0,系统可能会使用默认或预设的分辨率。
    "firstphase_height": 0,
    "hr_scale": 2,  # 放大倍数 对应webui Upscale by
    "hr_upscaler": "string",  # 对应webui 的 Upscaler
    "hr_second_pass_steps": 0,  # 迭代步数 对应webui 的 Hires steps。
    "hr_resize_x": 0,  # 不放大,指定宽高 对应webui Resize width to 和Resize height to
    "hr_resize_y": 0,  # 不放大,指定宽高 对应webui Resize width to 和Resize height to
    "hr_checkpoint_name": "string",  # 高分辨率模式下使用的大模型昵称。
    "hr_sampler_name": "string",  # 高分辨率模式下使用的采样器名称。
    "hr_prompt": "",  # 高分辨率模式下使用的提示词名称。
    "hr_negative_prompt": "",  # 高分辨率模式下使用的反向提示词名称。
    "override_settings": {
          "sd_model_checkpoint": "sd_xl_base_1.0.safetensors [31e35c80fc]",  # 指定大模型
          "sd_vae": "Automatic",  # 指定vae 默认自动
      },
    "override_settings_restore_afterwards": True # override_settings 是否在之后恢复覆盖的设置 默认是True


}

带 controlnet

data = {
    "prompt": "提示词",
    "negative_prompt": "反向提示词",
    "seed": -1,  # 随机种子
    "sampler_name": "取样器(之间复制webui的名字就行)",
    "cfg_scale": 7.5,  # 提示词相关性 越大越接近提示词
    "width": 640,  # 宽 (注意要被16整除)
    "height": 360,  # 高 (注意要被16整除)
    "batch_size": 4,  # 批量数量 并行 显存不够会爆显存
    "n_iter": 4,  # 批量数量 队列 显存不够排队一个一个来 和 batch_size 二选一
  	"steps": 30,  # 迭代步数
    "return_grid": True,  # 返回网格预览 xl-base 好像没用
    "restore_faces": True,  # 脸部修复
    "send_images": True,  # 是否在响应中返回生成的图像
    "save_images": False,  # 是否保存生成的图像 一般api设置成False
    "do_not_save_samples": False,  # 是否保存samples 一般api设置成False
    "do_not_save_grid": False,  # 是否保存网格的图像 一般api设置成False
    "alwayson_scripts": {
        "controlnet":
            {
                "args": [
                    {
                        "enabled": True,  # 启用
                        "control_mode": 0,  # 对应webui 的 Control Mode 可以直接填字符串 推荐使用下标 0 1 2
                        "model": "t2i-adapter_diffusers_xl_lineart [bae0efef]",  # 对应webui 的 Model
                        "module": "lineart_standard (from white bg & black line)",  # 对应webui 的 Preprocessor
                        "weight": 0.45,  # 对应webui 的Control Weight
                        "resize_mode": "Crop and Resize",
                        "threshold_a": 200,  # 阈值a 部分control module会用上
                        "threshold_b": 245,  # 阈值b
                        "guidance_start": 0,  # 什么时候介入 对应webui 的 Starting Control Step
                        "guidance_end": 0.7,  # 什么时候退出 对应webui 的 Ending Control Step
                        "pixel_perfect": True,  # 像素完美
                        "processor_res": 512,  # 预处理器分辨率
                        "save_detected_map": False,  # 因为使用了 controlnet API会返回生成controlnet的效果图,默认是True,如何不需要,改成False
                        "input_image": "",  # 图片 格式为base64

                    }
                    # 多个controlnet 在复制上面一个字典下来就行
                ]
            }
    },
    # 下面的很少用
    "enable_hr": True,  # 是否开启高清修复
    "denoising_strength": 0.5,  # 去噪强度 要求enable_hr = True
    "firstphase_width": 0,
    # firstphase_width 和firstphase_height 定义了图像的初始分辨率。在图像生成的第一阶段,这些值决定了图像的大小。如果这些值设置为0,系统可能会使用默认或预设的分辨率。
    "firstphase_height": 0,
    "hr_scale": 2,  # 放大倍数 对应webui Upscale by
    "hr_upscaler": "string",  # 对应webui 的 Upscaler
    "hr_second_pass_steps": 0,  # 迭代步数 对应webui 的 Hires steps。
    "hr_resize_x": 0,  # 不放大,指定宽高 对应webui Resize width to 和Resize height to
    "hr_resize_y": 0,  # 不放大,指定宽高 对应webui Resize width to 和Resize height to
    "hr_checkpoint_name": "string",  # 高分辨率模式下使用的大模型昵称。
    "hr_sampler_name": "string",  # 高分辨率模式下使用的采样器名称。
    "hr_prompt": "",  # 高分辨率模式下使用的提示词名称。
    "hr_negative_prompt": "",  # 高分辨率模式下使用的反向提示词名称。
    "override_settings": {
          "sd_model_checkpoint": "sd_xl_base_1.0.safetensors [31e35c80fc]",  # 指定大模型
          "sd_vae": "Automatic",  # 指定vae 默认自动
      },
    "override_settings_restore_afterwards": True # override_settings 是否在之后恢复覆盖的设置 默认是True

}
带 Refiner

data = {
    "prompt": "提示词",
    "negative_prompt": "反向提示词",
    "seed": -1,  # 随机种子
    "sampler_name": "取样器(之间复制webui的名字就行)",
    "cfg_scale": 7.5,  # 提示词相关性 越大越接近提示词
    "width": 640,  # 宽 (注意要被16整除)
    "height": 360,  # 高 (注意要被16整除)
    "batch_size": 4,  # 批量数量 并行 显存不够会爆显存
    "n_iter": 4,  # 批量数量 队列 显存不够排队一个一个来 和 batch_size 二选一
  	"steps": 30,  # 迭代步数
    "return_grid": True,  # 返回网格预览 xl-base 好像没用
    "restore_faces": True,  # 脸部修复
    "send_images": True,  # 是否在响应中返回生成的图像
    "save_images": False,  # 是否保存生成的图像 一般api设置成False
    "do_not_save_samples": False,  # 是否保存samples 一般api设置成False
    "do_not_save_grid": False,  # 是否保存网格的图像 一般api设置成False
    "alwayson_scripts": {
        "controlnet":
            {
                "args": [
                    {
                        "enabled": True,  # 启用
                        "control_mode": 0,  # 对应webui 的 Control Mode 可以直接填字符串 推荐使用下标 0 1 2
                        "model": "t2i-adapter_diffusers_xl_lineart [bae0efef]",  # 对应webui 的 Model
                        "module": "lineart_standard (from white bg & black line)",  # 对应webui 的 Preprocessor
                        "weight": 0.45,  # 对应webui 的Control Weight
                        "resize_mode": "Crop and Resize",
                        "threshold_a": 200,  # 阈值a 部分control module会用上
                        "threshold_b": 245,  # 阈值b
                        "guidance_start": 0,  # 什么时候介入 对应webui 的 Starting Control Step
                        "guidance_end": 0.7,  # 什么时候退出 对应webui 的 Ending Control Step
                        "pixel_perfect": True,  # 像素完美
                        "processor_res": 512,  # 预处理器分辨率
                        "save_detected_map": False,  # 因为使用了 controlnet API会返回生成controlnet的效果图,默认是True,如何不需要,改成False
                        "input_image": "",  # 图片 格式为base64

                    }
                    # 多个controlnet 在复制上面一个字典下来就行
                ]
            },
        "Refiner": {
            "args": [
                True,  # 是否开启
                "sd_xl_refiner_1.0",  # 大模型昵称
                0.75,  # 介入时机
            ]
        }
    },
    # 下面的很少用
    "enable_hr": True,  # 是否开启高清修复
    "denoising_strength": 0.5,  # 去噪强度 要求enable_hr = True
    "firstphase_width": 0,
    # firstphase_width 和firstphase_height 定义了图像的初始分辨率。在图像生成的第一阶段,这些值决定了图像的大小。如果这些值设置为0,系统可能会使用默认或预设的分辨率。
    "firstphase_height": 0,
    "hr_scale": 2,  # 放大倍数 对应webui Upscale by
    "hr_upscaler": "string",  # 对应webui 的 Upscaler
    "hr_second_pass_steps": 0,  # 迭代步数 对应webui 的 Hires steps。
    "hr_resize_x": 0,  # 不放大,指定宽高 对应webui Resize width to 和Resize height to
    "hr_resize_y": 0,  # 不放大,指定宽高 对应webui Resize width to 和Resize height to
    "hr_checkpoint_name": "string",  # 高分辨率模式下使用的大模型昵称。
    "hr_sampler_name": "string",  # 高分辨率模式下使用的采样器名称。
    "hr_prompt": "",  # 高分辨率模式下使用的提示词名称。
    "hr_negative_prompt": "",  # 高分辨率模式下使用的反向提示词名称。
    "override_settings": {
          "sd_model_checkpoint": "sd_xl_base_1.0.safetensors [31e35c80fc]",  # 指定大模型
          "sd_vae": "Automatic",  # 指定vae 默认自动
      },
    "override_settings_restore_afterwards": True # override_settings 是否在之后恢复覆盖的设置 默认是True

}
生成蒙版 segment anything -> /sam/sam-predict
data = {
    "sam_model_name": "sam_vit_b_01ec64.pth",  # 蒙版模型名称
    "input_image": "base64_str",  # 图像base64
    "sam_positive_points": [
        [317.7521, 174.7542],
        [304.25, 174.75],
        [295.25, 152.25],
        [292.25, 174.75],
        [284.75, 168.75],
    ],  # 选中坐标点
    "sam_negative_points": [],  # 反选中坐标点
    "dino_enabled": True,  # 开启文字识别 例如一只猫在草坪上,想要得到猫的蒙版 可以使用 cat 会自动识别物品
    "dino_model_name": "GroundingDINO_SwinT_OGC (694MB)",  # 文字识别模型
    "dino_text_prompt": "",  # 文字(要英语)例如 cat
}

img2img -> /sdapi/v1/img2img

使用蒙版局部重绘
data = {
    "init_images": ["base64", ],  # 初始图像(要求使用base64列表)
    "mask": "base64",  # 蒙版base64
    "prompt": "",  # 提示词
    "negative_prompt": "",  # 负面提示词
    "batch_size": 4,  # 批量数量 并行 显存不够会爆显存
    "n_iter": 4,  # 批量数量 队列 显存不够排队一个一个来 和 batch_size 二选一
  	"seed": -1,  # 随机种子
    "sampler_name": "Euler a",  # 采样器名称
    "mask_blur": 4,  # 边缘模糊
    "inpaint_full_res": True,  # 更高分辨率修复 耗费算力,一般显卡建议关闭
    "inpaint_full_res_padding": 4,  # 小到中等大小的修复区域 建议 4 - 10 大型修复区域建议 10 - 20
    "inpainting_mask_invert": 0,  # 1 则反转蒙版
    "cfg_scale": 7,  # 提示词相关性
    "send_images": True,  # 是否在响应中返回生成的图像
    "save_images": False,  # 是否保存生成的图像 一般api设置成False
    "width": 640,
    "height": 360,
    "denoising_strength": 0.5,  # 去噪强度
    "steps": 30,  # 步数
    "override_settings": {
        "sd_model_checkpoint": "sd_xl_base_1.0.safetensors [31e35c80fc]",  # 指定大模型
        "sd_vae": "Automatic",  # 指定vae 默认自动
    },
  	"override_settings_restore_afterwards": True # override_settings 是否在之后恢复覆盖的设置 默认是True
}

版权声明:本文为博主作者:Python_anning原创文章,版权归属原作者,如果侵权,请联系我们删除!

原文链接:https://blog.csdn.net/Python_anning/article/details/135269356

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
心中带点小风骚的头像心中带点小风骚普通用户
上一篇 2024年5月6日
下一篇 2024年5月6日

相关推荐