Automating AI-Generated Professional Headshots

Hi All,

Its week 5 of my mastering Make journey! After completing Make Advanced from the Make Academy I wanted to build a more complex automation so I created an automation for training an AI model :robot: on a persons likeness, and then generating headshots of that person which could be used on LinkedIn etc.

Here is an overview of the 3 scenarios involved (There is a :wrapped_gift: at the end)

Scenario 1: Gather training data and train AI model

I used a Google Form to collect the training data from the user. It has 3 steps, gathering things like, name, email, age, eye color etc. The last step collects the images of the user. The images are important as they determine the quality of the headshots that will be generated later.

Scenario 1 takes the images and zips them up. I used the HTTP modules to call Replicate’s APIs.

Replicate is a platform that allows developers, researchers, and businesses to run, fine-tune, and deploy AI models using a cloud-based API.

The first API call creates a new training model, and the next API call passes the zipped images to that model for training. Training takes approximately 20 minutes for 10 images. The calls to Replicate’s APIs are asynchronous. To trigger my second scenario when the model training is completed I used webhooks. You can specify your webhook url in the request object as follows

By specifying in the webhook_events_filter “completed”, I am telling Replicate to only call my webhook when its status is completed. This is important for scenario 2 as it means I can go ahead and run predictions against the newly trained model.

Scenario 2: Generating AI Headshot Photos

Before running predictions against the new AI model I first constructed a prompt template, including some of the user information from the Google Form response like eye color, ethnicity etc.

prompt_template

I then created variables to store 4 different outfit descriptions and 4 different background descriptions.

From these I was able to create 16 unique prompts which I put into a prompts array. For each prompt I made an API call to the new AI model on Replicate to generate Headshots based on the prompts. Again like in scenario 1, I used webhooks to get notified when the images were generated.

Scenario 3: Get AI Headshot Photos

The webhook gets triggered when Replicate is finished generating the images. The images come as urls in an array. I iterate over each one, use a HTTP Get request to fetch the image data and then upload the images to Google Drive.

Notes

You can run HTTP requests directly from Visual Studio Code using the extension REST Client.

This was useful while working on scenario 2 and 3 as it allowed me to trigger the webhooks during development without having to make calls to Replicate APIs which cost money each time you call them :money_with_wings:!

I see lots of improvements I could make to my scenarios like error handling, automate zipping the headshots and emailing them to the user etc.

It would be great to get some feedback from you all, good or bad! :thinking: Can you see any improvements I could make etc.

:wrapped_gift: Also if someone wants to submit my Google Form and see what kind of images come out the other side, then reply here with “ME PLEASE”. I will pick someone and send you a link to the form. :slightly_smiling_face: Also, before replying please checkout the file upload instructions above and make sure you have such images as this will determine the quality of the Headshots generated.

Have a great rest of the weekend!
Brian

4 Likes