function predict_age_shortcode() {
if(isset($_FILES[‘age_image’])) {
$image = $_FILES[‘age_image’][‘tmp_name’];
$response = wp_remote_post(‘https://your-api-url.com/predict-age’, [
‘body’ => [
‘file’ => curl_file_create($image)
]
]);
$body = wp_remote_retrieve_body($response);
$data = json_decode($body, true);
if(isset($data[‘age’])) {
return ”
Predicted Age: {$data[‘age’]}
“;
} else {
return ”
Failed to predict age. Please try again.
“;
}
}
return ‘
Predict Age
‘;
}
add_shortcode(‘predict_age’, ‘predict_age_shortcode’);