1

I am using Automatic1111 and it is working fine on my local machine and txt2img API is also working fine but when I try to use controlNet it always gives me the server 500 response, any help or guide to where should I look for solution?

import requests
import base64

# Open the control image file in binary mode
with open("poses\poses_base.png", "rb") as f:
    # Read the image data
    image_data = f.read()

    # Encode the image data as base64
    image_base64 = base64.b64encode(image_data)

    # Convert the base64 bytes to string
    image_string = image_base64.decode("utf-8")

# Define the payload with the prompt and other parameters
payload = {
    "prompt": "A PURPLE VEST",
    "negative_prompt": "",
    "width": 512,
    "height": 512,
    "steps": 100,
    "cfg": 10,
    "sampler_index": "DPM++ 2S a Karras",
    "controlnet_units": [
        {
            "input_image": image_string,
            "mask": '',
            "module": "none",
            "model": "control_sd15_canny [fef5e48e]",
            "weight": 1.6,
            "resize_mode": "Scale to Fit (Inner Fit)",
            "lowvram": False,
            "processor_res": 512,
            "threshold_a": 64,
            "threshold_b": 64,
            "guidance": 1,
            "guidance_start": 0,
            "guidance_end": 1,
            "guessmode": True
        }
    ]
}

# Send the request to the API endpoint
response = requests.post(url=f'http://127.0.0.1:7860/controlnet/txt2img', json=payload)

# Print the response
print(response)
Tzane
  • 2,752
  • 1
  • 10
  • 21
Imran Bughio
  • 4,811
  • 2
  • 30
  • 53
  • Automatic1111 is a GitHub username. See https://github.com/AUTOMATIC1111 and [Why AUTOMATIC1111 is named like this?](https://genai.stackexchange.com/q/179/12) – Wicket Aug 13 '23 at 00:14

2 Answers2

2

The API changed today, or yesterday. There is a new extension to the API, smth like this. Check on Automatic1111 github

"alwayson_scripts": {
"ControlNet": {
"args":[True, False,
True,
"canny",
"control_canny-fp16 [e3fe7712]",
1.0,
{"image": image_string},
False,
"Scale to Fit (Inner Fit)",
False,
False,
64,
64,
64,
0.0,
1.0,
False]}}
Vasilije
  • 36
  • 2
  • Thanks, can you tell me where I can find what those args means? – Imran Bughio Mar 14 '23 at 07:45
  • @ImranBughio, there's a new format, and now it includes the keys: https://github.com/Mikubill/sd-webui-controlnet/wiki/API#migrating-from-controlnet2img-to-sdapiv12img – benrugg Mar 27 '23 at 19:55
0

This has now changed again. Here is the new format (with keys/values, instead of just an array):

{
  "init_images": ["base64..."],
  "sampler_name": "Euler",
  "alwayson_scripts": {
    "controlnet": {
      "args": [
        {
          "module": "depth",
          "model": "diff_control_sd15_depth_fp16 [978ef0a1]"
        }
      ]
    }
  }
}

More info / official documentation: https://github.com/Mikubill/sd-webui-controlnet/wiki/API#migrating-from-controlnet2img-to-sdapiv12img

benrugg
  • 2,088
  • 1
  • 16
  • 8