A self-hosted discord bot running Stable Diffusion 1.4.
- Get a discord bot token, connect it to your server. TODO: document
- Get a huggingface token. TODO: document
- Run the docker image jamesrom/discord-diffusion:latest
Example:
docker run --rm -it --gpus=all \
--volume $PWD\huggingface:/home/huggingface/.cache/huggingface \
--volume $PWD\output:/home/huggingface/output \
--env DISCORD_TOKEN=$BOT_TOKEN_HERE> \
--env HUGGINGFACE_TOKEN=$HF_TOKEN_HERE \
jamesrom/discord-diffusion:latest
Configure by environment variables:
Variable | Default | Description |
---|---|---|
DISCORD_TOKEN required |
— | Discord token. |
HUGGINGFACE_TOKEN required |
— | Huggingface token. |
DEFAULT_HEIGHT |
512 |
Must be divisible by 8. |
DEFAULT_SEED |
Random | Set the default seed for reproducibility. Must be an integer. |
DEFAULT_WIDTH |
512 |
Must be divisible by 8. |
FILE_FORMAT |
jpeg |
Must be jpeg or png . |
MAX_COUNT |
5 |
Set the maximum number of generated images per command. If set to 1, will disable the command option altogether. |
MAX_HEIGHT |
2048 |
Maximum height of generated images. |
MAX_WIDTH |
2048 |
Maximum width of generated images. |
NSFW_GLOBAL_ENABLE |
false |
Bypass the built-in safety check globally. |
NSFW_IN_AGE_RESTRICTED_CHANNELS |
true |
Disable the safety check only in Age-Restricted Channels. |
NSFW_USER_OVERRIDE |
false |
Allow the user to disable the safety check with the nsfw command option. |
SAVE_IMAGE_TO_DISK |
false |
Whether to save a copy of the generated image to disk. |
SD_ATTENTION_SLICING |
false |
Use less memory at the cost of speed. |
SD_MODEL |
CompVis/stable-diffusion-v1-4 |
The huggingface model to download and use. |
SD_REVISION |
main |
The model revision to use. |
TODO
Type /text2img
and enter your prompt. Optional parameters can be given:
width
- The desired width of the generated image. Must be divisible by 8 and smaller than the configuredMAX_WIDTH
.height
- The desired width of the generated image. Must be divisible by 8 and smaller than the configuredMAX_HEIGHT
.count
- The number of images to generate. IfMAX_IMAGE_COUNT
is 1, this option will be unavailable.nsfw
- Disable the built-in safety check. This option will be unavailable ifGLOBAL_NSFW_ENABLE
is true, orALLOW_NSFW_USER_OVERRIDE
is false.
At least 8GB recommended. Here's some things you can do if you see memory errors:
- Set
REVISION=fp16
, this uses half-sized tensors (16 bit instead of 32 bit) and should reduce memory footprint by about half. - Enable attention slicing with
ATTENTION_SLICING=true
. This lowers memory requirements at the cost of speed. - Lower
DEFAULT_WIDTH
andDEFAULT_HEIGHT
, similarlyMAX_HEIGHT
andMAX_WIDTH
Easy:
docker buildx build . --tag my-cool-bot
Thanks to the following prior work for inspiration: