Skip to content

A Telegram bot to generate stable diffusion images on request, on your GPU

License

Notifications You must be signed in to change notification settings

scristobal/botatobot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Botatobot 🥔

Yet another Telegram bot, this one generates stable diffusion images on request.

sample image

Yes, but how?

In a nutshell, Botatobot listen for users requests for images and push them in a (bounded) worker queue, the queue gets processed by a server running a Stable Diffusion inside a either locally or as a service, like replicate.com

Pre-requisites

To run Stable Diffusion, you have two options:

To run the Telegram bot server you need Go and a Telegram account.

Host a Cog Stable Diffusion server on your machine 🐳

First you need to install Cog, Docker and the NVIDIA Container Toolkit.

Then clone the pre-configured cog-stable-diffusion repository. Follow their instructions in the README to ensure the model is running correctly.

In particular you need to download the weights first

cog run script/download-weights

build your container with

cog build -t stable-diffusion

and run it with

docker run -d -p 5001:5000 --gpus all stable-diffusion

This will download, create and run a container with the stable diffusion image running on port 5001, eg.http://127.0.0.1:5001/predictions

Getting a Replicate.com token and model version

Go to Replicate.com api-tokens and generate your token, keep it safe.

You will also need to choose a Stable Diffusion model version. You can find the available versions here https://replicate.com/stability-ai/stable-diffusion/versions

Getting a Telegram bot token 🤖

  1. Talk to @BotFather on Telegram
  2. Send /newbot to create a new bot
  3. Follow the instructions to set a name and username for your bot
  4. Copy the token that BotFather gives you

The token looks like this: 123456789:ABCDEF1234567890ABCDEF1234567890ABC

Configure and run Botatobot 🥔

Configure

If running Stable Diffusion locally

Set the following environment variables or create a .env file with the following content:

TELEGRAMBOT_TOKEN=123456789:ABCDEF1234567890ABCDEF1234567890ABC
MODEL_URL=http://127.0.0.1:5001/predictions

The BOT_TOKEN you got from the @BotFather, and MODEL_URL indicates where the Cog Stable Diffusion is running, most likely a docker container in your local machine.

There is an optional variable OUTPUT_PATH that indicates the path where the generated images will be saved.

If using replicate.com

You need the Telegram and Replicate tokens and the Stable Diffusion model version, create an .env file or make them available in the environment.

BOT_TOKEN=123456789:ABCDEF1234567890ABCDEF1234567890ABC
REPLICATE_TOKEN=1234567890abdfeghijklmnopqrstuvwxyz
REPLICATE_VERSION=a9758cbfbd5f3c2094457d996681af52552901775aa2d6dd0b17fd15df959bef

The BOT_TOKEN you got from the @BotFather,REPLICATE_TOKEN and REPLICATE_VERSION you get from replicate.com.

Additionally you can set REPLICATE_URL to a custom url, and OUTPUT_PATH to indicate the path where the generated images will be saved.

Build and run

Build withgo build -o build/botatobot cmd/botatobot/main.go and then run ./build/botatobot

Usage

Tell the bot /help to let him self explain.

Notes

In some scenarios, like deploying to Heroku or other platforms you need a http rest health endpoint. Botatobot includes such functionality, to activate it include a LOCAL_PORT variable.

Acknowledgments

Botatobot uses the excellent go-telegram package to interact with the Telegram API. Go check it out!

About

A Telegram bot to generate stable diffusion images on request, on your GPU

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published