diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..85c7b7e
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,8 @@
+discord
+requests
+openai
+pynacl
+python-dotenv
+pillow
+duckduckgo-search
+tts
diff --git a/website_image_gen.py b/website_image_gen.py
new file mode 100644
index 0000000..b3868ae
--- /dev/null
+++ b/website_image_gen.py
@@ -0,0 +1,220 @@
+import requests
+from PIL import Image, PngImagePlugin
+import io
+import base64
+from ftplib import FTP
+import os
+
+ftp_server = "themis.feralhosting.com"
+ftp_username = "bottlecap"
+ftp_password = "UjSKCglyT5YlHMml"
+ftp_ai_webpage = "/media/sdq1/bottlecap/www/phixxy.com/public_html/ai-webpage/"
+ftp_ai_webpage_archive = "/media/sdq1/bottlecap/www/phixxy.com/public_html/webpage-archive/"
+
+def upload_html_and_imgs():
+ with FTP(ftp_server) as ftp:
+ ftp.login(ftp_username, ftp_password)
+ ftp.cwd(ftp_ai_webpage)
+ for filename in os.listdir("webpage/"):
+ if ".png" in filename:
+ ftp.storbinary("STOR " + filename, open("webpage/" + filename, "rb"))
+ #explicitly upload html files last!
+ for filename in os.listdir("webpage/"):
+ if ".html" in filename:
+ ftp.storbinary("STOR " + filename, open("webpage/" + filename, "rb"))
+
+def upload_websites():
+ with FTP(ftp_server) as ftp:
+ ftp.login(ftp_username, ftp_password)
+ for foldername in os.listdir("websites/"):
+ ftp.cwd(ftp_ai_webpage_archive)
+ if "archived.txt" not in os.listdir("websites/" +foldername):
+ ftp.mkd(foldername)
+ ftp.cwd(ftp_ai_webpage_archive + foldername)
+ for filename in os.listdir("websites/" +foldername):
+ if ".png" in filename:
+ ftp.storbinary("STOR " + filename, open("websites/" + foldername + "/" + filename, "rb"))
+ print("Uploaded websites/" + foldername + "/" + filename)
+ #explicitly upload html files last!
+ for filename in os.listdir("websites/" +foldername):
+ if ".html" in filename:
+ ftp.storbinary("STOR " + filename, open("websites/" + foldername + "/" + filename, "rb"))
+ print("Uploaded websites/" + foldername + "/" + filename)
+ with open("websites/" + foldername + "/" + "archived.txt","w") as f:
+ f.write("True")
+ f.close()
+
+
+
+def generate_website_archive_html():
+ html1 = '''
+
+
+
+ webpage-archive
+
+
+
+
+ webpage-archive
+ This is a list of saved websites that AI generated.
+
+
+
+'''
+ with FTP(ftp_server) as ftp:
+ ftp.login(ftp_username, ftp_password)
+ ftp.cwd(ftp_ai_webpage_archive)
+ file_list = ftp.nlst()
+ dir_list = ""
+ for folder in file_list:
+ if folder != "index.html":
+ dir_list += "" + folder + "\n"
+ html = html1 + dir_list + html2
+ with open("index.html","w") as f:
+ f.write(html)
+ f.close()
+ ftp.storbinary("STOR " + "index.html", open("index.html", "rb"))
+
+
+def combine_dicts(dict1, dict2): #prioritizes dict2 args
+ combined_dict = {}
+ for key in dict1:
+ combined_dict[key] = dict1[key]
+ for key in dict2:
+ combined_dict[key] = dict2[key]
+ return combined_dict
+
+def extract_image_tags(code):
+ count = code.count("
") + index1 + 1
+ img_tag = code[index1:index2]
+ tags.append(img_tag)
+ code = code[index2:]
+ return tags
+
+def extract_image_alt_text(tags):
+ alt_texts = []
+ for tag in tags:
+ index1 = tag.find("alt") + 5
+ index2 = tag[index1:].find("\"") + index1
+ alt_text = tag[index1:index2]
+ alt_texts.append(alt_text)
+ return alt_texts
+
+
+def generate_images(image_list):
+ file_list = []
+ for image in image_list:
+ filename = image.replace(" ", "").lower() + ".png"
+ url = "http://127.0.0.1:7861"
+ payload = {"prompt": image,"steps": 25}
+ response = requests.post(url=f'{url}/sdapi/v1/txt2img', json=payload)
+ r = response.json()
+ for i in r['images']:
+ image = Image.open(io.BytesIO(base64.b64decode(i.split(",",1)[0])))
+ png_payload = {"image": "data:image/png;base64," + i}
+ response2 = requests.post(url=f'{url}/sdapi/v1/png-info', json=png_payload)
+ pnginfo = PngImagePlugin.PngInfo()
+ pnginfo.add_text("parameters", response2.json().get("info"))
+ image.save("webpage/" + filename, pnginfo=pnginfo)
+ file_list.append(filename)
+ return file_list
+
+def add_image_filenames(code, file_list):
+ for filename in file_list:
+ code = code.replace("src=\"\"", "src=\""+ filename + "\"", 1)
+ return code
+
+def delete_local_pngs():
+ for filename in os.listdir("webpage/"):
+ if ".png" in filename:
+ os.remove("webpage/" + filename)
+
+def delete_ftp_pngs():
+ with FTP(ftp_server) as ftp:
+ ftp.login(ftp_username, ftp_password)
+ ftp.cwd(ftp_ai_webpage)
+ file_list = ftp.nlst()
+ for filename in file_list:
+ if ".png" in filename:
+ print("Deleting", filename)
+ ftp.delete(filename)
+
+delete_local_pngs()
+delete_ftp_pngs()
+
+
+with open("webpage/index.html", 'r') as f:
+ code = f.read()
+ f.close()
+
+tags = extract_image_tags(code)
+alt_texts = extract_image_alt_text(tags)
+file_list = generate_images(alt_texts)
+code = add_image_filenames(code, file_list)
+with open("webpage/index.html", 'w') as f:
+ f.write(code)
+ f.close()
+upload_html_and_imgs()
+upload_websites()
+generate_website_archive_html()
+print("Success")
+