From 148465cfded90aead3e46aa46b33252c59583806 Mon Sep 17 00:00:00 2001 From: Luke Robles <98352913+lrobles-iterable@users.noreply.github.com> Date: Thu, 6 Oct 2022 07:33:52 -0700 Subject: [PATCH] Add support for negative promts, also extend timeout to 5 minutes, also post that you're working on the image and then edit the message with the file upload --- app/cogs/actual_utils.py | 16 ++++++++++++---- app/help_methods.py | 3 ++- app/requirements.txt | 0 app/stable_diffusion.py | 8 ++++---- 4 files changed, 18 insertions(+), 9 deletions(-) mode change 100755 => 100644 app/requirements.txt diff --git a/app/cogs/actual_utils.py b/app/cogs/actual_utils.py index b93124e1..77a788b6 100644 --- a/app/cogs/actual_utils.py +++ b/app/cogs/actual_utils.py @@ -85,14 +85,22 @@ class ActualUtils(commands.Cog): ip = "192.168.1.80" try: - file_path = await stable_diffusion.generate_image( - ip=ip, port=port, prompt=prompt + original_message = await ctx.reply( + "Please be patient, I'm generating your image" ) - await ctx.reply( + negatives = "" + if ";" in prompt: + positives = prompt.split(";")[0] + negatives = prompt.split(";")[1] + file_path = await stable_diffusion.generate_image( + ip=ip, port=port, positives=positives, negatives=negatives + ) + await original_message.edit( + content="", file=discord.File( file_path, filename="unknown.png", - ) + ), ) os.remove(file_path) except Exception as e: diff --git a/app/help_methods.py b/app/help_methods.py index c9ed6d7e..41ad7d04 100644 --- a/app/help_methods.py +++ b/app/help_methods.py @@ -163,7 +163,8 @@ def get_help_message(method): "Issues a prompt against stable diffusion.\n", "For help with writing useful prompts, check out this article:\n\nhttps://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features#prompt-editing\n", "\n\nHere is a list of artists the the AI is able to understand https://rentry.org/artists_sd-v1-4", - "\n\nUsage: !sd A picture of a woman sitting by a bridge with blonde hair, wearing a black dress", + '\nAlso supports adding negatives (things you want the AI to leave out). Denote negatives by splitting the prompt with a ";"', + "\n\nUsage: !sd A picture of a woman sitting by a bridge with blonde hair, wearing a black dress; ugly, out of focus, weird hands", ], "sheeb": ["Returns a picture of a sheeb"], "source": ["Links you to the git repo with dale-bot's source code"], diff --git a/app/requirements.txt b/app/requirements.txt old mode 100755 new mode 100644 diff --git a/app/stable_diffusion.py b/app/stable_diffusion.py index 464789f3..aff1ba7f 100644 --- a/app/stable_diffusion.py +++ b/app/stable_diffusion.py @@ -5,7 +5,7 @@ import socket import tempfile -async def generate_image(ip, port, prompt): +async def generate_image(ip, port, positives, negatives): url = "http://" + ip + ":" + port + "/api/predict/" headers = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:105.0) Gecko/20100101 Firefox/105.0", @@ -18,8 +18,8 @@ async def generate_image(ip, port, prompt): json_data = { "fn_index": 11, "data": [ - prompt, - "", # Negative Prompt + positives, + negatives, # Negative Prompt "None", "None", 20, # Sampling Steps @@ -57,7 +57,7 @@ async def generate_image(ip, port, prompt): ], } client = httpx.AsyncClient() - response = await client.post(url, headers=headers, json=json_data, timeout=120) + response = await client.post(url, headers=headers, json=json_data, timeout=300) imageb64 = response.json()["data"][0][0].split("data:image/png;base64,")[1] imgdata = base64.b64decode(imageb64)