dragon-bot/app/cogs/stable_diffusion.py

102 lines
4.8 KiB
Python
Executable File

from discord import option
from discord.ext import commands
import core_utils
import discord
import os
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,
)
@option(
"model_name",
description="The SD model you want to use for this render",
default="dreamshaper 6.31 baked VAE",
choices=["dreamshaper 6.31 baked VAE", "absolutereality_v181", "dreamshaper_8"],
required=True,
)
async def sd(
self,
ctx: commands.Context,
positive_prompt: str,
negative_prompt: str,
model_name: str,
):
allowed_channels = ["stable-diffusion", "bot-testing"]
if ctx.channel.name in allowed_channels:
import socket
import stable_diffusion
port = "7860"
ip = "192.168.1.5"
steps = 120
enable_upscale = "false"
if "<lora:" not in positive_prompt:
positive_prompt = (
positive_prompt
+ " <lora:bimbostyleThreeU:0.3> <lora:gigatitums:0.3> <lora:add_detail:1>"
)
# 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.19"
enable_upscale = "true"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(1)
try:
s.connect((ip, int(port)))
except:
ip = "192.168.1.5"
try:
await ctx.defer()
original_message = await ctx.followup.send(
"Please be patient, I'm generating your image"
)
file_path = await stable_diffusion.generate_image(
ip=ip,
port=port,
positives=positive_prompt,
negatives=negative_prompt
or "(bad-image-v2-39000:0.8), (bad_prompt_version2:0.8), (bad-hands-5:1.1), (EasyNegative:0.8), (NG_DeepNegative_V1_4T:0.8), (bad-artist-anime:0.7),(deformed iris, deformed pupils, bad eyes, semi-realistic:1.4), (worst quality, low quality:1.3), (blurry:1.2), (greyscale, monochrome:1.1), (poorly drawn face), cloned face, cross eyed , extra fingers, mutated hands, (fused fingers), (too many fingers), (missing arms), (missing legs), (extra arms), (extra legs), (poorly drawn hands), (bad anatomy), (bad proportions), cropped, lowres, text, jpeg artifacts, signature, watermark, username, artist name, trademark, watermark, title, multiple view, Reference sheet, long neck, Out of Frame, B&W, logo, Watermark, bad artist, blur, blurry, text, b&w, 3d, bad art, poorly drawn, disfigured, deformed, extra limbs, ugly hands, extra fingers, canvas frame, cartoon, 3d, disfigured, bad art, deformed, extra limbs, weird colors, duplicate, morbid, mutilated, out of frame, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, ugly, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, out of frame, ugly, extra limbs, bad anatomy, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, mutated hands, fused fingers, too many fingers, long neck, Photoshop, video game, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, mutation, mutated, extra limbs, extra legs, extra arms, disfigured, deformed, cross-eye, body out of frame, bad art, bad anatomy, 3d render",
steps=steps,
enable_upscale=enable_upscale,
model_name=model_name,
)
await original_message.edit(
content="",
file=discord.File(
file_path,
filename="unknown.png",
),
)
os.remove(file_path)
except Exception as e:
await original_message.edit(
"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))