phixxycom should now read logfiles and update prompt accordingly

This commit is contained in:
phixxy 2024-01-20 21:55:19 -08:00
parent f19e996560
commit 241829d88e
3 changed files with 19 additions and 8 deletions

View file

@ -2,6 +2,7 @@ import os
import io
import base64
import time
import json
import asyncssh
from PIL import Image, PngImagePlugin
from discord.ext import commands, tasks
@ -16,6 +17,7 @@ class PhixxyCom(commands.Cog):
self.working_dir = "tmp/phixxy.com/"
self.data_dir = "data/phixxy.com/"
self.folder_setup()
self.stable_diffusion_log = "data/stable_diffusion/stable_diffusion.log"
self.phixxy_loop.start()
def folder_setup(self):
@ -27,6 +29,15 @@ class PhixxyCom(commands.Cog):
except:
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):
remotepath = server_folder + server_filename
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):
if filename[-4:] == '.png':
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_insert = '''<!--REPLACE THIS COMMENT-->
<div>