From 74246d573d5d5a5c25bff42e234345948c225dc4 Mon Sep 17 00:00:00 2001 From: Luke Robles <98352913+lrobles-iterable@users.noreply.github.com> Date: Tue, 18 Oct 2022 13:18:34 -0700 Subject: [PATCH] move stable diffusion to its own cog --- app/cogs/actual_utils.py | 66 ------------------------------ app/cogs/stable-diffusion.py | 79 ++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 66 deletions(-) create mode 100644 app/cogs/stable-diffusion.py diff --git a/app/cogs/actual_utils.py b/app/cogs/actual_utils.py index 9097936f..11a9d836 100644 --- a/app/cogs/actual_utils.py +++ b/app/cogs/actual_utils.py @@ -78,72 +78,6 @@ class ActualUtils(commands.Cog): questions.open_ai(query), ) - @commands.has_role("stable-diffuser") - @commands.slash_command( - guild_ids=core_utils.my_guilds, - name="sd", - description="Pass a prompt and optional negative prompt to stable diffusion", - ) - @option( - "positive_prompt", - description="The positive prompt to pass to stable diffusion", - input_type="str", - requred=True, - ) - @option( - "negative_prompt", - description="An optional set of negatives you want to pass to stable diffusion", - required=False, - ) - async def sd( - self, ctx: commands.Context, positive_prompt: str, negative_prompt: str - ): - - if ctx.channel.name == "stable-diffusion": - import socket - import stable_diffusion - - port = "7860" - ip = "192.168.1.80" - steps = 20 - - # Send my requests to my gaming computer with the 3080 (if its up) - if ctx.author.id == core_utils.my_id: - ip = "192.168.1.188" - steps = 60 - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.settimeout(1) - try: - s.connect((ip, int(port))) - except: - ip = "192.168.1.80" - try: - await ctx.defer() - original_message = await ctx.followup.send( - "Please be patient, I'm generating your image" - ) - file_path, time_taken = await stable_diffusion.generate_image( - ip=ip, - port=port, - positives=positive_prompt, - negatives=negative_prompt or None, - steps=steps, - ) - await original_message.edit( - content=time_taken, - file=discord.File( - file_path, - filename="unknown.png", - ), - ) - os.remove(file_path) - except Exception as e: - await ctx.reply( - "Stable diffusion isnt running right now, sorry.\n%s" % e, - ) - else: - await ctx.respond("You can only do that in the stable-diffusion channel") - @commands.has_role("Track day gamers") @commands.slash_command( guild_ids=core_utils.my_guilds, diff --git a/app/cogs/stable-diffusion.py b/app/cogs/stable-diffusion.py new file mode 100644 index 00000000..ca185f16 --- /dev/null +++ b/app/cogs/stable-diffusion.py @@ -0,0 +1,79 @@ +from discord import option +from discord.ext import commands +import core_utils +import discord + + +class StableDiffusion(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.has_role("stable-diffuser") + @commands.slash_command( + guild_ids=core_utils.my_guilds, + name="sd", + description="Pass a prompt and optional negative prompt to stable diffusion", + ) + @option( + "positive_prompt", + description="The positive prompt to pass to stable diffusion", + input_type="str", + requred=True, + ) + @option( + "negative_prompt", + description="An optional set of negatives you want to pass to stable diffusion", + required=False, + ) + async def sd( + self, ctx: commands.Context, positive_prompt: str, negative_prompt: str + ): + + if ctx.channel.name == "stable-diffusion": + import socket + import stable_diffusion + + port = "7860" + ip = "192.168.1.80" + steps = 20 + + # Send my requests to my gaming computer with the 3080 (if its up) + if ctx.author.id == core_utils.my_id: + ip = "192.168.1.188" + steps = 60 + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.settimeout(1) + try: + s.connect((ip, int(port))) + except: + ip = "192.168.1.80" + try: + await ctx.defer() + original_message = await ctx.followup.send( + "Please be patient, I'm generating your image" + ) + file_path, time_taken = await stable_diffusion.generate_image( + ip=ip, + port=port, + positives=positive_prompt, + negatives=negative_prompt or None, + steps=steps, + ) + await original_message.edit( + content=time_taken, + file=discord.File( + file_path, + filename="unknown.png", + ), + ) + os.remove(file_path) + except Exception as e: + await ctx.reply( + "Stable diffusion isnt running right now, sorry.\n%s" % e, + ) + else: + await ctx.respond("You can only do that in the stable-diffusion channel") + + +def setup(bot): + bot.add_cog(StableDiffusion(bot))