Skip to content

maltob/slack-txtoimgbot

Repository files navigation

SD - Bot

This bot allows for you to have access to stable diffusion at your fingertips!

Use

  1. @ the bot with the text you would like to generate
  2. It will send a photo to you shortly after

Advanced use

  1. You can send negative prompts to filter out items you would like to exclude by using -= or -- at the end of your prompt like below
-= Additive negative prompt

soup -= chicken, turkey, tomato would inform stable diffusion to avoid generating soups with chicken, turkey or tomato. This will still include any default negative prompts from the .env file.

-- Exclusive negative prompt

soup -- chicken, turkey, tomato would inform stable diffusion to avoid generating soups with chicken, turkey or tomato. This will override any default negative prompts from the .env file.

Installation

  1. Clone this repository to a folder with at least 5 GB free
git clone https://github.com/maltob/slack-txtoimgbot.git
  1. Open the directory
cd slack-txttoimgbot
  1. Create a venv
python -m venv venv
venv/Scripts/activate.ps1
  1. Install the requirements.txt
pip install -r requirements.txt
  1. Download the stable diffusion repository for the bot
huggingface-cli login
git clone https://huggingface.co/CompVis/stable-diffusion-v1-4

# or if you have less than 8 GB RAM/need FP16 for some other reason

huggingface-cli login
git clone --branch fp16 https://huggingface.co/CompVis/stable-diffusion-v1-4
  1. Copy example.env to just .env ; then open .env
cp example.env .env
notepad .env
  1. Create the Slack app for your team at https://api.slack.com/apps by importing the slack_manifest.yml
  2. Install to your workspace under OAuth in Slack. Copy the xobb value to set SLACK_BOT_TOKEN= in the .env
  3. In Slack App management, open basic information and copy signing secret to the SLACK_SIGNING_SECRET= in .env
  4. Further down in basic information generate an App-level token and copy it to the SLACK_APP_TOKEN= in the .env file
  5. You can now run the bot. If you get an error, remember to activate the venv with venv/Scripts/activate.ps1
python bot.py

.env config options

SD_IMG_WIDTH and SD_IMG_HEIGHT

Set the generated image size. One should be no more than 512 and both should be a multiple of 8

SD_PRECISION

Set to fp16 for lower precision to save VRAM on cards with less VRAM such as a GTX 1070 or GTX 3060

SD_MODEL_PATH

Relative path to the downloaded stable diffusion model. There should be a model_index.json inside the folder

SD_MODEL_AUTH_TOKEN

Authentication token to access the model from hugging-face. See https://huggingface.co/settings/tokens to generate one

SD_BENCHMARK

Set to false to not run a generation benchmark when running the bot. It will default to saying give 45 seconds for image to be generated

SD_GUIDANCE_SCALE

Defaults to 7.5; set higher to have less variance in images/more strongly correlated images

SD_ITERATIONS

Defaults to 50; set higher for higher quality images with slower generation

SD_NEGATIVE_PROMPT

Set to words you want to avoid such as low-res

SD_SCHEDULER

Change the scheduler. Defaults to DDIM. Valid options are LMS, PNDM, and KARRASVE.