AndBobsYourUncle / stable-diffusion-discord-bot

A Discord bot, written in Go, that interfaces with the Automatic 1111's API interface.
MIT License
128 stars 35 forks source link

Feature Request - Ability to set a style #6

Open bitburner opened 1 year ago

bitburner commented 1 year ago

In the API there is a way to set a "style" to use:

http://127.0.0.1:7860/docs#/default/text2imgapi_sdapi_v1_txt2img_post

"styles": [
    "string"
  ],

Where "string" is the name of the saved style in A1111. Styles are essentially just saved positive/negative prompts stored in a styles.csv in the root of A1111 folder. In the API it should be useful to add positive/negative prompts to a users prompt that they don't see (This is somewhat the magic behind MidJourney's bot). Styles solve this problem. Styles can also insert the users prompt into itself with a {prompt} in the style. This is added not as part of the "prompt" field for the API so the user should never see it, it's kind of like a backend style wrapper for prompts. If I concatenate extra positive prompts to the "prompt" in your backend files it will always be returned to the user and they will see the added positive prompts. Styles are a way to do this without the user ever seeing it but it's still part of the prompt when actually submitted to be rendered.

I think you're working on some way to set variables like sampler/cfg in a file users can configure or similar. Would be great to be able to set a style there. There are 2 styles and why it's an array, but I'd be happy with the ability to set one.

AndBobsYourUncle commented 1 year ago

Ah yeah, this is a great feature to add, and likely something that wouldn't be too difficult.

What might be really nice is for it to be stored alongside the bot settings just like the dimensions are stored now. Also, would be nice for the bot to request the available styles from the API, populating the choices when updating the setting for the settings dropdown.

bitburner commented 1 year ago

There is a command in the API to get the list of styles:

http://127.0.0.1:7860/docs#/default/get_prompt_styles_sdapi_v1_prompt_styles_get

AndBobsYourUncle commented 1 year ago

One interesting thing that I thought about is what if there is a grid of images generated with a style that no longer exists, and then the user wants to upscale that image?

Since the style is no longer found, the upscale would result in a completely different image.

The bot doesn't store any of these images locally, and instead relies on the AI being deterministic to be able to reproduce the source image that is then passed to the upscaler.

Same with image variations. It is using the seed and original txt2img request to ask for the same seed, and random subseeds.

AndBobsYourUncle commented 1 year ago

A proposal I can think of is that, since styles are ephemeral, the bot simply stores the style settings along with the image generation.

That way, even if you delete the style right after someone issues the imagine command, upscales and variations will still work, since it would pull from the stored "style" prompt and negative prompt additions.

bitburner commented 1 year ago

I actually implemented styles as I only have one I need to activate. I think it works great. I don't know go lang so it took me a few hours of trial and error. I also moved the reroll button to a new row on the bottom. I'm going to watch some tutorial videos on git as there is probably a way to create a branch for you to see what I did but I'm not sure how to do that.

AndBobsYourUncle commented 1 year ago

Oh nice!

Yeah, for PRs in a project like this, you'd want to fork this repo to your own Github account. Using that, you could open a PR from your fork to mine. That would show all the changes between your version of the repo and mine.

Screenshot 2023-01-10 at 4 03 11 PM
AndBobsYourUncle commented 1 year ago

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork

yo1nkers commented 1 year ago

Hi, Just wondering if you've still considered trying to implemenet styles?