Óscar A. Montiel — How to easily create a GPT of yourself

I had a really good idea… What if I feed ɬɧɛ ɱąƈɧıŋɛ with all my public writings? I thought about it for HRs and potential exploitersemployers to chat with the mechanical version of myself, and it kind of works, creating an interface for you to ask about what’s on my resume at the moment and some secrets hidden inside my occult, public diary since 2014.

Steps:

This was incredibly easy to achieve:

  1. First I needed to collect all my writings. Thankfully I’ve archived most of my thoughts in virtual text since I was a baby.

  2. I couldn’t just copy/paste everything, so I just scrapped the text using Python with the Selenium library, and then convert it to a PDF so ᏖᏂᏋ ᎷᏗፈᏂᎥᏁᏋ could read and learn from it.

Here is the code (I needed to use pdfkit to convert it into a PDF and some encoding stuff to make sure the font is correctly embedded in the PDF as UTF-8. Also, you’ll probably need the wkhtmltopdf binary):

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import pdfkit # To convert the HTML to PDF
import base64 # Encoding the font to base64 so it writes correctly in the PDF with all the UTF-8 characters (Óscar)
import time

def get_driver():
    """Initialize and return a Selenium WebDriver with configured options."""
    options = Options()
    options.add_argument("--disable-infobars")
    options.add_argument("--headless")
    options.add_argument("--disable-gpu")
    options.add_argument("--start-maximized")
    options.add_argument("--disable-dev-shm-usage")
    options.add_argument("--no-sandbox")
    options.add_experimental_option("excludeSwitches", ["enable-automation"])
    options.add_argument("--disable-blink-features=AutomationControlled")
    options.add_argument("--disable-images")

    driver = webdriver.Chrome(options=options)
    driver.get("{YOUR_BLOG_URL_HERE}") # Because you have one, right?
    return driver

def get_blog_content(driver):
    """Extract and return blog content from the current page."""
    time.sleep(5)
    paragraphs = driver.find_elements(By.TAG_NAME, "p")
    return "\n\n".join([p.text for p in paragraphs])

def encode_font_to_base64(font_path):
    """Encode the specified font file to base64."""
    with open(font_path, "rb") as font_file:
        return base64.b64encode(font_file.read()).decode('utf-8')

def main():
    path_wkhtmltopdf = "./wkhtmltopdf/bin/wkhtmltopdf.exe"
    config = pdfkit.configuration(wkhtmltopdf=path_wkhtmltopdf)

    driver = get_driver()
    all_blog_content = ""

    while True:
        all_blog_content += get_blog_content(driver)
        print(f"Scraping content from: {driver.current_url}")

        try:
            # My blog has a button to load more content, so I need to click it to load the next page:
            next_page = driver.find_element(By.CLASS_NAME, "blog-pager-older-link")
            next_page.click()
            time.sleep(5)
        except Exception as e:
            print(f"No more pages to load or error occurred: {e}")
            break

    driver.quit()

    # This applies the Cardo font in the generated PDF.
    font_path = './Cardo-Regular.ttf'
    encoded_font = encode_font_to_base64(font_path)
    font_face = f"""
    @font-face {{
        font-family: 'Cardo';
        src: url(data:font/truetype;charset=utf-8;base64,{encoded_font}) format('truetype');
    }}
    """
    style = f"<style>{font_face}</style>"
    html_content = f"<html><head>{style}</head><body style='font-family:Cardo;'>{all_blog_content}</body></html>"

    print("Generating PDF...")
    pdfkit.from_string(html_content, "blog_content.pdf", configuration=config, options={'encoding': "UTF-8"})

if __name__ == "__main__":
    main()

Execute this in a terminal with python main.py and voilá! (also, if you ever wondered why many websites ask you if “you’re a human” is because scripts like this 😉):

Generated PDF (of course much bigger than this, but you get the idea—probably its knowledge cap is like 2 weeks ago or something):
Óscar A. Montiel — How to easily create a GPT of yourself

At the end I simply uploaded the PDF into a custom GPT and told ɘᴎiʜɔɒM ɘʜT to act as me. Sadly, OpenAI doesn’t likes fun and it was kind of difficult for it to interpret as myself, so it ended being a simple chatbot with my writings as a base. Still fun, tho!

Result:

Try it yourself: Mechanical Óscar A. Montiel.


For any question please reach me out here: https://linktr.ee/animanoir 🙂.