From 65013afe122980d72c241d413a618aae714ec5db Mon Sep 17 00:00:00 2001 From: YellowRoseCx <80486540+YellowRoseCx@users.noreply.github.com> Date: Wed, 1 Mar 2023 01:51:17 -0600 Subject: [PATCH 01/10] Update main.py --- main.py | 60 ++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/main.py b/main.py index c6ac902..51d2045 100644 --- a/main.py +++ b/main.py @@ -5,13 +5,18 @@ import requests import io import random +from dotenv import load_dotenv from PIL import Image, PngImagePlugin import base64 -API_ID = os.environ.get("API_ID", None) -API_HASH = os.environ.get("API_HASH", None) -TOKEN = os.environ.get("TOKEN", None) -SD_URL = os.environ.get("TOKEN", None) + +load_dotenv() +API_ID = os.getenv("API_ID") +API_HASH = os.getenv("API_HASH") +TOKEN = os.getenv("TOKEN") +SD_URL = os.getenv("SD_URL") + + bot = Client( "stable", @@ -20,7 +25,7 @@ bot_token=TOKEN ) -@app.on_message(filters.command(["draw"])) +@bot.on_message(filters.command(["draw"])) def draw(client, message): msgs = message.text.split(' ', 1) if len(msgs) == 1: @@ -30,7 +35,38 @@ def draw(client, message): K = message.reply_text("Please Wait 10-15 Second") - payload = {"prompt": msg} + payload = { + "prompt": msg, + "steps": 35 + "enable _hr': false, + "denoising_strength": 0, + "firstphase_width": 0, + "firstphase_height": 0, + "styles": [ + "string" + ], + "seed": -1, + "subseed": -1, + "subseed_strength": 0, + "seed_resize_from_h: -1, + "seed_resize_from_w": -1, + "batch_size": 1 + "n_iter": 1, + "steps": 50, + "cfg scale": 7 + "width": 512, + "height": 512, + "restore_faces": false, + "tiling": false, + "negative prompt": "string", + "eta": O, + "s_churn": 0, + "s_tmax": 0, + "s_tmin": 0, + "s_noise": 1, + "sampler_ index": "Euler" + + } r = requests.post(url=f'{SD_URL}/sdapi/v1/txt2img', json=payload).json() @@ -52,7 +88,7 @@ def draw(client, message): image = Image.open(io.BytesIO(base64.b64decode(i.split(",", 1)[0]))) png_payload = {"image": "data:image/png;base64," + i} - response2 = requests.post(url=f'{url}/sdapi/v1/png-info', + response2 = requests.post(url=f'{SD_URL}/sdapi/v1/png-info', json=png_payload) pnginfo = PngImagePlugin.PngInfo() @@ -62,27 +98,25 @@ def draw(client, message): message.reply_photo( photo=f"{word}.png", caption= - f"Prompt - **{msg}**\n **[{message.from_user.first_name}-Kun](tg://user?id={message.from_user.id})**\n Join @WaifuAiSupport" + f"Prompt - **{msg}**\n **[{message.from_user.first_name}-Kun](tg://user?id={message.from_user.id})**\n" ) os.remove(f"{word}.png") K.delete() -@app.on_message(filters.command(["start"], prefixes=["/", "!"])) +@bot.on_message(filters.command(["start"], prefixes=["/", "!"])) async def start(client, message): Photo = "https://media.discordapp.net/attachments/1028156834944655380/1062018608022171788/3aac7aaf-0065-40aa-9e4d-430c717b3d87.jpg" buttons = [[ InlineKeyboardButton("Add to your group", url="http://t.me/botname?startgroup=true"), - InlineKeyboardButton("Channel", url="https://t.me/otakatsu"), - InlineKeyboardButton("Support", url="https://t.me/otakatsu_chat") ]] await message.reply_photo( photo=Photo, caption= - f"Hello! I'm botname Ai and I can make an anime-styled picture!\n\n/generate - Reply to Image\n/draw text to anime image\n\nPowered by @Otakatsu", + f"Hello! I'm botname Ai and I can make an anime-styled picture!\n\n/draw text to anime image", reply_markup=InlineKeyboardMarkup(buttons)) -app.run() +bot.run() From 98260fca34009188ad5e73e96b9f5d0451101fd6 Mon Sep 17 00:00:00 2001 From: YellowRoseCx <80486540+YellowRoseCx@users.noreply.github.com> Date: Wed, 1 Mar 2023 02:53:26 -0600 Subject: [PATCH 02/10] Update main.py From 23f2a80c90127544ba8d90a591ebe69f692167ed Mon Sep 17 00:00:00 2001 From: YellowRoseCx <80486540+YellowRoseCx@users.noreply.github.com> Date: Wed, 1 Mar 2023 02:57:13 -0600 Subject: [PATCH 03/10] Update main.py --- main.py | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/main.py b/main.py index 51d2045..2931b50 100644 --- a/main.py +++ b/main.py @@ -37,36 +37,33 @@ def draw(client, message): payload = { "prompt": msg, - "steps": 35 - "enable _hr': false, - "denoising_strength": 0, - "firstphase_width": 0, - "firstphase_height": 0, - "styles": [ - "string" - ], + "steps": 50, + "batch_size": 1, + "n_iter": 1, + "cfg scale": 7, + "width": 360, + "height": 640, + # "enable_hr': false, + # "denoising_strength": 0, + # "firstphase_width": 0, + # "firstphase_height": 0, + # "styles": [ + # "string" + # ], "seed": -1, "subseed": -1, "subseed_strength": 0, - "seed_resize_from_h: -1, + "seed_resize_from_h": -1, "seed_resize_from_w": -1, - "batch_size": 1 - "n_iter": 1, - "steps": 50, - "cfg scale": 7 - "width": 512, - "height": 512, - "restore_faces": false, - "tiling": false, - "negative prompt": "string", - "eta": O, + "restore_faces": True, + "tiling": False, + "negative prompt": "Out of frame, out of focus, morphed", "s_churn": 0, "s_tmax": 0, "s_tmin": 0, "s_noise": 1, - "sampler_ index": "Euler" - - } + "sampler_index": "DPM++ 2M Karras" +} r = requests.post(url=f'{SD_URL}/sdapi/v1/txt2img', json=payload).json() @@ -98,7 +95,7 @@ def draw(client, message): message.reply_photo( photo=f"{word}.png", caption= - f"Prompt - **{msg}**\n **[{message.from_user.first_name}-Kun](tg://user?id={message.from_user.id})**\n" + f"Prompt - **{msg}**\n **[{message.from_user.first_name}-Kun](tg://user?id={message.from_user.id})**\n Join @WaifuAiSupport" ) os.remove(f"{word}.png") K.delete() @@ -111,12 +108,13 @@ async def start(client, message): buttons = [[ InlineKeyboardButton("Add to your group", url="http://t.me/botname?startgroup=true"), + InlineKeyboardButton("Channel", url="https://t.me/otakatsu"), + InlineKeyboardButton("Support", url="https://t.me/otakatsu_chat") ]] await message.reply_photo( photo=Photo, caption= - f"Hello! I'm botname Ai and I can make an anime-styled picture!\n\n/draw text to anime image", + f"Hello! I'm botname Ai and I can make an anime-styled picture!\n\n/generate - Reply to Image\n/draw text to anime image\n\nPowered by @Otakatsu", reply_markup=InlineKeyboardMarkup(buttons)) - bot.run() From 4b340325652c132252debebcb9e6bcb32d4c78c6 Mon Sep 17 00:00:00 2001 From: Sourcery AI <> Date: Wed, 1 Mar 2023 08:57:53 +0000 Subject: [PATCH 04/10] 'Refactored by Sourcery' --- main.py | 60 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/main.py b/main.py index 2931b50..4ebe81d 100644 --- a/main.py +++ b/main.py @@ -35,35 +35,35 @@ def draw(client, message): K = message.reply_text("Please Wait 10-15 Second") - payload = { - "prompt": msg, - "steps": 50, - "batch_size": 1, - "n_iter": 1, - "cfg scale": 7, - "width": 360, - "height": 640, - # "enable_hr': false, - # "denoising_strength": 0, - # "firstphase_width": 0, - # "firstphase_height": 0, - # "styles": [ - # "string" - # ], - "seed": -1, - "subseed": -1, - "subseed_strength": 0, - "seed_resize_from_h": -1, - "seed_resize_from_w": -1, - "restore_faces": True, - "tiling": False, - "negative prompt": "Out of frame, out of focus, morphed", - "s_churn": 0, - "s_tmax": 0, - "s_tmin": 0, - "s_noise": 1, - "sampler_index": "DPM++ 2M Karras" -} + payload = { + "prompt": msg, + "steps": 50, + "batch_size": 1, + "n_iter": 1, + "cfg scale": 7, + "width": 360, + "height": 640, + # "enable_hr': false, + # "denoising_strength": 0, + # "firstphase_width": 0, + # "firstphase_height": 0, + # "styles": [ + # "string" + # ], + "seed": -1, + "subseed": -1, + "subseed_strength": 0, + "seed_resize_from_h": -1, + "seed_resize_from_w": -1, + "restore_faces": True, + "tiling": False, + "negative prompt": "Out of frame, out of focus, morphed", + "s_churn": 0, + "s_tmax": 0, + "s_tmin": 0, + "s_noise": 1, + "sampler_index": "DPM++ 2M Karras" + } r = requests.post(url=f'{SD_URL}/sdapi/v1/txt2img', json=payload).json() @@ -84,7 +84,7 @@ def draw(client, message): for i in r['images']: image = Image.open(io.BytesIO(base64.b64decode(i.split(",", 1)[0]))) - png_payload = {"image": "data:image/png;base64," + i} + png_payload = {"image": f"data:image/png;base64,{i}"} response2 = requests.post(url=f'{SD_URL}/sdapi/v1/png-info', json=png_payload) From b3ab3a2ae974161d707307219c5532187ee82b13 Mon Sep 17 00:00:00 2001 From: YellowRoseCx <80486540+YellowRoseCx@users.noreply.github.com> Date: Wed, 1 Mar 2023 05:04:48 -0600 Subject: [PATCH 05/10] Update README.md --- README.md | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/README.md b/README.md index f5d64fa..8b13789 100644 --- a/README.md +++ b/README.md @@ -1,32 +1 @@ -# AI Powered Art in a Telegram Bot! - -## Setup - -Install requirements - -`pip install -r requirements.txt` - -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 - -Create a file called `.env` in the same folder as `main.py`. Inside the `.env` file, -create a line `TOKEN = xxxx`, where xxxx is your telegram bot token. -create a line `API_ID = xxxx`, where xxxx is your telegram id api id. -create a line `API_HASH = xxxx`, where xxxx is your telegram id api hash. -create a line `SD_URL = xxxx`, where xxxx is your sd api url. - -Now, you can run the bot - -`python main.py` - -### Any questions or need help? Come hop on by to our Telegram Group! - -[Otakatsu Chat](https://t.me/otakatsu_chat) - From 34eecac473c3d0d8fdf309af9dc261262145004b Mon Sep 17 00:00:00 2001 From: YellowRoseCx <80486540+YellowRoseCx@users.noreply.github.com> Date: Wed, 1 Mar 2023 23:43:41 -0600 Subject: [PATCH 06/10] Create sample.env --- sample.env | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 sample.env diff --git a/sample.env b/sample.env new file mode 100644 index 0000000..f986f05 --- /dev/null +++ b/sample.env @@ -0,0 +1,4 @@ +TOKEN = +API_ID = +API_HASH = +SD_URL = From 9ef7ae9b1734edc4124d160f05641aa25dddb467 Mon Sep 17 00:00:00 2001 From: YellowRoseCx <80486540+YellowRoseCx@users.noreply.github.com> Date: Wed, 1 Mar 2023 23:46:01 -0600 Subject: [PATCH 07/10] Update README.md --- README.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/README.md b/README.md index 8b13789..5160595 100644 --- a/README.md +++ b/README.md @@ -1 +1,31 @@ +# AI Powered Art in a Telegram Bot! + +## Setup + +Install requirements + +`pip install -r requirements.txt` + +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 + +Create a file called `.env` in the same folder as `main.py`. Inside the `.env` file, +create a line `TOKEN = xxxx`, where xxxx is your telegram bot token. +create a line `API_ID = xxxx`, where xxxx is your telegram id api id. +create a line `API_HASH = xxxx`, where xxxx is your telegram id api hash. +create a line `SD_URL = xxxx`, where xxxx is your sd api url. + +Now, you can run the bot + +`python main.py` + +### Any questions or need help? Come hop on by to our Telegram Group! + +[Otakatsu Chat](https://t.me/otakatsu_chat) From 279c8ecc20e4f24652987e13a9547d064287d3f1 Mon Sep 17 00:00:00 2001 From: YellowRoseCx <80486540+YellowRoseCx@users.noreply.github.com> Date: Wed, 1 Mar 2023 23:46:35 -0600 Subject: [PATCH 08/10] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 5160595..f5d64fa 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,4 @@ Now, you can run the bot [Otakatsu Chat](https://t.me/otakatsu_chat) + From c7204622b35c4d2fb59a0fb1a66396108d362ff7 Mon Sep 17 00:00:00 2001 From: YellowRoseCx <80486540+YellowRoseCx@users.noreply.github.com> Date: Wed, 1 Mar 2023 23:47:08 -0600 Subject: [PATCH 09/10] Delete README.md --- README.md | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index f5d64fa..0000000 --- a/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# AI Powered Art in a Telegram Bot! - -## Setup - -Install requirements - -`pip install -r requirements.txt` - -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 - -Create a file called `.env` in the same folder as `main.py`. Inside the `.env` file, -create a line `TOKEN = xxxx`, where xxxx is your telegram bot token. -create a line `API_ID = xxxx`, where xxxx is your telegram id api id. -create a line `API_HASH = xxxx`, where xxxx is your telegram id api hash. -create a line `SD_URL = xxxx`, where xxxx is your sd api url. - -Now, you can run the bot - -`python main.py` - -### Any questions or need help? Come hop on by to our Telegram Group! - -[Otakatsu Chat](https://t.me/otakatsu_chat) - - From c8a6b34be5f67420c3e646cc4c08a0e5e55e76bd Mon Sep 17 00:00:00 2001 From: YellowRoseCx <80486540+YellowRoseCx@users.noreply.github.com> Date: Wed, 1 Mar 2023 23:47:15 -0600 Subject: [PATCH 10/10] Add files via upload --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..f5d64fa --- /dev/null +++ b/README.md @@ -0,0 +1,32 @@ +# AI Powered Art in a Telegram Bot! + +## Setup + +Install requirements + +`pip install -r requirements.txt` + +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 + +Create a file called `.env` in the same folder as `main.py`. Inside the `.env` file, +create a line `TOKEN = xxxx`, where xxxx is your telegram bot token. +create a line `API_ID = xxxx`, where xxxx is your telegram id api id. +create a line `API_HASH = xxxx`, where xxxx is your telegram id api hash. +create a line `SD_URL = xxxx`, where xxxx is your sd api url. + +Now, you can run the bot + +`python main.py` + +### Any questions or need help? Come hop on by to our Telegram Group! + +[Otakatsu Chat](https://t.me/otakatsu_chat) + +