Now save generated stable diffusion images in tmp/sfw or nsfw

Now save generated memes in tmp/meme/
This commit is contained in:
phixxy 2024-01-17 19:25:00 -08:00
parent 8aeb0142a6
commit b2fb09e681
3 changed files with 22 additions and 9 deletions

View file

@ -107,7 +107,7 @@ async def meme(ctx):
#------------------------------------Saving Image Using Aiohttp---------------------------------#
filename = memepics[id-1]['name']
async with http_session.get(image_link) as response:
folder = "tmp/"
folder = "tmp/meme/"
filename = folder + topic + str(len(os.listdir(folder))) + ".jpg"
with open(filename, "wb") as file:

View file

@ -150,11 +150,15 @@ async def draw(ctx):
response2 = await resp2.json()
pnginfo = PngImagePlugin.PngInfo()
pnginfo.add_text("parameters", response2.get("info"))
my_filename = "tmp/" + str(len(os.listdir("tmp/"))) + ".png"
try:
if ctx.channel.is_nsfw():
folder = "tmp/nsfw/"
else:
folder = "tmp/sfw/"
except:
folder = "tmp/"
my_filename = folder + str(time.time_ns()) + ".png"
image.save(my_filename, pnginfo=pnginfo)
'''channel_vars = await get_channel_config(ctx.channel.id)
if channel_vars["ftp_enabled"]:
await upload_ftp_ai_images(my_filename, prompt)'''
with open(my_filename, "rb") as fh:
f = discord.File(fh, filename=my_filename)
await ctx.send(file=f)
@ -266,6 +270,10 @@ async def imagine(ctx):
for i in r['images']:
if not os.path.isdir("users/" + str(ctx.author.id)):
os.makedirs("users/" + str(ctx.author.id))
if not os.path.isdir("users/" + str(ctx.author.id) + '/nsfw/'):
os.makedirs("users/" + str(ctx.author.id) + '/nsfw/')
if not os.path.isdir("users/" + str(ctx.author.id) + '/sfw/'):
os.makedirs("users/" + str(ctx.author.id) + '/sfw/')
image = Image.open(io.BytesIO(base64.b64decode(i.split(",", 1)[0])))
png_payload = {"image": "data:image/png;base64," + i}
@ -280,8 +288,14 @@ async def imagine(ctx):
pnginfo = PngImagePlugin.PngInfo()
pnginfo.add_text("parameters", response2.get("info"))
my_filename = "users/" + str(ctx.author.id) + '/' + str(len(os.listdir("users/" + str(ctx.author.id) + '/'))) + ".png"
try:
if ctx.channel.is_nsfw():
folder = "users/" + str(ctx.author.id) + '/nsfw/'
else:
folder = "users/" + str(ctx.author.id) + '/sfw/'
except:
folder = "users/" + str(ctx.author.id) + '/'
my_filename = folder + str(time.time_ns()) + ".png"
image.save(my_filename, pnginfo=pnginfo)
#channel_vars = await get_channel_config(ctx.channel.id)