AmericanPresidentJimmyCarter / yasd-discord-bot

Yet Another Stable Diffusion Discord Bot
MIT License
111 stars 15 forks source link
artificial-intelligence clip diffusion discord discord-bot generative-art image2image img2img inpainting outpainting python3 stable-diffusion text2image txt2img upscaling

Yet Another Stable Diffusion Discord Bot

Yet Another Stable Diffusion Discord Bot Splash Image

Live now on the LAION Discord Server for you to try!

LAION Discord Server

Features

Contents

Changelog

Content advisory

This bot does not come equipped with a NSFW filter for content by default and will make any content out of the box. Please be sure to read and agree with the license for the weights, as well as the MIT license, and abide by all applicable laws and regulations in your respective area.

To enable the NSFW filter to automatically add the spoiler tag to any potential NSFW images, use the flag --nsfw-auto-spoiler. You must first pip install -r requirements_nsfw_filter.txt to get the modules required for this.

To enable NSFW prompt detection via BERT, use the flag --nsfw-prompt-detection and be sure to pip install -r requirements_nsfw_filter.txt.

To reject any prompts if they contain a word within a wordlist, use the --nsfw-wordlist flag, e.g. --nsfw-wordlist bad_words.txt. The wordlist should be strings separated by newlines.

What do I need?

Python 3 3.9+ with pip and virtualenv installed (Ubuntu 22.04 works great!)

CUDA runtime environment installed

An NVIDIA GPU with >= 7 GB of VRAM

If running with a low VRAM GPU, you will not have access to the >upscale endpoint as you will run out of RAM. Buying an RTX 3090 or renting a server with one is recommended.

Installation

This installation is intended for debian or arch flavored linux users. YMMV. You will need to have Python 3 and pip installed.

sudo apt install python3 python3-pip
sudo pip3 install virtualenv

Docker installation (docker image)

Install the Nvidia docker container environment if you have not already.

Pull the dalle-flow docker image with:

docker pull jinaai/dalle-flow:latest

Log into Huggingface, agree to RunwayML's terms of service, go to RunwayML's repository for the latest version, then download sd-v1-5-inpainting.ckpt. Rename that to model.ckpt and then, from that directory, run the following commands:

mkdir ~/ldm
mkdir ~/ldm/stable-diffusion-v1
mv model.ckpt ~/ldm/stable-diffusion-v1/model.ckpt

Then run the container with this command:

sudo docker run -e DISABLE_CLIP="1" \
  -e DISABLE_DALLE_MEGA="1" \
  -e DISABLE_GLID3XL="1" \
  -e ENABLE_CLIPSEG="1" \
  -e ENABLE_REALESRGAN="1" \
  -e ENABLE_STABLE_DIFFUSION="1" \
  -p 51005:51005 \
  -it \
  -v ~/ldm:/dalle/stable-diffusion/models/ldm/ \
  -v $HOME/.cache:/home/dalle/.cache \
  --gpus all \
  jinaai/dalle-flow

Somewhere else, clone this repository and follow these steps:

git clone https://github.com/AmericanPresidentJimmyCarter/yasd-discord-bot/
cd yasd-discord-bot
python3 -m virtualenv env
source env/bin/activate
pip install -r requirements.txt

Then you can start the bot with:

cd src
python -m bot YOUR_DISCORD_BOT_TOKEN -g YOUR_GUILD_ID

Be sure you have the "Message Content Intent" flag set to be on in your bot settings!

Where YOUR_DISCORD_BOT_TOKEN is your token and YOUR_GUILD_ID is the integer ID for your server (right click on the server name, then click "Copy ID"). Supplying the guild ID is optional, but it will result in the slash commands being available to your server almost instantly. Once the bot is connected, you can read about how to use it with >help.

The bot uses the folders as a bus to store/shuttle data. All images created are stored in images/.

OPTIONAL: If you aren't running jina on the same box, you will need change the address to connect to declared as constant JINA_SERVER_URL in imagetool.py.

Docker installation (build docker image yourself)

Install the Nvidia docker container environment if you have not already.

Make a folder for dalle-flow:

mkdir ~/dalle
cd ~/dalle
git clone https://github.com/jina-ai/dalle-flow
cd dalle-flow

Log into Huggingface, agree to RunwayML's terms of service, go to RunwayML's repository for the latest version, then download sd-v1-5-inpainting.ckpt. Rename that to model.ckpt and then, from that directory, run the following commands:

mkdir ~/ldm
mkdir ~/ldm/stable-diffusion-v1
mv model.ckpt ~/ldm/stable-diffusion-v1/model.ckpt

In the dalle-flow folder (cd ~/dalle/dalle-flow), build with this command:

docker build --build-arg GROUP_ID=$(id -g ${USER}) --build-arg USER_ID=$(id -u ${USER}) -t jinaai/dalle-flow .

Then run the container with this command:

sudo docker run -e DISABLE_CLIP="1" \
  -e DISABLE_DALLE_MEGA="1" \
  -e DISABLE_GLID3XL="1" \
  -e ENABLE_CLIPSEG="1" \
  -e ENABLE_REALESRGAN="1" \
  -e ENABLE_STABLE_DIFFUSION="1" \
  -p 51005:51005 \
  -it \
  -v ~/ldm:/dalle/stable-diffusion/models/ldm/ \
  -v $HOME/.cache:/home/dalle/.cache \
  --gpus all \
  jinaai/dalle-flow

Somewhere else, clone this repository and follow these steps:

git clone https://github.com/AmericanPresidentJimmyCarter/yasd-discord-bot/
cd yasd-discord-bot
python3 -m virtualenv env
source env/bin/activate
pip install -r requirements.txt

Then you can start the bot with:

cd src
python -m bot YOUR_DISCORD_BOT_TOKEN -g YOUR_GUILD_ID

Be sure you have the "Message Content Intent" flag set to be on in your bot settings!

Where YOUR_DISCORD_BOT_TOKEN is your token and YOUR_GUILD_ID is the integer ID for your server (right click on the server name, then click "Copy ID"). Supplying the guild ID is optional, but it will result in the slash commands being available to your server almost instantly. Once the bot is connected, you can read about how to use it with >help.

The bot uses the folders as a bus to store/shuttle data. All images created are stored in images/.

OPTIONAL: If you aren't running jina on the same box, you will need change the address to connect to declared as constant JINA_SERVER_URL in imagetool.py.

Native installation

Follow the instructions for dalle-flow to install and run that server. The steps you need to follow can be found under "Run natively". Once flow is up and running, proceed to the next step.

At this time, if you haven't already, you will need to put the stable diffusion weights into dalle/stable-diffusion/models/ldm/stable-diffusion-v1/model.ckpt.

Need to download the weights? Log into Huggingface, agree to RunwayML's terms of service, go to RunwayML's repository for the latest version, then download sd-v1-5-inpainting.ckpt. Rename that to model.ckpt and put it into the location specified above.

To start jina with old models disabled when you're all done:

python flow_parser.py --enable-stable-diffusion --disable-dalle-mega --disable-glid3xl
jina flow --uses flow.tmp.yml

Jina should display lots of pretty pictures to tell you it's working. It may take a bit on first boot to load everything.

Somewhere else, clone this repository and follow these steps:

git clone https://github.com/AmericanPresidentJimmyCarter/yasd-discord-bot/
cd yasd-discord-bot
python3 -m virtualenv env
source env/bin/activate
pip install -r requirements.txt

Then you can start the bot with:

cd src
python -m bot YOUR_DISCORD_BOT_TOKEN -g YOUR_GUILD_ID

Be sure you have the "Message Content Intent" flag set to be on in your bot settings!

Where YOUR_DISCORD_BOT_TOKEN is your token and YOUR_GUILD_ID is the integer ID for your server (right click on the server name, then click "Copy ID"). Supplying the guild ID is optional, but it will result in the slash commands being available to your server almost instantly. Once the bot is connected, you can read about how to use it with >help.

The bot uses the folders as a bus to store/shuttle data. All images created are stored in images/.

OPTIONAL: If you aren't running jina on the same box, you will need change the address to connect to declared as constant JINA_SERVER_URL in imagetool.py.

What can it do?

Examples:

>image A United States twenty dollar bill with [Jerry Seinfeld, Jason Alexander, Michael Richards, Julia Louis-Dreyfus]'s portrait in the center (seed=2)

Seinfeld actors on money

>image2image Still from Walt Disney's The Princess and the Frog, 2001 (iterations=4, strength=0.6, scale=15)

Attached image

Vermeer's Girl with a Pearl Earring

Output image

Vermeer's Girl with a Pearl Earring diffused into Disney's Princess and the Front

>interpolate Sonic the Hedgehog portrait | European Hedgehog Portrait

Interpolation of Sonic the Hedgehog portrait to European Hedgehog Portrait

Something is broken

Open an issue here.

Closing remarks

Be cool, stay in school.

License

Copyright 2022 Jimmy (AmericanPresidentJimmyCarter)

MIT