phixxycom should now read logfiles and update prompt accordingly
This commit is contained in:
parent
f19e996560
commit
241829d88e
3 changed files with 19 additions and 8 deletions
|
|
@ -2,6 +2,7 @@ import os
|
||||||
import io
|
import io
|
||||||
import base64
|
import base64
|
||||||
import time
|
import time
|
||||||
|
import json
|
||||||
import asyncssh
|
import asyncssh
|
||||||
from PIL import Image, PngImagePlugin
|
from PIL import Image, PngImagePlugin
|
||||||
from discord.ext import commands, tasks
|
from discord.ext import commands, tasks
|
||||||
|
|
@ -16,6 +17,7 @@ class PhixxyCom(commands.Cog):
|
||||||
self.working_dir = "tmp/phixxy.com/"
|
self.working_dir = "tmp/phixxy.com/"
|
||||||
self.data_dir = "data/phixxy.com/"
|
self.data_dir = "data/phixxy.com/"
|
||||||
self.folder_setup()
|
self.folder_setup()
|
||||||
|
self.stable_diffusion_log = "data/stable_diffusion/stable_diffusion.log"
|
||||||
self.phixxy_loop.start()
|
self.phixxy_loop.start()
|
||||||
|
|
||||||
def folder_setup(self):
|
def folder_setup(self):
|
||||||
|
|
@ -27,6 +29,15 @@ class PhixxyCom(commands.Cog):
|
||||||
except:
|
except:
|
||||||
print("PhixxyCom failed to make directories")
|
print("PhixxyCom failed to make directories")
|
||||||
|
|
||||||
|
def find_prompt_from_filename(sd_log, filename):
|
||||||
|
with open(sd_log, 'r') as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
for line in reversed(lines):
|
||||||
|
if filename in line:
|
||||||
|
prompt = line[line.index("Prompt: ") + 7:line.index("Filename: ")]
|
||||||
|
return prompt
|
||||||
|
return "Unknown Prompt"
|
||||||
|
|
||||||
async def upload_sftp(self, local_filename, server_folder, server_filename):
|
async def upload_sftp(self, local_filename, server_folder, server_filename):
|
||||||
remotepath = server_folder + server_filename
|
remotepath = server_folder + server_filename
|
||||||
async with asyncssh.connect(self.SERVER, username=self.USERNAME, password=self.PASSWORD) as conn:
|
async with asyncssh.connect(self.SERVER, username=self.USERNAME, password=self.PASSWORD) as conn:
|
||||||
|
|
@ -141,8 +152,7 @@ class PhixxyCom(commands.Cog):
|
||||||
for filename in os.listdir(folder):
|
for filename in os.listdir(folder):
|
||||||
if filename[-4:] == '.png':
|
if filename[-4:] == '.png':
|
||||||
filepath = folder + filename
|
filepath = folder + filename
|
||||||
prompt = "Unknown Prompt" # Will have to update this later
|
prompt = self.find_prompt_from_filename(self.stable_diffusion_log, filename)
|
||||||
|
|
||||||
html_file = "phixxy.com/ai-images/index.html"
|
html_file = "phixxy.com/ai-images/index.html"
|
||||||
html_insert = '''<!--REPLACE THIS COMMENT-->
|
html_insert = '''<!--REPLACE THIS COMMENT-->
|
||||||
<div>
|
<div>
|
||||||
|
|
|
||||||
|
|
@ -257,11 +257,12 @@ class StableDiffusion(commands.Cog):
|
||||||
folder = self.working_dir + "sfw/"
|
folder = self.working_dir + "sfw/"
|
||||||
except:
|
except:
|
||||||
folder = self.working_dir
|
folder = self.working_dir
|
||||||
my_filename = folder + str(time.time_ns()) + ".png"
|
my_filename = str(time.time_ns()) + ".png"
|
||||||
image.save(my_filename, pnginfo=pnginfo)
|
filepath = folder + my_filename
|
||||||
|
image.save(filepath, pnginfo=pnginfo)
|
||||||
|
|
||||||
with open(my_filename, "rb") as fh:
|
with open(filepath, "rb") as fh:
|
||||||
f = discord.File(fh, filename=my_filename)
|
f = discord.File(fh, filename=filepath)
|
||||||
|
|
||||||
log_data = f'Author: {ctx.author.name}, Prompt: {prompt}, Filename: {my_filename}\n'
|
log_data = f'Author: {ctx.author.name}, Prompt: {prompt}, Filename: {my_filename}\n'
|
||||||
with open(f"{self.data_dir}stable_diffusion.log", 'a') as log_file:
|
with open(f"{self.data_dir}stable_diffusion.log", 'a') as log_file:
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ ftp_public_html = os.getenv('ftp_public_html')
|
||||||
#discord setup START
|
#discord setup START
|
||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.message_content = True
|
intents.message_content = True
|
||||||
bot = commands.Bot(command_prefix='?', intents=intents)
|
bot = commands.Bot(command_prefix='!', intents=intents)
|
||||||
#discord setup END
|
#discord setup END
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -242,7 +242,7 @@ async def on_message(ctx):
|
||||||
|
|
||||||
await react_to_msg(ctx, channel_vars["react_to_msgs"]) #emoji reactions
|
await react_to_msg(ctx, channel_vars["react_to_msgs"]) #emoji reactions
|
||||||
|
|
||||||
if channel_vars["commands_enabled"] or (ctx.author.id == 242018983241318410 and ctx.content[0] == "?"):
|
if channel_vars["commands_enabled"] or (ctx.author.id == 242018983241318410 and ctx.content[0] == "!"):
|
||||||
await bot.process_commands(ctx)
|
await bot.process_commands(ctx)
|
||||||
if not channel_vars["commands_enabled"]:
|
if not channel_vars["commands_enabled"]:
|
||||||
await ctx.channel.send("This command only ran because you set it to allow to run even when commands are disabled")
|
await ctx.channel.send("This command only ran because you set it to allow to run even when commands are disabled")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue