全网最全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
}
  • 28
    点赞
  • 46
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
Stable Diffusion WebUI是一种用于管理CodePlex常见操作的网络用户界面(WebUI),这意味着您不需要登录到服务器上的命令行界面来管理项目。安装过程并不复杂,但需要一些基本的技术知识。下面是安装过程的一些步骤: 首先,确保您的服务器已安装一个数据库管理系统。Stable Diffusion WebUI支持MSSQL Server、MySQL和SQLite等数据库系统,您可以根据自己的需要选择。然后,您需要在服务器上安装.NET框架,因为Stable Diffusion WebUI是一个基于.NET开发的应用程序。您可以在微软官网上下载适合您的版本。 接下来,您需要下载最新版本的Stable Diffusion WebUI。您可以从官方网站或GitHub页面上找到下载链接。将安装包下载到服务器上的任何目录中,然后解压缩它。安装包中包含了一些必要的文件和文件夹,包括安装向导(Install.bat)、WebUI配置文件(StableDiffusion.config)和WebUI启动程序(WebUI.exe)。 在使用安装向导之前,您需要进一步配置您的数据库。因此,您需要使用数据库管理系统(如MSSQL Server Management Studio)创建一个新的Database,并确保您对其具有足够的权限。然后,将您的数据库连接字符串添加到StableDiffusion.config文件中,并更改一些其他设置,例如端口号和SSL证书等。您还需要指定用于启动WebUi的帐户和密码。 一旦您完成了这些准备工作,就可以启动安装向导了。双击Install.bat脚本文件,它会自动安装Stable Diffusion WebUI,并将相关的文件复制到服务器上的指定目录中。安装程序还可以安装.NET框架和其他必要的组件(如IIS和ASP.NET)。 最后,您可以尝试连接到WebUI界面并登录到您的CodePlex项目。在您经过手动或自动设置后,您可以使用Stable Diffusion WebUI的各种功能来管理代码版本控制、问题跟踪、建立代码合并请求等等。它非常方便、强大,是一个非常受欢迎的开源项目管理工具。
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值