Try it on API Model training example¶
In this tutorial, we'll guide you through using the Try it on API to train models and generate 100 or 200 AI headshots.
The steps for getting this going are:
Test your API Key
Purchase a model.
1.5 Fetch the model
Choose or upload your own styles
Upload close-ups of the subject
Train the model
Use any AI edits
At the end of the tutorial, we'll show you how to use the image edits as well.
import io
import os
import json
import requests
from PIL import Image
from dotenv import load_dotenv
load_dotenv()
True
0. Testing your API Key¶
headers = {
"x-tryiton-key": os.environ['TRYITON_API_KEY']
}
url = "https://studio.tryitonai.com/api/key/user-data"
response = requests.get(url, headers=headers)
user = json.loads(response.text)
user
{'userId': '...', 'lastName': None, 'name': 'Team Try it on', 'email': 'team@tryitonai.com', 'credits': 100, 'createdAt': '2024-06-18T23:46:15.520822+00:00', 'stripeCustomerId': None, 'stripeSubStatus': None, 'stripeSubPriceId': None}
If you recieved an empty list, then you're well on your way.
The next step is to purchase a model! You can purchase it on our website: studio.tryitonai.com, or by e-mailing us if you'd like to get bulk pricing: nathan@tryitonai.com.
NOTE: Proceed once you've purchased the model!¶
url = "https://studio.tryitonai.com/api/key/get-models"
response = requests.get(url, headers=headers)
model = json.loads(response.text)
model
[{'id': 180635, 'createdAt': '2024-06-18T23:54:30.238398+00:00', 'gender': None, 'productName': 'AI Headshots', 'isTrained': False, 'emailSent': False, 'email': 'team@tryitonai.com', 'isUsed': False, 'modelName': 'API Test', 'deletedAt': None, 'customizations': None, 'projectId': None, 'metadata': None}]
model_id = model[0]['id']
2. Check out the Try it on available styles¶
response = requests.get(url, headers=headers)
import requests
url = "https://studio.tryitonai.com/api/key/get-styles"
payload = {
"gender": "man" # or "woman"
}
json_headers = headers.copy()
json_headers["Content-Type"] = "application/json"
response = requests.get(url, payload, headers=headers)
styles = json.loads(response.text)
styles.keys()
dict_keys(['semi casual studio', 'real estate', 'business studio', 'hollywood', 'sporty', 'dating', 'casual studio', 'timeless', 'casual outdoors', 'business outdoors', 'streetstyle', 'neon lights', 'color pop', 'business office'])
styles['business studio'][0]
{'url': 'https://pics.tryitonai.com/styles%2Fapproved%2Fman%2Fbusiness%20studio%2F413e2db2-f00f-4874-93b8-d7b8b7d673d8%2Fa2c1157d-f435-4613-948a-534c0500e7d8%2Fthumbnail_((q_*%20man))%20business%20studio%20portrait%2C%20studio%20lighting%2C%20tailroed%20black%20suit%20and%20white%20shirt%2C%20dark%20backdrop%2C%20film%20grain%2C%20warm%20tones.webp?Expires=1719098226&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=ixfLD5aOJpFFfcEgJK-i-bxRDndvuZlzUUtscBD6X7q4K1E2sycIBlDF~5w-0EXpDr27n5Dl~k0uBTc8jMTYh~dQkqU4ymAr~aa0NcN~zGOIcEbwdNpYeqTWi2O-HVfOLAStgkV3D77x4IxkxqNfN2hl~tXUHGuE~XuHIbOdfj~gp~dF-jG5ABptZbzoENNvCeKnmyFI5h4BuskCUUzur3Y-lEdyb7SKriZnVvLdMfNL1OXhZYTZnvSPYFzkr7ouz~mFRGEVOUdYbTcaBvoeGLVN1Zyd4LcF6inm4KuKdOfF~KdjnOp-7baBtBkfDWnXaUu~ozbgQdOsBmd5pnP9kA__', 'uuid': '413e2db2-f00f-4874-93b8-d7b8b7d673d8', 'name': '((q_* man)) business studio portrait, studio lighting, tailroed black suit and white shirt, dark backdrop, film grain, warm tones', 'key': 'styles/approved/man/business studio/413e2db2-f00f-4874-93b8-d7b8b7d673d8/a2c1157d-f435-4613-948a-534c0500e7d8/((q_* man)) business studio portrait, studio lighting, tailroed black suit and white shirt, dark backdrop, film grain, warm tones.png', 'category': 'business studio', 'lastModified': '2024-04-12T08:15:21+00:00', 'userId': 'a2c1157d-f435-4613-948a-534c0500e7d8', 'timesUsed': 2649, 'timesUsed30d': 1068, 'type': 'Published'}
def load_image_from_url(url):
response = requests.get(url)
response.raise_for_status()
image = Image.open(io.BytesIO(response.content))
return image
# Do note that this url corresponds to the thumbnail, so the size is smaller than the 640x640 you'll get when using the image as reference.
real_estate_style = styles['business studio'][0]['url']
load_image_from_url(real_estate_style)
hood_style = styles['sporty'][2]['url']
load_image_from_url(hood_style)
casual_style = styles['ca'][0]['url']
load_image_from_url(real_estate_style)
You can also upload your own image if you'd like to use it to generate headshots!¶
Note that you should make sure to crop the image to be a square! If it is not, we will automatically crop it and may cut off the person in the image. Also, please resize the image to 640x640 in case there are size constraints.
# Thank you, Unsplash! Find this image here: https://unsplash.com/photos/man-standing-beside-wall-pAtA8xe_iVM
headshot = Image.open("male-headshot.png").resize((640, 640))
headshot
headshot.size
(640, 640)
import io
import base64
def image_to_base64(image, format='PNG'):
buffered = io.BytesIO()
image.save(buffered, format=format)
img_str = base64.b64encode(buffered.getvalue()).decode()
return img_str
def base64_to_image(data, format="PNG"):
image_bytes = base64.b64decode(data)
return Image.open(io.BytesIO(image_bytes))
def upload(url, payload):
try:
response = requests.put(url, json=payload, headers=json_headers)
return json.loads(response.text)['imageUrl']
except Exception as e:
print(e)
print(response.text)
if "Body exceeded 1mb limit" == response.text:
print("Reducing the size and trying again....")
return upload_image(
base64_to_image(payload['base64']).resize((500, 500)).resize((640, 640))
)
raise
def upload_style(pil_image, model_id):
url = "https://studio.tryitonai.com/api/key/upload-style"
payload = {
"modelId" : model_id,
"gender": "man",
"imageBase64": image_to_base64(pil_image)
}
return upload(url, payload)
def upload_image(pil_image):
url = "https://studio.tryitonai.com/api/key/upload-image"
payload = {
"base64": image_to_base64(pil_image),
"type": "png"
}
return upload(url, payload)
response = upload_style(pil_image=headshot, model_id=model_id)
response.text
'{"imageKeyResponse":"team@tryitonai.com/180635/model_styles/a ((q_* man)) in a dark suit jacket and white collared shirt, professional headshot style, bright clean background, soft lighting, sharp focus, corporate setting.png"}'
headshot_key = json.loads(response.text)['imageKeyResponse']
3. Get the subject's close-ups in order and upload them to Try it on's servers.¶
If your images are hosted elsewhere, you can also use them here. Make sure there are at least 10 images!
import matplotlib.pyplot as plt
def plot_side_by_side(imgs_and_titles, title=None, max_per_row=3, notebook_width=18):
# Calculate number of rows and the figure size
num_imgs = len(imgs_and_titles)
max_per_row = min(num_imgs, max_per_row)
num_rows = (num_imgs + max_per_row - 1) // max_per_row
# Assuming images are square, adjust height relative to width
img_aspect_ratio = 1 # Set to the aspect ratio of your images (height / width)
row_height = notebook_width / max_per_row * img_aspect_ratio
fig_size = (notebook_width, row_height * num_rows)
fig, axs = plt.subplots(num_rows, max_per_row, figsize=fig_size, squeeze=False)
if title:
plt.suptitle(title)
# Set padding between images in one row
pad = 5 # 5 pixels
fig.subplots_adjust(wspace=pad / fig.dpi)
# Iterate through images and plot them
for i, img_assets in enumerate(imgs_and_titles):
row = i // max_per_row
col = i % max_per_row
if type(img_assets) == list or type(img_assets) == tuple:
img = img_assets[0]
img_title = img_assets[1][:25]
axs[row, col].set_title(img_title)
else:
img = img_assets
axs[row, col].imshow(img, cmap='gray')
axs[row, col].axis('off') # Hide axes
# Hide any unused axes
for i in range(num_imgs, num_rows * max_per_row):
row = i // max_per_row
col = i % max_per_row
axs[row, col].axis('off')
# Show the plot
plt.show()
root = "mypics/"
image_names = os.listdir(root)
image_paths = [os.path.join(root, file) for file in image_names if not file.startswith(".")]
images = [Image.open(image) for image in image_paths]
images_and_titles = list(zip(images[:6], [i.size for i in images[:6]]))
plot_side_by_side([(x, f"Size: {y}") for x, y in images_and_titles])
Make sure they're a square and sized appropriately so you don't get the exceed limit error!¶
def resize_image(image, dims=(640, 640)):
"""Image must be a PIL image object.
dims = (width, height)
"""
# Create an empty frame the size of "dims"
frame = Image.new('RGB', dims, 'white')
aspect_ratio = image.width / image.height
if image.width > image.height:
new_width = dims[0]
new_height = int(dims[1] / aspect_ratio)
else:
new_width = int(dims[0] * aspect_ratio)
new_height = dims[1]
image = image.resize((new_width, new_height), Image.LANCZOS)
x = int((dims[0] - new_width) / 2)
y = int((dims[1] - new_height) / 2)
frame.paste(image, (x, y))
return frame
images = [resize_image(image) for image in images]
images_and_titles = list(zip(images[:6], [i.size for i in images[:6]]))
plot_side_by_side([(x, f"Size: {y}") for x, y in images_and_titles])
Gotta make sure the uploaded images are 640x640 max, then it'll work just fine 👍!¶
You can also simply not crop them or resize them and we will do it automatically for you, but we may crop the images in the incorrect places.
image_urls = []
for i, img in enumerate(images):
print(f"Processing image {i}")
url = upload_image(img)
image_urls.append(url)
Processing image 0 Processing image 1 Processing image 2 Processing image 3 Processing image 4 Processing image 5 Processing image 6 Processing image 7 Processing image 8 Expecting value: line 1 column 1 (char 0) Body exceeded 1mb limit Reducing the size and trying again.... Processing image 9
print("Number of uploaded images: ", len(image_urls))
Number of uploaded images: 10
image_urls
['https://pics.tryitonai.com/tmp%2F4db26c63-d606-43a3-a494-c314b3a3d27b.png?Expires=1719615841&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=CGVJlm9Tz8ZgcN5PwkSyDM1NtJ56nBBEiBqzHz4inPoQD1~7IKICRlzPFLddkHgmrTxr8XctbVJc2LXqEb1AaBcGwT9JFuJ9XYMWuPXr7POc2gO4Mrz-BJN8-p4VRvih32mS0e5wQY1bdHVKpBEOK9-J0~uSNzqLTAf7sQLQZMtOaTiVpt57NHagPjlggqs85pMyS8-y9Nb-TaBWXu-HIwWSibr8b5tzHSsPqoE4hhx3Rlh-uuCCT2xvWvu3Cnc0emvGm9NDOHNEBhghbqexdcjxsuFgz0tp0mP6bNZokfW-LyXK~KY64DTc7tsLscEwfuPZm-0WxRuICb-b3X2ZjQ__', 'https://pics.tryitonai.com/tmp%2F1fbf132a-9f01-4b9a-b081-f5981bfb0fd3.png?Expires=1719615841&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=gLQhBRLawVXnnBBckO~Pn641hrTbqSVbC7VOhXjuv7PkSAPScI-KdeFLlEwsTmIVJpZR9uCkoEFmK9naHyANpJyCdbPFtk9MBhzHjEeDpfmrv05t-15WLJlbgnozr4r0OrfvmK7icPs85ly50RRgFxw3t1ysCZVXV5t4WWgMLP3RiKQeuL4qa0i59im7YU9rQ~lHf214R0TvasNZpW384AvRHOiU7Duju891TvdL5l6YqzI1GCFd02o4eKahyOhsLkRh7pz0iO3tXSExujAGeAuwmL2XXB9Pte~XgVYZqEVTogdGbYBUQK7T5cwk2gTbBRIhWrC~D4AX~DKrw7wSlQ__', 'https://pics.tryitonai.com/tmp%2F43c83d40-d38e-4802-a2f9-b69afe648dc8.png?Expires=1719615842&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=tGGlGi40o3Pu-Lk04ETtA9gprCkKdtyvMttT4f1J62ABjECQcJ17dgkxRkjtOy9DARr-Y-sUVF9F-Hd5So25cKE2V73JN0528RLRNg4uX4JZAqEWz6ZPV5kcpWPXCwtiXqFt~SMapiToc5fcLET9WX0DWfKEvY-4qNcZiuEbASfjEqESLe19rgax66sfMGODPw5~793h6hFlyID1w2Fr6QG6RsUzr-gKKnzOjSFJdYz1rExA5e5b9yyFl8QekKQGz27SKamvUvz3RjtsIYlGP2BcQePLUmG8sM5cwUM66cWcznJMvKkODQ2lxjn9EKewAn8RGmHOR4JaL9MPpu9pow__', 'https://pics.tryitonai.com/tmp%2F08822a56-a36e-4324-a741-a299e8689082.png?Expires=1719615843&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=rEZFRe79VVfeyTbSIkRcVLxhrg3Qnp9gtSRWDd2a5zJAo2PT6Ki3ck8mhwVPn~KKlskYlZhA~ZD7~e7gwsKwy9wj~DffGw59dh3tSmPP2I5YUMrewmtVvCyTo8lPvYS-q6syYdmgnRQe0eFtP1UGDOm8X0VCU3Mnq5nL717CmMbBlVVBPDqet6M3ET6v7e4xUjqWSgvyP65ucH~tu24UPNY3B7cVY00XKXGuLYzdJXA27xNZsZTVQz-3x8swIGUFLALkF329ilYJtETeVQe2cx3tOhm4u~Fe5~gDKEDbKeOBrmVFwrqWFXO0cU4uGIjzq~ohPA6evCpg0XUiN4Sjgw__', 'https://pics.tryitonai.com/tmp%2F8251e3d6-9078-4031-9730-50cb91044054.png?Expires=1719615844&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=CknM-jJIwwG5Po4Kmn29p5MpJtyidaCJFxCxAisBerNFdb6SugM65wrZG7rYPAq0-T5F6sfantRpdXvrse~dRVEQAUnQW3tcRXDeyRbDLR320Ux7diD4~VjBRUKQTOIK2g7EqBg5F-jiVArLd7j-OSoUip0kMX9pPcRAZapcqLxiZjO7nbAREMdE7q5EK~YlKpij~6Ucpdn-uCCXiStcGyITwdwEtH6NvUE8YnLuN7SIwJBGYXmT5AlvuVAWcLd~w9YZegveOyYkwCVOvVXtnuvCOQZ18R1-wex2TNeJmS0bLthovUIiORbrg2wa7G0WjsHidJoXZRoCHThmHCGRJQ__', 'https://pics.tryitonai.com/tmp%2Fc1bbfe35-e5ca-4db8-a45e-ab50bcf2cad4.png?Expires=1719615845&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=hWU89PQMQQeR02egAJf58oqHgiTD6ne1tv-OiyQHysYZrusU5EUaFz8GuaWkzGPKNYcUfhUQwK5yrJeon7rB2Y402hHj7aZCQ2ZWnvi0xEKSLhtDN4R4GAxyuggbCoNvRLic8hfS3l5z0IiUQSqm0JHWLq2uRIoTokHwpsQq~dkL2nh36KEwVAaIhUZphb66Cbbr6h1P5iSt8udQ0LLloV-fAgmdKYQQzGNtDXlnN3qoATzVarQJhX7-R-P3Rn5UaBCyyjEzW11mcon7OL32aoQWovl9V1EaAT~nLU1yfJWn9yJheAWijX6~o6FwtSiEbwPs6l0VRjewvRwabbjP3Q__', 'https://pics.tryitonai.com/tmp%2Fb1f0b37c-8ad1-4943-9260-9b5a7a5c4927.png?Expires=1719615846&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=KUlCtihUIw9b0RPhlxvNvC42mYo6JSQjDR2UmF6SdUoWdzJYTELswiWz3tY8Hw0TQJRQtE1RoBVDXDhcSvHTHQ9BgXF33Lf~BBJtto5zN3LCd7Y076qUsth1nSid6sormw708I4UMV0qoJKFFXlkzbrthO30vlHqifOFWLeQDpZKCOWkTyLHFvXVascHEWBRNdi7NsitJ5E5CdFqrYMpD~aed8jLQ1Stf2a5bK-~y43ffXYf~2uCf6f~-93bkZ2mJo~EPWFjj3g-ODlYIQ9Y5EoKWOPHUailQ5il~TdU0FOy6qlpCZUn0PAiUj37u~Brm2r6kKVOEmMHtHRiWL9W-w__', 'https://pics.tryitonai.com/tmp%2F735b58a1-0e74-4576-b47b-56df5df8c36e.png?Expires=1719615846&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=agUY0Zh7s~BqZ~PyRWP2XP54XbyXX2cHjfKTe4UNqLm-RmjWzZEFNjVd0tjTQzIU0WKOcGnpc0G3Jvpv712eDzGJ3kHkIkLpmANF-QjlvAJWH34gOhiNEMbx71UaNiomaJam6frRG2DqxueY7ZcxWupC5RlB0Z3H5jzqGr2-ua4iTVJhN6TQrySlRUaO9rMhsndyeGsh0SYZRXL~7Kkn-ifWbJMeJh1apRjYHtu~yeCCislG1AVkqDLF4Fy20vidfvvujwCq3FJcSnKjyo9Rx3ejOWkESzLXT4o96mm3rovtn7-wOYBCulxBiv8gNNZQ6tin66SADG9vpRl8GIC2KA__', 'https://pics.tryitonai.com/tmp%2F169364e9-b245-42c2-a0fb-795b02051ca4.png?Expires=1719615848&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=BkOgUDFYhHAOTXsnxqvjGfUM9PSrHqCjQMUSHB4oej7Yw9xLUqX8pFLruk8bYfzAuFol~Xeh8A9CCdTbPIOkPG~-4wV3ir0fENbasiQ3pMfPY4RiQSsSK8V-tdpzlxQvobgsLkB1HYljP9Bym~ll59j-rX2ZAg12xXzFeEZl7Y6K-eQghT9Oz9AS7vDudtFjXWPQml7q26V~sOEcPAtHt4fJoOJ5yHGBnACRT7GyCuyWAbazFhTZA4~6Zsti189y69l0bnYuu7Jga~FdB86ZGiUAqJqkzUQYBd4dJDjseRUgyqNcio5gexOWeZ8aX3jMKAXbsjAL0c26K05HnUZ4Ag__', 'https://pics.tryitonai.com/tmp%2Fa27340c1-e50c-4fad-bf6b-e75eb8a8fbaa.png?Expires=1719615849&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=tk2h-Sl3kvBJnXyeTqulNOQi7u01hFHIA5-fGc~5lyEoxrXIARo9th2HEXdqEByH3AEwy81jjCjma0hIKpRGgHUnC76glYmDes~Ish--OyNtNn2d9R-R1VxNtmg65j7oZK0J4qNXLV9tt6XhJTOv2YDiL-ZAvJLdHrawMQweOussLXZO~LKKUCYNeK0436aoT5Ua-EaPYaUBqbbykajJmIOCZ4ObSm0BZ8IRbQQjwGuSVL-d5uG0-ZdLuS4-yxQP-bpjHnDgbBqCDvshgS9ywwFVBFxcIezBPGXldIGDA8vQgm90SDrT3-uFIFw2lLKWS2C5~CGIXLK1ApwLekPH4g__']
4. Define attributes to train the model¶
style_image_keys = [styles['business studio'][0]['key'], headshot_key, styles['sporty'][0]['key']]
len(style_image_keys)
3
style_image_keys
['styles/approved/man/business studio/413e2db2-f00f-4874-93b8-d7b8b7d673d8/a2c1157d-f435-4613-948a-534c0500e7d8/((q_* man)) business studio portrait, studio lighting, tailroed black suit and white shirt, dark backdrop, film grain, warm tones.png', 'team@mystellaai.com/180635/model_styles/a ((q_* man)) in a dark suit jacket and white collared shirt, professional headshot style, bright clean background, soft lighting, sharp focus, corporate setting.png', 'styles/approved/man/sporty/b58b5bd2dad61943941b3972ae274be1/1d7e4672-c668-4e74-bd7a-8e9c8d38cc8e/a professional portrait of ((q_* man)), sporty, wearing a sporty gray top, concrete background, soft lighting, soft smile, bokeh.png']
payload = {
"modelId": model_id,
"gender": "man",
"styleImageKeys": style_image_keys,
"imageUrls": image_urls,
"customizations": "brown hair", # This one is an optional argument
}
payload
{'modelId': 180635, 'gender': 'man', 'styleImageKeys': ['styles/approved/man/business studio/413e2db2-f00f-4874-93b8-d7b8b7d673d8/a2c1157d-f435-4613-948a-534c0500e7d8/((q_* man)) business studio portrait, studio lighting, tailroed black suit and white shirt, dark backdrop, film grain, warm tones.png', 'team@mystellaai.com/180635/model_styles/a ((q_* man)) in a dark suit jacket and white collared shirt, professional headshot style, bright clean background, soft lighting, sharp focus, corporate setting.png', 'styles/approved/man/sporty/b58b5bd2dad61943941b3972ae274be1/1d7e4672-c668-4e74-bd7a-8e9c8d38cc8e/a professional portrait of ((q_* man)), sporty, wearing a sporty gray top, concrete background, soft lighting, soft smile, bokeh.png'], 'imageUrls': ['https://pics.tryitonai.com/tmp%2F4db26c63-d606-43a3-a494-c314b3a3d27b.png?Expires=1719615841&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=CGVJlm9Tz8ZgcN5PwkSyDM1NtJ56nBBEiBqzHz4inPoQD1~7IKICRlzPFLddkHgmrTxr8XctbVJc2LXqEb1AaBcGwT9JFuJ9XYMWuPXr7POc2gO4Mrz-BJN8-p4VRvih32mS0e5wQY1bdHVKpBEOK9-J0~uSNzqLTAf7sQLQZMtOaTiVpt57NHagPjlggqs85pMyS8-y9Nb-TaBWXu-HIwWSibr8b5tzHSsPqoE4hhx3Rlh-uuCCT2xvWvu3Cnc0emvGm9NDOHNEBhghbqexdcjxsuFgz0tp0mP6bNZokfW-LyXK~KY64DTc7tsLscEwfuPZm-0WxRuICb-b3X2ZjQ__', 'https://pics.tryitonai.com/tmp%2F1fbf132a-9f01-4b9a-b081-f5981bfb0fd3.png?Expires=1719615841&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=gLQhBRLawVXnnBBckO~Pn641hrTbqSVbC7VOhXjuv7PkSAPScI-KdeFLlEwsTmIVJpZR9uCkoEFmK9naHyANpJyCdbPFtk9MBhzHjEeDpfmrv05t-15WLJlbgnozr4r0OrfvmK7icPs85ly50RRgFxw3t1ysCZVXV5t4WWgMLP3RiKQeuL4qa0i59im7YU9rQ~lHf214R0TvasNZpW384AvRHOiU7Duju891TvdL5l6YqzI1GCFd02o4eKahyOhsLkRh7pz0iO3tXSExujAGeAuwmL2XXB9Pte~XgVYZqEVTogdGbYBUQK7T5cwk2gTbBRIhWrC~D4AX~DKrw7wSlQ__', 'https://pics.tryitonai.com/tmp%2F43c83d40-d38e-4802-a2f9-b69afe648dc8.png?Expires=1719615842&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=tGGlGi40o3Pu-Lk04ETtA9gprCkKdtyvMttT4f1J62ABjECQcJ17dgkxRkjtOy9DARr-Y-sUVF9F-Hd5So25cKE2V73JN0528RLRNg4uX4JZAqEWz6ZPV5kcpWPXCwtiXqFt~SMapiToc5fcLET9WX0DWfKEvY-4qNcZiuEbASfjEqESLe19rgax66sfMGODPw5~793h6hFlyID1w2Fr6QG6RsUzr-gKKnzOjSFJdYz1rExA5e5b9yyFl8QekKQGz27SKamvUvz3RjtsIYlGP2BcQePLUmG8sM5cwUM66cWcznJMvKkODQ2lxjn9EKewAn8RGmHOR4JaL9MPpu9pow__', 'https://pics.tryitonai.com/tmp%2F08822a56-a36e-4324-a741-a299e8689082.png?Expires=1719615843&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=rEZFRe79VVfeyTbSIkRcVLxhrg3Qnp9gtSRWDd2a5zJAo2PT6Ki3ck8mhwVPn~KKlskYlZhA~ZD7~e7gwsKwy9wj~DffGw59dh3tSmPP2I5YUMrewmtVvCyTo8lPvYS-q6syYdmgnRQe0eFtP1UGDOm8X0VCU3Mnq5nL717CmMbBlVVBPDqet6M3ET6v7e4xUjqWSgvyP65ucH~tu24UPNY3B7cVY00XKXGuLYzdJXA27xNZsZTVQz-3x8swIGUFLALkF329ilYJtETeVQe2cx3tOhm4u~Fe5~gDKEDbKeOBrmVFwrqWFXO0cU4uGIjzq~ohPA6evCpg0XUiN4Sjgw__', 'https://pics.tryitonai.com/tmp%2F8251e3d6-9078-4031-9730-50cb91044054.png?Expires=1719615844&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=CknM-jJIwwG5Po4Kmn29p5MpJtyidaCJFxCxAisBerNFdb6SugM65wrZG7rYPAq0-T5F6sfantRpdXvrse~dRVEQAUnQW3tcRXDeyRbDLR320Ux7diD4~VjBRUKQTOIK2g7EqBg5F-jiVArLd7j-OSoUip0kMX9pPcRAZapcqLxiZjO7nbAREMdE7q5EK~YlKpij~6Ucpdn-uCCXiStcGyITwdwEtH6NvUE8YnLuN7SIwJBGYXmT5AlvuVAWcLd~w9YZegveOyYkwCVOvVXtnuvCOQZ18R1-wex2TNeJmS0bLthovUIiORbrg2wa7G0WjsHidJoXZRoCHThmHCGRJQ__', 'https://pics.tryitonai.com/tmp%2Fc1bbfe35-e5ca-4db8-a45e-ab50bcf2cad4.png?Expires=1719615845&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=hWU89PQMQQeR02egAJf58oqHgiTD6ne1tv-OiyQHysYZrusU5EUaFz8GuaWkzGPKNYcUfhUQwK5yrJeon7rB2Y402hHj7aZCQ2ZWnvi0xEKSLhtDN4R4GAxyuggbCoNvRLic8hfS3l5z0IiUQSqm0JHWLq2uRIoTokHwpsQq~dkL2nh36KEwVAaIhUZphb66Cbbr6h1P5iSt8udQ0LLloV-fAgmdKYQQzGNtDXlnN3qoATzVarQJhX7-R-P3Rn5UaBCyyjEzW11mcon7OL32aoQWovl9V1EaAT~nLU1yfJWn9yJheAWijX6~o6FwtSiEbwPs6l0VRjewvRwabbjP3Q__', 'https://pics.tryitonai.com/tmp%2Fb1f0b37c-8ad1-4943-9260-9b5a7a5c4927.png?Expires=1719615846&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=KUlCtihUIw9b0RPhlxvNvC42mYo6JSQjDR2UmF6SdUoWdzJYTELswiWz3tY8Hw0TQJRQtE1RoBVDXDhcSvHTHQ9BgXF33Lf~BBJtto5zN3LCd7Y076qUsth1nSid6sormw708I4UMV0qoJKFFXlkzbrthO30vlHqifOFWLeQDpZKCOWkTyLHFvXVascHEWBRNdi7NsitJ5E5CdFqrYMpD~aed8jLQ1Stf2a5bK-~y43ffXYf~2uCf6f~-93bkZ2mJo~EPWFjj3g-ODlYIQ9Y5EoKWOPHUailQ5il~TdU0FOy6qlpCZUn0PAiUj37u~Brm2r6kKVOEmMHtHRiWL9W-w__', 'https://pics.tryitonai.com/tmp%2F735b58a1-0e74-4576-b47b-56df5df8c36e.png?Expires=1719615846&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=agUY0Zh7s~BqZ~PyRWP2XP54XbyXX2cHjfKTe4UNqLm-RmjWzZEFNjVd0tjTQzIU0WKOcGnpc0G3Jvpv712eDzGJ3kHkIkLpmANF-QjlvAJWH34gOhiNEMbx71UaNiomaJam6frRG2DqxueY7ZcxWupC5RlB0Z3H5jzqGr2-ua4iTVJhN6TQrySlRUaO9rMhsndyeGsh0SYZRXL~7Kkn-ifWbJMeJh1apRjYHtu~yeCCislG1AVkqDLF4Fy20vidfvvujwCq3FJcSnKjyo9Rx3ejOWkESzLXT4o96mm3rovtn7-wOYBCulxBiv8gNNZQ6tin66SADG9vpRl8GIC2KA__', 'https://pics.tryitonai.com/tmp%2F169364e9-b245-42c2-a0fb-795b02051ca4.png?Expires=1719615848&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=BkOgUDFYhHAOTXsnxqvjGfUM9PSrHqCjQMUSHB4oej7Yw9xLUqX8pFLruk8bYfzAuFol~Xeh8A9CCdTbPIOkPG~-4wV3ir0fENbasiQ3pMfPY4RiQSsSK8V-tdpzlxQvobgsLkB1HYljP9Bym~ll59j-rX2ZAg12xXzFeEZl7Y6K-eQghT9Oz9AS7vDudtFjXWPQml7q26V~sOEcPAtHt4fJoOJ5yHGBnACRT7GyCuyWAbazFhTZA4~6Zsti189y69l0bnYuu7Jga~FdB86ZGiUAqJqkzUQYBd4dJDjseRUgyqNcio5gexOWeZ8aX3jMKAXbsjAL0c26K05HnUZ4Ag__', 'https://pics.tryitonai.com/tmp%2Fa27340c1-e50c-4fad-bf6b-e75eb8a8fbaa.png?Expires=1719615849&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=tk2h-Sl3kvBJnXyeTqulNOQi7u01hFHIA5-fGc~5lyEoxrXIARo9th2HEXdqEByH3AEwy81jjCjma0hIKpRGgHUnC76glYmDes~Ish--OyNtNn2d9R-R1VxNtmg65j7oZK0J4qNXLV9tt6XhJTOv2YDiL-ZAvJLdHrawMQweOussLXZO~LKKUCYNeK0436aoT5Ua-EaPYaUBqbbykajJmIOCZ4ObSm0BZ8IRbQQjwGuSVL-d5uG0-ZdLuS4-yxQP-bpjHnDgbBqCDvshgS9ywwFVBFxcIezBPGXldIGDA8vQgm90SDrT3-uFIFw2lLKWS2C5~CGIXLK1ApwLekPH4g__'], 'customizations': 'brown hair'}
url = "https://studio.tryitonai.com/api/key/train-model"
response = requests.post(url, json=payload, headers=json_headers)
print(response)
<Response [200]>
url = "https://studio.tryitonai.com/api/key/get-models"
response = requests.get(url, headers=headers)
model = json.loads(response.text)
print("Training started: ", model[0]['isUsed'])
print("Training finished: ", model[0]['isTrained'])
Training started: True Training finished: False
NOTE:¶
We currently only send you an e-mail when the training is done. Takes about 30 minutes.
If you'd like to send us a webhook for us to hit when the training is done, please let us know :)
## 30 minutes later...
print("Training finished: ", model[0]['isTrained'])
Training finished: True
Results¶
url = "https://studio.tryitonai.com/api/key/get-headshot-results"
payload = {
"modelId": model_id
}
response = requests.get(url, payload, headers=headers)
images = json.loads(response.text)
len(images)
100
images.keys()
dict_keys(['imageUrls'])
load_image_from_url(images['imageUrls'][2])
image = load_image_from_url(images['imageUrls'][2])
AI Image Edits¶
Enhance¶
url = "https://studio.tryitonai.com/api/key/enhance"
payload = {
"modelId": model_id,
"imageUrl": images['imageUrls'][2]
}
response = requests.post(url, payload, headers=headers)
images = json.loads(response.text)
images
{'imageUrl': 'https://pics.tryitonai.com/team%tryitonai.com%2F156501%2Foutput%2F7f83d65e-28d4-476d-af6f-379ec06dfb67png?Expires=1719444974&Key-Pair-Id=K1CVI41MJ72Z7W&Signature=Tjv21UU9KCtWD7rvFjQlrOy0weLdF1Pf8GiM1dFedS4LbUkqBAtpoTX6rMjQJqhNa5GJeBDIwvCI3DUHBwfzNRS6iElEJo4t6~bOk6Si2F14XYNBdNk7Rwqu1HgOqcSLJEkVCNHB5B1MTUtm0gJKgFxhl0~BTGKbv3SpTp4FS3tzdmIvuD4QgOnV4A8arJI7kHNbDHcFXbMvqCt86We0iWT3dc~90LTYK7dL41qF~ntEU14cmTYECozGsrEov4XdhfwsYMxEWNqJe4PknhqgsxMMjLgrD-QVg1cLUVfD3ei90xwAmDn6zyluN~PzqZ6ZQn8JnHwdp9zKCArH-cCtiA__', 'imageKey': 'team@tryitonai.com/156501/output/7f83d65e-28d4-476d-af6f-379ec06dfb67png', 'status': 'SUCCESS'}
load_image_from_url(images['imageUrl'])