GithubHelp home page GithubHelp logo

un1tz3r0 / controlnet-discord-bot Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 7 KB

an example stable diffusion controlnet discord bot

Python 100.00%
controlnet diffusers huggingface img2img stable-diffusion

controlnet-discord-bot's Introduction

controlnet-discord-bot

A simple (not really tho) example of a discord bot which runs huggingface diffusers controlnet pipeline (the canny edges one, to be specific) in response to a slash command (/cannyremix <prompt>) with an input image attachment.

It is by no means complete, but should serve as a decent starting point for anyone who wants to implement a discord-bot interface to huggingface's diffusers pipelines.

What is controlnet?

Huggingface has a great blog post where you can read more about all the crazy stuff you can do with controlnet.

Getting Started

Install controlnet dependencies. This should grab torch and everything else you need (I think, feel free to open an issue if I missed something)

pip install diffusers==0.14.0 transformers xformers git+https://github.com/huggingface/accelerate.git

pip install opencv-contrib-python
pip install controlnet_aux

Install janus Queue

pip install git+https://github.com/aio-libs/janus

Install py-cord...

python3 -m pip install -U py-cord --pre

Future

There is a lot left to do here, but the basics are working, the bot will respond with a message containing the intermediate results of the diffusion, and update the image periodically until it gets the final result from the pipeline.

Comments

This was no small feat, as discord.py uses asyncio and diffusers' pipelines are cpu bound and the progress callback isv not async friendly either. we end up needing to run the pipeline inside a thread and use a janus.Queue to send the intermediate and final images back to the async main thread so it can edit the bot's message.

This had me stumped for a good 24 hours or so, and I'm really grateful for [janus]((https://github.com/aio-libs/janus) which made everything work in about 10 minutes once I came across it.

controlnet-discord-bot's People

Contributors

un1tz3r0 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.