添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
深沉的松鼠  ·  [Python] ...·  12 小时前    · 
多情的仙人球  ·  Spark(一) | Learner·  12 小时前    · 
一身肌肉的煎鸡蛋  ·  Python: ...·  12 小时前    · 
火爆的香瓜  ·  建议收藏!Python ...·  12 小时前    · 
紧张的香瓜  ·  c++ string utf16 - CSDN文库·  7 小时前    · 
风度翩翩的斑马  ·  [Question] 503 ...·  3 周前    · 
无邪的芹菜  ·  CCI Technology ...·  2 月前    · 

I found this page and I got txt2img to work with my automatic1111:
https://towardsdatascience.com/stable-diffusion-as-an-api-5e381aec1f6

How can I enhance the program to use ControlNet?

OK, I got it to work. It's not the most beautiful code :-) But I hope that could be helpful to someone. Thanks to @ljleb again.

# https://github.com/Mikubill/sd-webui-controlnet/wiki/API#migrating-from-controlnet2img-to-sdapiv12img
import json
import base64
import requests
def submit_post(url: str, data: dict):
    Submit a POST request to the given URL with the given data.
    return requests.post(url, data=json.dumps(data))
def save_encoded_image(b64_image: str, output_path: str):
    Save the given image to the given output path.
    with open(output_path, "wb") as image_file:
        image_file.write(base64.b64decode(b64_image))
def encode_image(image_path):
  with open(image_path, "rb") as i:
    b64 = base64.b64encode(i.read())
  return b64.decode("utf-8")
if __name__ == '__main__':
#    img2img_url = 'http://127.0.0.1:7861/sdapi/v1/img2img'
    img2img_url = 'http://127.0.0.1:7861/sdapi/v1/txt2img'
    image= encode_image("pose.png")	 
    data =\
	  "prompt":"a sad 70 y.o man sitting at dinning table",
#	  "init_images": [image],	# For img2img
	  "sampler_name": "Euler",
	  "alwayson_scripts": {
	    "controlnet": {
	      "args": [
	  	  "input_image": image,
#		  "module": "depth","model": "control_depth-fp16 [400750f6]"
		  "module": "none","model": "control_openpose-fp16 [9ca67cc5]",
    response = submit_post(img2img_url, data)
#    print( response.json())
    save_encoded_image(response.json()['images'][0], 'result.png')