+
96
-

回答

Stable Diffusion支持http的api,开启方式有两种:

1、webui.bat 启动命令后面增加一个--api

2、打开webui-user.bat文件,将里面的set COMMANDLINE_ARGS=--api  这样运行就是启动api,启动后通过 http://127.0.0.1:7860/docs)就能看到api文档了。

800_auto

import requests
import base64

# Define the URL and the payload to send.
url = "http://127.0.0.1:7860"

payload = {
    "prompt": "puppy dog",
    "steps": 5
}

# Send said payload to said URL through the API.
response = requests.post(url=f'{url}/sdapi/v1/txt2img', json=payload)
r = response.json()

# Decode and save the image.
with open("output.png", 'wb') as f:
    f.write(base64.b64decode(r['images'][0]))

参考:https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/API

网友回复

我知道答案,我要回答