Opensource Self-hosted StableDiffusion Discord bot
996
This is the Docker image of the first version of my Discord bot software named "DeguDiffusion", that allows you to run your own self-hosted AI images generation Discord bot using a local StableDiffusion installation.


The software is available under MIT license.
The concept behind it is simple :
.env file as DISCORD_TOKEN./degudiffusion notably) on the servers it has been invited
to.You can of course run the bot inside Docker, while being connected to Discord with another account on the same machine.
.env
# Make sure your bot has sufficient rights and privileges.
# Write your Discord bot token after the '='. No quotes needed.
DISCORD_TOKEN=
# Make sure you accepted the license on
# https://huggingface.co/CompVis/stable-diffusion-v1-4
# Write your Huggingfaces token after the '='. No quotes needed.
HUGGINGFACES_TOKEN=
docker-compose.yml
version: "3.9" # optional since v1.27.0
services:
degu:
image: vrvoyage/degudiffusion:1.1
build: .
env_file: .env
environment:
- STABLEDIFFUSION_CACHE_DIR=stablediffusion_cache
- IMAGES_OUTPUT_DIRECTORY=generated # Can be commented if SAVE_IMAGES_TO_DISK is set to false
# - SAVE_IMAGES_TO_DISK=false # If you uncomment this, you can comment the first volume
volumes:
- ./generated:/app/generated # Only required if SAVE_IMAGES_TO_DISK=false isn't set
- ./cache:/app/stablediffusion_cache # Related to STABLEDIFFUSION_CACHE_DIR
- ./config:/app/config # Can be mounted in Read-Only if a 'replacers.json' file is already present
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
docker-compose up
As you can understand, the server is required to have access to a GPU.
The only tested setup is Windows / NVIDIA Graphics Card / CUDA.
This setup has not been tested at all with CPU only setup.
This setup has not been tested at all with ROCM.
Ensure that you can use the GPU through Docker.
A Discord Bot Token.
Environment variable : DISCORD_TOKEN
See below for more information about how to create and register your
own bot on Discord, and how to retrieve its token.
A HuggingFaces Token.
Environment variable : HUGGINGFACES_TOKEN
This is required to download the weights the first time.
Once done, you can set the environment variable
STABLEDIFFUSION_LOCAL_ONLY=true to reuse the local files,
in which case HUGGINGFACES_TOKEN isn't required anymore.
Accepting the licence terms of StableDiffusion
The licence is pretty permissive, but to download the weights from
HuggingFaces, you'll have to click on the accept button on the
page :
https://huggingface.co/CompVis/stable-diffusion-v1-4
Setting up the DISCORD_TOKEN and HUGGINGFACES_TOKEN environment variables.
You can leave other intents disabled.
botapplication.commandsbot and application.commands) and PERMISSIONS.You can also send this link to others servers admins who'd like to invite the bot to their servers.
DISCORD_TOKEN in the .env file.If the permissions were wrong :
Set the permissions again on both panels
Open the new URL in your browser and invite the Bot again on the same server.



If you don't know it, click on "Reset Token" in the "Bot" section of your application. You can view your application settings on the Discord Developer Portal.

IMAGES_OUTPUT_DIRECTORY
Define where you want to store the generated pictures.
Default : generated
Spaces are allowed. No need to use quotes.
The directory will be created if it doesn't exist.
Example : IMAGES_OUTPUT_DIRECTORY=another folder
This setting is ignored when
SAVE_IMAGES_TO_DISKis set tofalse.
SAVE_IMAGES_TO_DISK
Define whether generated files are saved on the disk or not.
Default : true
Example : SAVE_IMAGES_TO_DISK=false
STABLEDIFFUSION_MODE
Allows you to select between different StableDiffusion modes.
Default : fp32
Currently only fp16 and fp32 are supported.
VRAM usage is lower in fp16, so if you're low on VRAM,
set this to fp16.
Example : STABLEDIFFUSION_MODE=fp16
MAX_IMAGES_PER_JOB
Maximum number of images to output per job request.
Default : 64
That means that the NUMBER OF IMAGES typed in /degudiffusion
form will be clamped to that maximum value.
Example : MAX_IMAGES_PER_JOB=8
MAX_INFERENCES_PER_IMAGE
Maximum number of inferences steps per image.
Default : 120
This clamps the INFERENCES number typed in /degudiffusion
form to that maximum value.
Example : MAX_INFERENCES_PER_IMAGE=30
MAX_GUIDANCE_SCALE_PER_IMAGE
Maximal guidance scale allowed.
Default : 20
This clamps the GUIDANCE SCALE number typed in /degudiffusion
form will be clamped to that maximum value.
Example : MAX_GUIDANCE_SCALE_PER_IMAGE=7.5
IMAGES_WIDTH and IMAGES_HEIGHT
The width and height of generated images.
Default : 512
Be EXTREMELY careful with this one, VRAM usage grows dramatically
when using higher values.
I highly recommend to switch to fp16 when using more than 512x512.
Going below 512 in any direction will generally lead to garbage results.
Example :
IMAGES_WIDTH=768
IMAGES_HEIGHT=768
MAX_IMAGES_BEFORE_THREAD
The number of images after which the bot will automatically create a thread.
Default : 2
That means that if you set it to 5 :
When requesting up to 5 images per job, the bot will output everything
on the channel from where the job request was done.
When requesting 6 images or more, the bot will create a thread and
send the results inside this thread.
Example : MAX_IMAGES_BEFORE_THREAD=5
COMPACT_RESPONSES
When set to True or true, the job response will only include the pictures,
without any further details (like the Seed, Actual Prompt.).
Default : false
Example : COMPACT_RESPONSES=True
You can still use "Check Degu PNG Metadata" when using compact responses.
DEFAULT_IMAGES_PER_JOB
The default NUMBER OF IMAGES used in /degudiffusion form.
Default : 8
Example : DEFAULT_IMAGES_PER_JOB=3
DEFAULT_PROMPT
The default PROMPT used in /degudiffusion form.
Default : Degu enjoys its morning coffee by {random_artists}, {random_tags}
Example : DEFAULT_PROMPT=A Nendoroid of a Chipmunk by {random_artists}, {lyuma_cheatcodes}
DEFAULT_SEED
The default SEED used in /degudiffusion form.
Default to an empty value.
Note that you don't have to type a SEED value, in Degu Diffusion.
When no seed is provided, a random seed is generated for you.
Example : DEFAULT_SEED=-1
DEFAULT_INFERENCES_STEPS
The default number of INFERENCES used in /degudiffusion form.
Default : 60
Example : DEFAULT_INFERENCES_STEPS=30
DEFAULT_GUIDANCE_SCALE
The default GUIDANCE SCALE used in /degudiffusion form.
Default : 7.5
Example : DEFAULT_GUIDANCE_SCALE=15
SEED_MINUS_ONE_IS_RANDOM
Determine if -1 should be interpreted as a random seed or an actual seed value.
Default : True
By default, now, -1 is treated as a random value, since many users
are used to type -1 to get a random seed.
Note that you don't have to type a SEED value, in Degu Diffusion.
When no seed is provided, a random seed is generated for you.
Example : SEED_MINUS_ONE_IS_RANDOM=false
STABLEDIFFUSION_LOCAL_ONLY
Force StableDiffusionPipeline to use predownloaded local files only, and avoid
connecting to the internet.
Default : false
Example : STABLEDIFFUSION_LOCAL_ONLY=true
When set to true,
HUGGINGFACES_TOKENis not required anymore.
STABLEDIFFUSION_CACHE_DIR
Determine where StableDiffusionPipeline download its files to.
Empty by Default
This is mainly used for Docker setups.
When not set, or set to an empty string, StableDiffusionPipeline will
determine where to download its files.
Example : STABLEDIFFUSION_CACHE_DIR=sd_cache
The directory will be created if it doesn't exist.
STABLEDIFFUSION_MODEL_NAME
Determine the HuggingFaces model used by StableDiffusionPipeline.
Default : CompVis/stable-diffusion-v1-4
Do not change this unless you really know what you are doing.
TORCH_DEVICE
Determine the PyTorch device used. Default to "cuda".
Default : cuda
Any value other that cuda is untested.
Example : TORCH_DEVICE=rocm
FORM_NUMBER_OF_IMAGES_INPUT_MAX
Maximum number of characters allowed for NUMBER OF IMAGES in
/degudiffusion form.
Default : 4
Example : FORM_NUMBER_OF_IMAGES_INPUT_MAX=3
FORM_PROMPT_INPUT_MAX
Maximum number of characters allowed for PROMPT in
/degudiffusion form.
Default : 500
Example : FORM_PROMPT_INPUT_MAX=100
Note that with the default setup, StableDiffusion will parse up to 77 tokens and ignore the rest.
FORM_SEED_INPUT_MAX
Maximum number of characters allowed for SEED in
/degudiffusion form.
Default : 38
Example : FORM_SEED_INPUT_MAX=200
FORM_INFERENCES_INPUT_MAX
Maximum number of characters allowed for INFERENCES in
/degudiffusion form.
Default : 3
Example : FORM_INFERENCES_INPUT_MAX=2
FORM_GUIDANCE_SCALE_INPUT_MAX
Maximum number of characters allowed for GUIDANCE SCALE in
/degudiffusion form.
Default : 6
Example : FORM_GUIDANCE_SCALE_INPUT_MAX=3
Be careful, conversion from float to string adds at least one decimal.
This conversion might lead to errors when using theDEFAULT_GUIDANCE_SCALE, while preparing the form.
For example, ifDEFAULT_GUIDANCE_SCALE=7then the displayed value will be7.0, and will take 3 characters.
IfFORM_GUIDANCE_SCALE_INPUT_MAXis set to2characters, the form will become unuseable.
Content type
Image
Digest
sha256:5718e8e03…
Size
4 GB
Last updated
almost 4 years ago
docker pull vrvoyage/degudiffusion