should upload all dalle images to website now

This commit is contained in:
phixxy 2024-01-27 21:01:24 -08:00
parent 254fbdd8ec
commit e2e42e8139
2 changed files with 34 additions and 26 deletions

View file

@ -32,6 +32,8 @@ class ChatGPT(commands.Cog):
os.mkdir(self.data_dir + "logs")
if not os.path.exists(self.data_dir + "dalle"):
os.mkdir(self.data_dir + "dalle")
if not os.path.exists(self.data_dir + "dalle2"):
os.mkdir(self.data_dir + "dalle2")
except:
self.bot.logger.exception("ChatGPT failed to make directories")
@ -219,7 +221,7 @@ class ChatGPT(commands.Cog):
prompt = ctx.message.content.split(" ", maxsplit=1)[1]
img_url = await self.get_dalle(prompt)
my_filename = str(time.time_ns()) + ".png"
filepath = f"{self.data_dir}dalle/{my_filename}"
filepath = f"{self.data_dir}dalle2/{my_filename}"
await self.download_image(img_url, filepath)
with open(filepath, "rb") as fh:
f = discord.File(fh, filename=filepath)

View file

@ -150,30 +150,31 @@ class PhixxyCom(commands.Cog):
await self.upload_sftp(f"{self.data_dir}ai-memes/index.html", server_folder, "index.html")
os.rename(filename, 'tmp/' + new_file_name)
async def upload_ftp_ai_images(self, folder):
for filename in os.listdir(folder):
if filename[-4:] == '.png':
filepath = folder + filename
prompt = self.find_prompt_from_filename(self.stable_diffusion_log, filename)
html_file = f"{self.data_dir}ai-images/index.html"
html_insert = '''<!--REPLACE THIS COMMENT-->
<div>
<img src="<!--filename-->" loading="lazy">
<p class="image-description"><!--description--></p>
</div>'''
server_folder = (os.getenv('ftp_public_html') + 'ai-images/')
new_filename = str(time.time_ns()) + ".png"
await self.upload_sftp(filepath, server_folder, new_filename)
self.bot.logger.debug("Uploaded", new_filename)
with open(html_file, 'r') as f:
html_data = f.read()
html_insert = html_insert.replace("<!--filename-->", new_filename)
html_insert = html_insert.replace("<!--description-->", prompt)
html_data = html_data.replace("<!--REPLACE THIS COMMENT-->", html_insert)
with open(html_file, "w") as f:
f.writelines(html_data)
await self.upload_sftp(html_file, server_folder, "index.html")
os.rename(filepath, f"tmp/{new_filename}")
async def upload_ftp_ai_images(self, ai_dict):
for folder in ai_dict:
for filename in os.listdir(folder):
if filename[-4:] == '.png':
filepath = folder + filename
prompt = self.find_prompt_from_filename(ai_dict[folder], filename)
html_file = f"{self.data_dir}ai-images/index.html"
html_insert = '''<!--REPLACE THIS COMMENT-->
<div>
<img src="<!--filename-->" loading="lazy">
<p class="image-description"><!--description--></p>
</div>'''
server_folder = (os.getenv('ftp_public_html') + 'ai-images/')
new_filename = str(time.time_ns()) + ".png"
await self.upload_sftp(filepath, server_folder, new_filename)
self.bot.logger.debug("Uploaded", new_filename)
with open(html_file, 'r') as f:
html_data = f.read()
html_insert = html_insert.replace("<!--filename-->", new_filename)
html_insert = html_insert.replace("<!--description-->", prompt)
html_data = html_data.replace("<!--REPLACE THIS COMMENT-->", html_insert)
with open(html_file, "w") as f:
f.writelines(html_data)
await self.upload_sftp(html_file, server_folder, "index.html")
os.rename(filepath, f"tmp/{new_filename}")
async def answer_question(self, topic, model="gpt-3.5-turbo"):
headers = {
@ -318,7 +319,12 @@ class PhixxyCom(commands.Cog):
@tasks.loop(seconds=60)
async def phixxy_loop(self):
current_time = time.localtime()
ai_images_dict = {
# Folder Path : Log Path
"tmp/stable_diffusion/sfw/":self.stable_diffusion_log,
"data/chatgpt/dalle/":"data/chatgpt/logs/dalle3.log",
"data/chatgpt/dalle2/":"data/chatgpt/logs/dalle2.log"
}
await self.meme_handler('tmp/meme/')
await self.upload_ftp_ai_images('tmp/stable_diffusion/sfw/')