stable-diffusion-telegram-bot/README.md

105 lines
3.9 KiB
Markdown
Raw Permalink Normal View History

2023-01-12 06:30:46 +02:00
# AI Powered Art in a Telegram Bot!
2024-05-18 13:18:58 +03:00
this is a txt2img/img2img bot to converse with SDweb bot [API](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/API) running on tami telegram channel
2023-03-18 15:09:38 +02:00
2024-04-09 22:40:23 +03:00
## How to
2024-05-18 13:18:58 +03:00
### txt2img
2023-03-18 15:09:38 +02:00
`/draw <text>` - send prompt text to the bot and it will draw an image
2023-04-28 10:32:19 +03:00
you can add `negative_prompt` using `ng: <text>`
2023-05-06 21:21:49 +03:00
you can add `denoised intermediate steps` using `steps: <text>`
2023-04-28 10:32:19 +03:00
2023-05-06 21:21:49 +03:00
basicly anything the `/controlnet/txt2img` API payload supports
like,
2024-04-09 22:40:23 +03:00
2023-05-06 21:21:49 +03:00
```json
{
"prompt": "",
"negative_prompt": "",
"denoising_strength": 0.5,
"seed": -1,
"n_iter": 1,
"steps": 20,
"cfg_scale": 7
}
```
2024-04-09 22:40:23 +03:00
2023-03-18 15:09:38 +02:00
examples:
`/draw a city street`
and without people
2023-04-27 13:59:16 +03:00
`/draw a city street ng: people`
2023-04-28 10:03:47 +03:00
with more steps
`/draw a city street ng: people steps: 50`
2023-03-18 15:09:38 +02:00
to change the model use:
`/getmodels` - to get a list of models and then click to set it.
2023-04-28 10:32:19 +03:00
- note1: Anything after ng will be considered as nergative prompt. a.k.a things you do not want to see in your diffusion!
- note2: on [negative_prompt](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Negative-prompt) (aka ng):
2024-05-18 13:18:58 +03:00
thia is a bit of a black art. i took the recommended defaults for the `Deliberate` model from this fun [alt-model spreadsheet](https://docs.google.com/spreadsheets/d/1Q0bYKRfVOTUHQbUsIISCztpdZXzfo9kOoAy17Qhz3hI/edit#gid=797387129).
2023-04-28 10:32:19 +03:00
- note3: on `steps` - step of 1 will generate only the first "step" of bot hallucinations. the default is 40. higher will take longer and will give "better" image. range is hardcoded 1-70.
see ![video](https://user-images.githubusercontent.com/57876960/212490617-f0444799-50e5-485e-bc5d-9c24a9146d38.mp4)
2024-04-09 22:40:23 +03:00
2024-05-18 13:18:58 +03:00
### img2img
`/img <prompt> ds:<0.0-1.0>` - reply to an image with a prompt text and it will draw an image
you can add `denoising_strength` using `ds:<float>`
Set that low (like 0.2) if you just want to slightly change things. defaults to 0.4
basicly anything the `/controlnet/img2img` API payload supports
2024-05-18 20:41:30 +03:00
### general
`X/Y/Z script` [link](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features#xyz-plot), one powerfull thing
for prompt we use the Serach Replace option (a.k.a `prompt s/r`) [exaplined](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features#prompt-sr)
2023-01-12 06:30:46 +02:00
## Setup
2024-04-09 22:40:23 +03:00
Install requirements using venv
```bash
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
```
Install requirements using conda
2023-01-12 06:30:46 +02:00
2023-03-18 15:09:38 +02:00
```bash
conda create -n sdw python=3.8
conda activate sdw
pip install -r requirements.txt
```
2024-04-09 22:40:23 +03:00
## Original README
2023-01-12 06:30:46 +02:00
My Bot uses [Automatic1111's WebUI](https://github.com/AUTOMATIC1111/stable-diffusion-webui) as the backend.
Follow the directions on their repo for setup instructions.
Once you have WebUI set up, run `webui.sh` with the `--api` argument. You can also add other
arguments such as `--xformers` to use xformers memory efficient attention.
You can use the web ui interface that Automatic1111 provides to select the model and VAE to use.
Their repo has documentation on how to do so. I also recommend doing a test generation
2024-04-09 22:40:23 +03:00
Copy a file called `.env_template` into `.env_template` in the same folder as `main.py`.
In the `.env` file fill out the following environment variables:
`TOKEN = xxxx`, where xxxx is your telegram bot token.
`API_ID = xxxx`, where xxxx is your telegram id api id.
`API_HASH = xxxx`, where xxxx is your telegram id api hash.
`SD_URL = xxxx`, where xxxx is your sd api url.
2023-01-12 06:30:46 +02:00
2024-04-09 22:40:23 +03:00
To get the API_ID and API_HASH, you need to create a new application on the Telegram's developer website. Here are the steps:
1. Open browser and visit https://my.telegram.org and log in with your Telegram account.
2. Click on "API development tools".
3. Fill out the form to create a new application. You can enter any valid details you want.
4. After you've created the application, you'll be given the API_ID and API_HASH.
5. Once you have these, you can add them to your .env file:
2023-01-12 06:30:46 +02:00
2024-04-09 22:40:23 +03:00
Now, you can run the bot
2023-01-12 06:41:51 +02:00
2024-04-09 22:40:23 +03:00
`python main.py`
2023-01-12 06:30:46 +02:00