Skip to content

Api changes #316

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

Closed
wants to merge 17 commits into from
Closed

Api changes #316

wants to merge 17 commits into from

Conversation

graemeniedermayer
Copy link
Contributor

So this is where I am with allowing api in standalone + updating the api.

The standalone api should be working when the options --api is enabled.

There's still a lot of things missing like the gradio auto documentation is pretty bad. I would like auto docs + wiki docs eventually (wiki docs really needs to include dates). There's some clunky stuff in the api_constants.py that eventually I'd like to remove, but it doesn't seem so bad for now.

I'm going to be heading away for a couple of days. So if you did want to try to integrate the api, hopefully this is helpful. I'll format it and rigorously test when I return.

Maybe having a dedicated api branch would be helpful too?

semjon00 and others added 16 commits July 24, 2023 13:27
Refactored GradioComponentBundle
Hide/unselect depthmap generation/output options if using custom depthmap
New stereoimage outputs
Preparing to change the algo again...
* "Viewing" deleted, as it's info was moved to a separate page in the wiki
* "Forks and Related"->"Generate normal maps" deleted, now a feature is this repo
* Changelog moved to a separate file
* Added 0.4.3 changelog
Also updated some parts of the README. Other parts still need updating.
Video mode fixes

Video mode fixes
@semjon00
Copy link
Collaborator

semjon00 commented Aug 1, 2023

@graemeniedermayer Thanks for the effort! API is a very good feature to expand. Great to see that standalone API can be done (Gradio-less would be even better). The code needs some changes before we can safely allow users to use it (so they are not confused and there is less breakage in the future) - I've dropped some comments on how it could be done. Please read them all before changing the code.

Btw, there has been requests to add API for other features that we provide - but this could be added after otherwise it looks good.

@@ -2,80 +2,12 @@
# (will only be on with --api starting option)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is too small now, please move enerything into srcipts/depthmap.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

"GEN_INPAINTED_MESH": False
}

#model diction TODO find a way to remove without forcing people do know indexes of models
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong place: only accounts for the API, but this is something that better would be used when options are parsed by the core_generation_funnel. Btw, core_generation_funnel should not use ints as model numbers, it should be enum. When inputs are processed, numbers, strings, display strings, etc. should be converted into Enums. Some work, yes, but this would be the proper way to do it. Also, please do not duplicate model names - there should be either one copy, or two copies (formal and what we display in the UI) at the same place.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The model names can't only exist in the gradio ui. The names are either going to need to be duplicated or moved.

MODEL_TYPE = "res101" # Will become enum element

I assume the names will eventual exist here? That would be a better location to important them from.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

@@ -0,0 +1,32 @@

api_options = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'outputs' would lead only to more confusion I think. The right way to go is specifying "GEN_STEREO" ir something like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of the options output a lot of extras that can be really heavy on a networking. 1mb images can really add up and sometimes we make 1-2 extra images. Maybe this should be more hidden but I often want more control over the output (sometimes I don't want the depthmap).

There might be an more elegant solution but I think it's helpful to have control over the returning images.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This already can be controlled, no option generates more images than asked.

#TODO try-catch type errors here
for key, value in client_options.items():
if key == "model_type":
default_options[key] = models_to_index[value]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be inside CoreGenerationFunnelInp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll have less control over api specific commands if we do it this way. I don't like moving api code into core.py because of separation of concerns.

I might be misunderstanding.


def api_gen(input_images, client_options):

default_options = CoreGenerationFunnelInp(api_defaults).values
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CoreGenerationFunnelInp dependency and accessing it's inner workings is not required here. Simply get api_defaults and modify them. Also bad variable name.

from src.api.api_core import api_gen, encode_to_base64

# gr.Blocks is needed for auto1111 extensions
def depth_api(_: gr.Blocks, app: FastAPI):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocks object goes into memory hole right after it is supplied. I assume nothing depends on it. It should be removed (unnecessary argument).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a type-hint so it shouldn't be given memory.

It can be changed to

def depth_api(_, app: FastAPI): or maybe def depth_api(_grBlocks, app: FastAPI): to help with context?

This function is being given to auto1111 so the unused argument can't be removed.

if args.api is not True:
ui_block.launch(share=args.share, server_name=server_name)
else:
app, _, _ = ui_block.launch(share=args.share, server_name=server_name, prevent_thread_lock=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is prevent_thread_lock? About locks: core_generation_funnel is not "multithread-safe" - at most one thread can yield from it at the same time - otherwise everything breaks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't about multithreading this is about blocking the main thread. Without it no code below is executed. In order to attach the api to the same port as the webui you need to have code afterwards. This option is also enabled in auto1111 with the --api option and it doesn't cause any issues with this extension (https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/master/webui.py).

My understanding is almost every python webserver is single threaded and the strategy with python is usually to just run multiple single threaded apps as workers rather than multi-threading.

@@ -29,6 +29,7 @@ def maybe_chdir():
parser = argparse.ArgumentParser()
parser.add_argument("--share", help="Create public link", action='store_true')
parser.add_argument("--listen", help="Create public link", action='store_true')
parser.add_argument("--api", help="start-up api", action='store_true')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent: capitalize

init_api(ui_block, app)
while True:
pass

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace at the end of the file


#TODO add CORS

#TODO enable easy SSL. right now completely unsecured.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be an option - self-signed certs might scare some non-tech-savvy users.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self-signed cert are such a headache.

It probably make more sense to make a docker image with some nginx proxy/letsencrypt combo for people who actually want ssl/cors.

@semjon00
Copy link
Collaborator

semjon00 commented Aug 1, 2023

Hope it is useful :)

@semjon00
Copy link
Collaborator

@graemeniedermayer Sorry for being absent for some time. Would you still like to mainline this? There need to be some changes... Maybe extract the most important changes into a separate MR - usually mainlining small changes is easier than large changes.

@graemeniedermayer
Copy link
Contributor Author

@semjon00 Sorry I've gotten quite busy as well. I'll try to get to this in the next few days!

@semjon00 semjon00 deleted the branch thygate:next February 10, 2024 14:50
@semjon00 semjon00 closed this Feb 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants