Our Age Prediction API allows you to quickly and accurately predict the age of a person based on their image. Simply send a POST request with the image and receive a response with the predicted age. Optional the extracted face can be returned as a base64 encoded image.
import requests
url = "https://age-detection2.p.rapidapi.com/age"
image = "https://upload.wikimedia.org/wikipedia/commons/8/8c/Cristiano_Ronaldo_2018.jpg"
#alternatively upload base64 encoded image
#import base64
#with open("m.jpeg", "rb") as f:
# image = f.read()
# image = base64.b64encode(image).decode('utf-8')
payload = {"image": image, "return_face" : False}
headers = {
"X-RapidAPI-Key": "<REPLACE_WITH_YOUR_API_KEY>",
"X-RapidAPI-Host": "age-detection2.p.rapidapi.com",
"Content-Type": "application/json"
}
response = requests.request("POST", url, json=payload, headers=headers)
print(response.status_code)
print(response.json())
{
'age' : 26.03,
'region' : [120,140,180,180] //x,y, width, height
}