Fixing stable diffusion

This commit is contained in:
Luke Robles 2022-11-24 11:30:31 -08:00
parent f1007f5d89
commit b1c30719d6
2 changed files with 23 additions and 18 deletions

View File

@ -2,6 +2,7 @@ from discord import option
from discord.ext import commands from discord.ext import commands
import core_utils import core_utils
import discord import discord
import os
class StableDiffusion(commands.Cog): class StableDiffusion(commands.Cog):
@ -10,7 +11,8 @@ class StableDiffusion(commands.Cog):
@commands.has_role("stable-diffuser") @commands.has_role("stable-diffuser")
@commands.slash_command( @commands.slash_command(
guild_ids=core_utils.my_guilds, # guild_ids=core_utils.my_guilds,
guild_ids=None,
name="sd", name="sd",
description="Pass a prompt and optional negative prompt to stable diffusion", 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 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 socket
import stable_diffusion import stable_diffusion
@ -68,7 +71,7 @@ class StableDiffusion(commands.Cog):
) )
os.remove(file_path) os.remove(file_path)
except Exception as e: except Exception as e:
await ctx.reply( await ctx.respond(
"Stable diffusion isnt running right now, sorry.\n%s" % e, "Stable diffusion isnt running right now, sorry.\n%s" % e,
) )
else: else:

View File

@ -18,15 +18,16 @@ async def generate_image(ip, port, positives, negatives, steps):
} }
json_data = { json_data = {
"fn_index": 11, "fn_index": 51,
"data": [ "data": [
positives, positives,
negatives, # Negative Prompt negatives,
"None", "None",
"None", "None",
steps, # Sampling Steps 1,
# steps,
"Euler a", "Euler a",
True, # enable face fix True,
False, False,
1, 1,
1, 1,
@ -39,33 +40,34 @@ async def generate_image(ip, port, positives, negatives, steps):
False, False,
512, 512,
512, 512,
True, # Enable highres fix True,
False, 0.7,
0.7, # Denoising Strength 0,
0,
"None", "None",
False, False,
False, False,
None, False,
"", "",
"Seed", "Seed",
"", # What seed to use "",
"Steps", "Nothing",
"", "",
True, True,
False, False,
False,
None, None,
"",
"",
], ],
} }
client = httpx.AsyncClient() client = httpx.AsyncClient()
response = await client.post(url, headers=headers, json=json_data, timeout=1200) response = await client.post(url, headers=headers, json=json_data, timeout=1200)
imageb64 = response.json()["data"][0][0].split("data:image/png;base64,")[1] file_path = response.json()["data"][0][0]["name"]
imgdata = base64.b64decode(imageb64)
imgdata = await client.get("http://%s:%s/file=%s" % (ip, port, file_path))
file, file_path = tempfile.mkstemp() file, file_path = tempfile.mkstemp()
with open(file_path, "wb") as f: with open(file_path, "wb") as f:
f.write(imgdata) f.write(imgdata.content)
soup = BeautifulSoup(response.json()["data"][2], "html.parser") soup = BeautifulSoup(response.json()["data"][2], "html.parser")
time_taken = soup.find("p", class_="time").text time_taken = soup.find("p", class_="time").text