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

Stable Diffusion via REST #1500

Merged
merged 24 commits into from
Feb 7, 2023
Merged

Conversation

adodge
Copy link
Contributor

@adodge adodge commented Jan 23, 2023

Hi! Thanks for this project. It's exactly the sort of thing I was looking for. I made some nodes to hook into Automatic1111.

To get it running, you have to set up the service from here: https://github.com/AUTOMATIC1111/stable-diffusion-webui and run it with ./webui.sh --api to expose the REST API. Here are some examples of it working:

Screenshot from 2023-01-23 11-29-23
Screenshot from 2023-01-23 11-44-06

- Exposes a run_async() coroutine
- processed appropriately in process.py
- globals for interacting with the automatic1111 API
- encoding/decoding images from the JSON
- async HTTP call to the API
- Nodes interacting with the automatic1111 API
- text2img, img2img, and interrogate
@joeyballentine
Copy link
Member

This is really cool! Thanks!

I'm not too sure how i feel about relying on a separate server to run this stuff though. It makes sense in that it's a lot easier to not have to integrate everything directly, but i feel like it has the potential to cause lots of issues and incompatibility given enough time. For example if automatic's SD repo updates and makes breaking changes, people would need to use an old version for this to work properly.

This would however be the perfect use case for a plugin once we have the plugin system implemented, but I'll defer to @RunDevelopment on this one to see what he thinks.

@joeyballentine
Copy link
Member

Skimmed through the code. I like that you put this in a separate REST category to make it clear that it's interacting with external things and not anything built into chaiNNer.

If you don't have SD running, do these nodes still show up? What happens in that case?

@adodge
Copy link
Contributor Author

adodge commented Jan 23, 2023

Thanks for taking a look! Yes, all good points.

The nodes do show up, but obviously they report an error if you try to run them. I could have it try to connect to the API when the nodes are imported.

@joeyballentine
Copy link
Member

We're currently talking about this, and we feel the benefits of adding this most likely outweigh any drawbacks. Are you in our Discord server? I think it would be easier to discuss this with you there, if you don't mind

- causes the nodes to be hidden if the API isn't up
- also these options might be useful later
Copy link
Member

@RunDevelopment RunDevelopment left a comment

Choose a reason for hiding this comment

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

Thank you for this @adodge! Great work!

I left you a few comments with questions and suggestions.

backend/src/nodes/impl/rest.py Outdated Show resolved Hide resolved
backend/src/nodes/nodes/rest/__init__.py Outdated Show resolved Hide resolved
backend/src/nodes/nodes/rest/img2img.py Outdated Show resolved Hide resolved
backend/src/nodes/nodes/rest/img2img.py Outdated Show resolved Hide resolved
backend/src/nodes/nodes/rest/img2img.py Outdated Show resolved Hide resolved
backend/src/nodes/nodes/rest/img2img.py Outdated Show resolved Hide resolved
backend/src/nodes/nodes/rest/img2img.py Outdated Show resolved Hide resolved
backend/src/nodes/nodes/rest/img2img.py Outdated Show resolved Hide resolved
backend/src/nodes/impl/rest.py Outdated Show resolved Hide resolved
backend/src/nodes/impl/rest.py Outdated Show resolved Hide resolved
- renaming REST to External Stable Diffusion
- making some text arguments optional
- using sliders where appropriate
- using the "seed" group
- geting rid of async
    - we're already calling the nodes in a thread, so we don't need individual http calls to be async
- replace aiohttp with requests in requirements
@adodge adodge requested review from joeyballentine and RunDevelopment and removed request for RunDevelopment and joeyballentine January 24, 2023 23:02
@adodge
Copy link
Contributor Author

adodge commented Jan 24, 2023

Implemented the feedback given. Here are some new screenshots:

image
image

@joeyballentine
Copy link
Member

joeyballentine commented Jan 24, 2023

The results of this all still get saved by automatic's repo right? Like there's no chance someone would generate something cool but forget to save it and never be able to get it back?

I'll try this out myself when I have some time

@adodge
Copy link
Contributor Author

adodge commented Jan 24, 2023

Weirdly it doesn't save, and I don't see an option in the API to do so. Would be good to have an easy way to do something similar on the ChaiNNer side. Maybe a node that outputs the current time as text, that could be used with the save node.

There's also the problem of saving metadata. The API does give a JSON blob with metadata, so that could be an output from the SD node, and we could hook it into a "Save Text" node.

@adodge
Copy link
Contributor Author

adodge commented Jan 25, 2023

Here's a possible implementation of the saving:

image
image

It's kind of a lot of spaghetti to do something basic. Maybe there could be one node that does it all.

- Added requests library to requirements.ts
- Removed kebab case in favor of "Text to Image"
- Changed LargeImageOutput to ImageOutput
@adodge adodge requested a review from RunDevelopment January 25, 2023 19:22
@adodge
Copy link
Contributor Author

adodge commented Jan 25, 2023

Made a few more changes in response to feedback:

  • Added requests library to requirements.ts
  • Removed kebab case in favor of "Text to Image"
  • Changed LargeImageOutput to ImageOutput

Copy link
Member

@RunDevelopment RunDevelopment left a comment

Choose a reason for hiding this comment

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

Sorry for the delay!

One last thing for the Img2Img and Tex2Img nodes.

Copy link
Member

@RunDevelopment RunDevelopment left a comment

Choose a reason for hiding this comment

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

Sorry about this. Last last last change request.

- Actually looks like SD rounds down to the nearest multiple of 8
- Added slider_step and control_step to SliderInputs
- Added a runtime error if an invalid value is manually entered or piped in
- Would be nice if we could encode this "round down" behavior in the image_type
  expression of the output type, then we could get rid of the runtime error
RunDevelopment
RunDevelopment previously approved these changes Feb 6, 2023
@joeyballentine
Copy link
Member

Whoops. Fix that conflict and I'll merge this

@adodge
Copy link
Contributor Author

adodge commented Feb 7, 2023

@joeyballentine Oops. Done!

Copy link
Member

@joeyballentine joeyballentine left a comment

Choose a reason for hiding this comment

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

Awesome. Thanks again for this

@joeyballentine joeyballentine merged commit fc9fa32 into chaiNNer-org:main Feb 7, 2023
@li1i9 li1i9 mentioned this pull request Apr 17, 2023
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.

3 participants