From 59e74ae87ae647960959d3af6d263772db661b30 Mon Sep 17 00:00:00 2001 From: Luke Robles <98352913+lrobles-iterable@users.noreply.github.com> Date: Thu, 24 Nov 2022 11:30:31 -0800 Subject: [PATCH] Fixing stable diffusion --- app/cogs/stable-diffusion.py | 9 ++++++--- app/stable_diffusion.py | 32 +++++++++++++++++--------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/app/cogs/stable-diffusion.py b/app/cogs/stable-diffusion.py index ca185f16..389488c9 100644 --- a/app/cogs/stable-diffusion.py +++ b/app/cogs/stable-diffusion.py @@ -2,6 +2,7 @@ from discord import option from discord.ext import commands import core_utils import discord +import os class StableDiffusion(commands.Cog): @@ -10,7 +11,8 @@ class StableDiffusion(commands.Cog): @commands.has_role("stable-diffuser") @commands.slash_command( - guild_ids=core_utils.my_guilds, + # guild_ids=core_utils.my_guilds, + guild_ids=None, name="sd", description="Pass a prompt and optional negative prompt to stable diffusion", ) @@ -29,7 +31,8 @@ class StableDiffusion(commands.Cog): self, ctx: commands.Context, positive_prompt: str, negative_prompt: str ): - if ctx.channel.name == "stable-diffusion": + if True: + # if ctx.channel.name == "stable-diffusion": import socket import stable_diffusion @@ -68,7 +71,7 @@ class StableDiffusion(commands.Cog): ) os.remove(file_path) except Exception as e: - await ctx.reply( + await ctx.respond( "Stable diffusion isnt running right now, sorry.\n%s" % e, ) else: diff --git a/app/stable_diffusion.py b/app/stable_diffusion.py index b7984fe9..d99e6bf6 100644 --- a/app/stable_diffusion.py +++ b/app/stable_diffusion.py @@ -18,15 +18,16 @@ async def generate_image(ip, port, positives, negatives, steps): } json_data = { - "fn_index": 11, + "fn_index": 51, "data": [ positives, - negatives, # Negative Prompt + negatives, "None", "None", - steps, # Sampling Steps + 1, + # steps, "Euler a", - True, # enable face fix + True, False, 1, 1, @@ -39,33 +40,34 @@ async def generate_image(ip, port, positives, negatives, steps): False, 512, 512, - True, # Enable highres fix - False, - 0.7, # Denoising Strength + True, + 0.7, + 0, + 0, "None", False, False, - None, + False, "", "Seed", - "", # What seed to use - "Steps", + "", + "Nothing", "", True, False, + False, None, - "", - "", ], } client = httpx.AsyncClient() response = await client.post(url, headers=headers, json=json_data, timeout=1200) - imageb64 = response.json()["data"][0][0].split("data:image/png;base64,")[1] - imgdata = base64.b64decode(imageb64) + file_path = response.json()["data"][0][0]["name"] + + imgdata = await client.get("http://%s:%s/file=%s" % (ip, port, file_path)) file, file_path = tempfile.mkstemp() with open(file_path, "wb") as f: - f.write(imgdata) + f.write(imgdata.content) soup = BeautifulSoup(response.json()["data"][2], "html.parser") time_taken = soup.find("p", class_="time").text