Slack Diffusion
Slack bot for generating images with Stable Diffusion
![dylan hacking a slack diffusion bot together](https://github.com/dbut2/slack-diffusion/raw/6a420799fed6/example.jpg)
Usage
Prereqs
You will need to create some resources outside of this project in order to get it to work. The required resources and their information we will need is as follows:
- Hugging Face
- Slack
- Create a Slack app with the following user scopes
- Note Signing Secret, Client ID and Client Secret for later
- GCP
- Create Pub/Sub topic and subscription
- Storage bucket for image uploads
- Note Topic, Subscription and Bucket for later
Build
Only the request processor here is required to be built, this can be done as follows:
$ docker build -t slack-diffusion .
Run
This can be deployed using any method you wish that is publicly accessible. Should you choose to use Google Cloud Functions, all the required code in this project can be found in functions.zip
.
Required env vars
PROJECT_ID
// GCP Project ID
Once function has been deployed, update request URL in Slack to point to deployment.
This can be deployed using any method you wish that is publicly accessible. Should you choose to use Google Cloud Functions, all the required code in this project can be found in functions.zip
.
Required env vars
PROJECT_ID
// GCP project ID
PUBSUB_TOPIC
// Pub/Sub topic created earlier
SLACK_SIGNING_SECRET
// Slack signing secret (recommend using Google Secret Manager here if running on Cloud Functions)
SLACK_CLIENT_ID
// Slack client ID (recommend GSM)
SLACK_CLIENT_SECRET
// Slack client secret (recommend GSM)
Once function has been deployed, create a slash command in Slack and point to deployment.
At this point you should be able to successfully call the diffusion bot from within Slack, with status hanging on Sending...
Request processor / Image generation main.main
Ensure your application-default-credentials have been updated with $ gcloud auth login --update-adc
.
Recommended to run on a machine with graphics card with >8GB memory.
$ docker run --rm --gpus=all \
-v huggingface:/home/huggingface/.cache/huggingface \
-v ~/.config/gcloud:/home/huggingface/.config/gcloud \
--env-file docker.envs \
slack-diffusion
The following environment variables can be filled into docker.envs
Required env vars
HUGGINGFACE_TOKEN
// user access token from Hugging Face
PROJECT_ID
// GCP project ID
PUBSUB_SUBSCRIPTION
// Pub/Sub subscription created earlier
STORAGE_BUCKET
// Storage bucket created earlier
Optional env vars
IMAGE_WIDTH
// width of generated images, must be divisible by 8, defaults to 512
IMAGE_HEIGHT
// height of generated images, must be divisible by 8, defaults to 512
You should now be able to generate images through Slack using Stable Diffusion, great success 👍
Thanks
Based on works by: