Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request]: New API Endpoint - Post Control Type to Get Filtered Data #2737

Closed
1 task done
altoiddealer opened this issue Apr 10, 2024 · 3 comments
Closed
1 task done
Labels
enhancement New feature or request

Comments

@altoiddealer
Copy link

Is there an existing issue for this?

  • I have searched the existing issues and checked the recent builds/commits of both this extension and the webui

What happened?

As of this writing, the ControlNet API endpoints are few and barely helpful.

Screenshot 2024-04-09 200854

POST Detect is probably the most useful, and I don't have any use for it.

  • You can get a model list, likely a crap ton of them.
  • You can get the module list, again likely a crap ton of them.
    ....The thought of filtering these lists on the user end is absurd.

The ControlNet script has those amazing functions for filtering the data in the UI, based simply on "Control Type" and checking the current SD Model.

It would be super duper awesome to be able to get a dictionary response containing all that filtered data via API request!!

Screenshot 2024-04-09 201914

Glorious filtered data... I want you so badly via API

Steps to reproduce the problem

  • Create a script that uses SD WebUI via API
  • Add ControlNet integrations
  • Cry

What should have happened?

An API endpoint to get that juicy filtered data would be freakin' sweet.

Commit where the problem happens

webui: Current
controlnet: Current

What browsers do you use to access the UI ?

No response

Command Line Arguments

No

List of enabled extensions

ControlNet

Console logs

None required

Additional information

No response

@huchenlei huchenlei added the enhancement New feature or request label Apr 15, 2024
@huchenlei
Copy link
Collaborator

We already have /controlnet/control_types API endpoint to return the filtered preprocessor/models.

models are futher filtered by the active SD version. You can obtain SD version from existing A1111 API.

Revelant code:

@app.get("/controlnet/control_types")
async def control_types():
def format_control_type(
filtered_preprocessor_list,
filtered_model_list,
default_option,
default_model,
):
return {
"module_list": filtered_preprocessor_list,
"model_list": filtered_model_list,
"default_option": default_option,
"default_model": default_model,
}
return {
"control_types": {
control_type: format_control_type(
*global_state.select_control_type(control_type)
)
for control_type in Preprocessor.get_all_preprocessor_tags()
}
}

@huchenlei huchenlei closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2024
@altoiddealer
Copy link
Author

We already have /controlnet/control_types API endpoint to return the filtered preprocessor/models.

models are futher filtered by the active SD version. You can obtain SD version from existing A1111 API.

Revelant code:

@app.get("/controlnet/control_types")
async def control_types():
def format_control_type(
filtered_preprocessor_list,
filtered_model_list,
default_option,
default_model,
):
return {
"module_list": filtered_preprocessor_list,
"model_list": filtered_model_list,
"default_option": default_option,
"default_model": default_model,
}
return {
"control_types": {
control_type: format_control_type(
*global_state.select_control_type(control_type)
)
for control_type in Preprocessor.get_all_preprocessor_tags()
}
}

At first I thought you were pulling my leg, but you are 100% correct. Hot damn that is amazing!

This is a colossal blunder by sd-webui-forge - I made this report because I thought ControlNet lacked such an API endpoint.

...Wrong! Only Forge is missing it. SMH.

This is immensely useful. Such a shame that Forge doesn't have it.

@altoiddealer
Copy link
Author

altoiddealer commented Apr 26, 2024

@huchenlei proud to say, I actually made this happen.

I consider myself a bottom tier coder, but after a crap ton of guess-and-check and asking ChatGPT for help I managed to do this thing.

Now, hopefully Forge merges this.

lllyasviel pushed a commit to lllyasviel/stable-diffusion-webui-forge that referenced this issue Aug 1, 2024
Restores the '/controlnet/control_types' API endpoint, which is immensely useful for anyone using ControlNet via the API

## Description

I recently opened an Issue on the main ControlNet extension repo Mikubill/sd-webui-controlnet#2737 suggesting that they add a new API endpoint to allow users to retrieve filtered data based on a Control Type, just like in the UI.

I was both shocked and immensely disappointed when they finally replied, stating that the endpoint does already exist!

I understand that Forge is a massive overhaul to A1111, so perhaps this aspect was removed to get everything working, and then just never reimplemented.

Whatever the case, this endpoint is truly amazing for using ControlNet via API.  With only the 'models' and 'modules' endpoints, how the heck is someone to make a dynamic script?  They would essentially have to take a fat chunk of existing ControlNet code, plus these few added functions, just to filter the data appropriately.

I'm an amateur coder, at best, however I'm quite confident about this implementation.

This uses your existing functions as best as possible, I believe, including your filter list and the check for currently loaded SD model version.

Please merge this.

Thank you

## Screenshots/videos:

<img width="1136" alt="Restored" src="https://github.com/lllyasviel/stable-diffusion-webui-forge/assets/1613484/8996c3f2-27be-4405-b0cd-7f05f3eaa2d2">

[response_1714160176770.json](https://github.com/lllyasviel/stable-diffusion-webui-forge/files/15134692/response_1714160176770.json)

## Checklist:

- [X] I have read [contributing wiki page](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Contributing)
- [X] I have performed a self-review of my own code
- [X] My code follows the [style guidelines](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Contributing#code-style)
- [X] My code passes [tests](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Tests)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants