TG Generator Bot is a Telegram bot designed to generate images based on user input. By communicating with the bot, users can send specific parameters, and the bot will leverage the capabilities of the Draw Things API to produce the desired images.
Draw Things is a standalone application that creates images based on specific models. Before using this bot, ensure that the API switch is activated in Draw Things and that it is set to accept connections from all IPs (0.0.0.0).
To operate the TG Generator Bot on Telegram, you'll need a bot token. Follow these steps:
- Contact the BotFather on Telegram.
- Follow the instructions here to create a new bot and obtain your unique bot token.
For ease of deployment, I have containerized the application using Docker:
-
Environment Setup:
- Rename
.env.example
to.env
. - Update the configuration with your specific details:
TELEGRAM_BOT_TOKEN=664XXXXXXX:AAFYXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX # IP/hostname of the Draw Things machine TXT2IMG_ENDPOINT=http://192.168.1.88:7860/sdapi/v1/txt2img
- Rename
-
Docker Deployment:
- Ensure you have both Docker and Docker Compose installed.
- Navigate to the
infra
directory - Build with
docker-compose build
- Run the command
docker-compose up
This process will start the TG Generator Bot and the Prompt Generator API, which can be used to enhance prompts or generate random adjustments. You are fine to go if you see in logs something similar to
infra-prompt-generator-api-1 | * Running on all addresses (0.0.0.0)
infra-prompt-generator-api-1 | * Running on http://127.0.0.1:5000
infra-prompt-generator-api-1 | * Running on http://172.21.0.2:5000
infra-prompt-generator-api-1 | Press CTRL+C to quit
infra-tg-generator-bot-1 | DEBUG:asyncio:Using selector: EpollSelector
infra-tg-generator-bot-1 | INFO:aiogram.dispatcher:Start polling
infra-tg-generator-bot-1 | INFO:aiogram.dispatcher:Run polling for bot @TestGenerationModelsBot id=6641122475 - 'TestGenerationModels'
Enable HTTP API Server in Draw Things. Make sure that IP dropdown is set to "0.0.0.0".
Once docker started it should be good to go. Write /start (or better /help) to your telegram bot. Things might be pretty slow so if nothing happens you might want to wait a bit and then visit logs for the explanation.
There are default values which will be passed to Draw Things coded in resource/generation_template.j2 . You might want to adjust them according to your preferences. After adjustment don't forget to rebuild docker containers (docker-compose build
).
TG Generator Bot simplifies the process of generating images via Telegram by integrating with the Draw Things API. With the addition of the Prompt Generator API, users can benefit from enhanced and randomized prompts, leading to more diverse image outputs.
It's been a hot minute since I last dabbled in software development, so things might be a tad rusty. 🛠️ But, hey, shoutout to ChatGPT for doing most of the heavy lifting here! 🚀
- Normal OOP for bot code
- Stop carrying global state with generation_results, use class
- Add proper image gallery message deletion (now it collects all messages ever sent and tries to delete them on every message send)
- Add tasks queue
- Split galleries if number of images to generate in batch > 10
- Add more than one worker
This project is open source and available under the MIT License.