ExamplesΒΆ

  1. Query a REST API with an image
  2. Query a REST API with an image and get neighbors
  3. Query a REST API with features

Query a REST API with an image

This example shows how to query a REST API by sending an image. You can start it by running:

start_mlrestapi --name=dummyimg

And then query it with:

import requests
import ujson
from lightmlrestapi.args import image2base64
img = "path_to_image"
b64 = image2base64(img)[1]
features = ujson.dumps({'X': b64})
r = requests.post('http://127.0.0.1:8081', data=features)
print(r)
print(r.json())

It should return something like:

{'distance': [0.21]}

(original entry : dummy_applications.py:docstring of lightmlrestapi.testing.dummy_applications.dummy_application_image, line 12)

Query a REST API with an image and get neighbors

A previous example shows how to send an image, this one illustrates a result which is a classifier result neither a regressor one but neighbors. You can start it by running:

start_mlrestapi --name=dummyknn

And then query it with:

import requests
import ujson
features = ujson.dumps({'X': [0.1, 0.2]})
r = requests.post('http://127.0.0.1:8081', data=features)
print(r)
print(r.json())

It should return:

{'Y': [[[41, 4.8754486973], [13, 5.0477717856], [8, 5.0774009099], [38, 5.1312766443], [60, 5.2201532545]]]}

(original entry : dummy_applications.py:docstring of lightmlrestapi.testing.dummy_applications.dummy_application_neighbors, line 9)

Query a REST API with features

This example shows how to query a REST API by sending a vector of features. You can start it by running:

start_mlrestapi --name=dummy

And then query it with:

import requests
import ujson
features = ujson.dumps({'X': [0.1, 0.2]})
r = requests.post('http://127.0.0.1:8081', data=features)
print(r)
print(r.json())

It should return:

{'Y': [[0.4994216179, 0.4514893599, 0.0490890222]]}

(original entry : dummy_applications.py:docstring of lightmlrestapi.testing.dummy_applications.dummy_application, line 10)