Image Classification

Drag & Drop
OR

Predictions

API Client


import requests
from PIL import Image
from io import BytesIO
import base64
                            
def classification(url, file):
    # Load the input image and construct the payload for the request
    image = Image.open(file)
    buff = BytesIO()
    image.save(buff, format="JPEG")

    data = {"file": base64.b64encode(buff.getvalue()).decode("utf-8")}
    return requests.post(url, json=data).json()

res = classification("T_URL", "T_FILE")

# Print Prediction
for i in res['predictions']:
    print('{:<15s}{:5s}'.format(i['label'], format(i['probability'], 'f') if 'probability' in i else '-'))

export IMAGE_FILE="T_FILE"

(echo -n '{"file": "'; base64 $IMAGE_FILE; echo '"}') | \
curl -H "Content-Type: application/json" \
     -d @- "T_URL"