Closed ashleykleynhans closed 6 months ago
See https://github.com/lllyasviel/stable-diffusion-webui-forge/wiki/ControlNet-Web-API
Also you probably need to update your forge.
See https://github.com/lllyasviel/stable-diffusion-webui-forge/wiki/ControlNet-Web-API
Also you probably need to update your forge.
Thanks for the wiki link, my forge is already at the latest commit.
Seems I did actually need to update it, but its still not working, now I am getting a different error:
*** Error running process: /workspace/stable-diffusion-webui-forge/extensions-builtin/sd_forge_controlnet/scripts/controlnet.py
Traceback (most recent call last):
File "/workspace/stable-diffusion-webui-forge/modules/scripts.py", line 803, in process
script.process(p, *script_args)
File "/workspace/venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "/workspace/stable-diffusion-webui-forge/extensions-builtin/sd_forge_controlnet/scripts/controlnet.py", line 548, in process
self.process_unit_after_click_generate(p, unit, params, *args, **kwargs)
File "/workspace/venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "/workspace/stable-diffusion-webui-forge/extensions-builtin/sd_forge_controlnet/scripts/controlnet.py", line 298, in process_unit_after_click_generate
input_list, resize_mode = self.get_input_data(p, unit, preprocessor, h, w)
File "/workspace/stable-diffusion-webui-forge/extensions-builtin/sd_forge_controlnet/scripts/controlnet.py", line 203, in get_input_data
resize_mode = external_code.resize_mode_from_value(p.resize_mode)
AttributeError: 'StableDiffusionProcessingTxt2Img' object has no attribute 'resize_mode'
---
*** Error running process_before_every_sampling: /workspace/stable-diffusion-webui-forge/extensions-builtin/sd_forge_controlnet/scripts/controlnet.py
Traceback (most recent call last):
File "/workspace/stable-diffusion-webui-forge/modules/scripts.py", line 835, in process_before_every_sampling
script.process_before_every_sampling(p, *script_args, **kwargs)
File "/workspace/venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "/workspace/stable-diffusion-webui-forge/extensions-builtin/sd_forge_controlnet/scripts/controlnet.py", line 555, in process_before_every_sampling
self.process_unit_before_every_sampling(p, unit, self.current_params[i], *args, **kwargs)
KeyError: 0
---
100%|█████████████████████████████████████████████████████████████████████| 20/20 [00:11<00:00, 1.72it/s]
*** Error running postprocess_batch_list: /workspace/stable-diffusion-webui-forge/extensions-builtin/sd_forge_controlnet/scripts/controlnet.py
Traceback (most recent call last):
File "/workspace/stable-diffusion-webui-forge/modules/scripts.py", line 859, in postprocess_batch_list
script.postprocess_batch_list(p, pp, *script_args, **kwargs)
File "/workspace/venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "/workspace/stable-diffusion-webui-forge/extensions-builtin/sd_forge_controlnet/scripts/controlnet.py", line 561, in postprocess_batch_list
self.process_unit_after_every_sampling(p, unit, self.current_params[i], pp, *args, **kwargs)
KeyError: 0
Exact same payload works fine with img2img, its only txt2img giving me issues.
Exact same payload works fine with img2img, its only txt2img giving me issues.
Looks like you're missing the image
arg; with img2img it defaults to the main image, but for txt2img you have to pass the image upon which the controlnet unit will work.
Exact same payload works fine with img2img, its only txt2img giving me issues.
Looks like you're missing the
image
arg; with img2img it defaults to the main image, but for txt2img you have to pass the image upon which the controlnet unit will work.
Thanks, its working now.
@ashleykleynhans where did you update the image arg?
@ashleykleynhans where did you update the image arg?
@ashleykleynhans where did you update the image arg?
Could you please let me know which file to change I am not able to find? I am getting the error in img2img as well. Please help
@sumit91in There are no files to change, it is an API request.
Basically the input_image
property changed to image
in the controlnet unit; changing the request payload accordingly should fix the issue.
Basically the
input_image
property changed toimage
in the controlnet unit; changing the request payload accordingly should fix the issue.
@ramyma Thank for your reply but I cant figure out where exactly i need to make the change. Now apart from the above error, i am getting the below error.
Kindly help. Stuck on this over a week still cant figure out
It looks like the controlnet model file you're using is broken, did it download the model again why you try to generate again? Also does it work for you through the web-ui interface?
This issue is closed and the stuff you are posting here is not relevant, please use a forum or log a new issue, it does not belong here.
this is still happening,
no matter what i try from the API i get the same error and the controlnet image fails to apply, while it works inside the webui
this is the test script i'm using:
import io
import cv2
import base64
import requests
import json
from PIL import Image, PngImagePlugin
def test(test_image):
url = "http://localhost:7860" # change to your SD url
img = cv2.imread(test_image)
retval, bytes = cv2.imencode('.png', img)
encoded_image = base64.b64encode(bytes).decode('utf-8')
# Note: You can no longer pass file path in payload as in sd-webui-controlnet.
payload = {
"prompt":"2girls, reading, book, elf, simple white background, white dress, hatsune miku",
"negative_prompt": "",
"sampler_name": "Euler a",
"batch_size": 1,
"steps": 20,
"cfg_scale": 6,
"width": 1024,
"height": 1024,
# txt2img should not need any init images except for the controlnet image
#"init_images": [test_image],
#"init_images": [encoded_image],
"alwayson_scripts": {
"controlnet": {
"args": [
{
"enabled": True,
"image": encoded_image,
#"mask_image": encoded_image,
"control_mode": "Balanced",
"guidance_end": 1,
"guidance_start": 0,
"pixel_perfect": True,
"processor_res": 512,
"resize_mode": "Resize and Fill", # "Just Resize", "Crop and Resize", "Resize and Fill"
"threshold_a": 0.5,
"threshold_b": 0.5,
"weight": 1,
"save_detected_map": True,
"hr_option": "Both",
#"module": "canny",
"module": "lineart_anime",
"model": "t2i-adapter_diffusers_xl_canny [6b0c1490]",
#"model": "control_v11p_sd15_canny [d14c016b]",
#"model": "control_v11p_sd15s2_lineart_anime [3825e83e]",
}
]
}
}
}
response = requests.post(url=f'{url}/sdapi/v1/txt2img', json=payload)
r = response.json()
result = r['images'][0]
image = Image.open(io.BytesIO(base64.b64decode(result.split(",", 1)[0])))
pnginfo = PngImagePlugin.PngInfo()
if 'parameters' in image.info and image.info['parameters'] is not None:
pnginfo.add_text("parameters", image.info.get('parameters'))
print("\nParameters:\n" + json.dumps(image.info, indent=4))
image.save('test_output.png', pnginfo=pnginfo)
print("image saved to test_output.png")
test("test.png")
controlnet test image:
controlnet console error:
controlnet webui in editor output with same settings (no console errors):
test output using API:
Checklist
What happened?
I am able to successfully use ControlNet with txt2img within the WebUI GUI, but when I want to do the same thing via the API, I get the following error:
This still continues to happen even when I set enabled to true in my payload.
Steps to reproduce the problem
POST the following JSON payload to the
/sdapi/v1/txt2img
endpoint:What should have happened?
The ControlNet unit should have activated and been applied to the request.
What browsers do you use to access the UI ?
Other
Sysinfo
sysinfo-2024-02-23-14-04.json
Console logs