Skip to main content

Turing visual search and visually similar recommendations API library for Python

Project description

Turing Python Library

Turing visual search and visually similar recommendations API library for python. The REST API documentation can be found here: https://api.turingiq.com/doc/

Setup

This package is available through pip and can be install using following command.

pip3 install turing-api

Initialize

import the visualAPI class as bellow.

from turing_api.lib.visualAPI import VisualAPI

You can initialize the VisualAPI class with below parameters.

api_key = 'your_api_key' # You can get API key when you login at: https://www.turingiq.com/login
mode = 'live'            # the mode can be either `live` or `sandbox`. Default mode is `live`.
visual_api = VisualAPI(api_key, mode)

Autocrop

Detect objects in image and get bounding boxes around objects detected.

# image_url is required field.
image_url = "https://example.com/image_url.jpg"

# now let's call the API.
response = visual_api.autocrop(image_url)

The bounding boxes returned by this method can be given to visual search to improve visual search quality.

Insert

You need to insert images to our index to query on them. The insert function can be written as below.

# id is required field.
id = 'some_product_id'

# image_url is required field.
image_url = "https://example.com/image_url.jpg"

# filters argument is optional. You can specify upto 3 filters as per example given below.
# Filters can be useful when querying images from our index. You can apply any filter
# as per your requirement.
filters = {"filter1" : "onefilter", "filter2" : "twofilter", "filter3" : "threefilter"}

# metadata is optional. You can pass additional information about your image which will be
# returned when you query image from our index.
metadata = {"title" : "Image Title"}

# now let's call the API.
response = visual_api.insert(id, image_url, filters, metadata)

Update

If you need to update information to indexed image, you can use update function. If you call update function for id which is not already indexed, it will insert the image to index.

# id is required field. Provide id for which you need to update the information.
id = 'some_product_id'

# image_url is optional field. You can pass `null` if you would like to keep URL unchanged.
image_url = "https://example.com/image_url.jpg"

# filters argument is optional. You can specify upto 3 filters as per example given below.
# Filters can be useful when querying images from our index. You can apply any filter
# as per your requirement. The filters you provide here will be overwritten.
filters = {"filter1" : "onefilter", "filter2" : "twofilter", "filter3" : "threefilter"}

# metadata is optional. You can pass additional information about your image which will be
# returned when you query image from our index. Existing metadata values will be overwritten
# based on keys supplied to this array.
metadata = {"title" : "Image Title"}

# now let's call the API.
response = visual_api.update(id, image_url, filters, metadata)

Delete

You can delete image from index with this method.

# id is required field.
id = 'some_product_id'

# now let's call the API.
response = visual_api.delete(id)

Visual Search

Visual search can be used to search indexed images based on query image.

# image_url is required field. The API will perform visual search on the image and return
image_url = "https://example.com/image_url.jpg"

# crop_box is optional field. You can supply empty array if you don't want to specify crop box.
# The format of crop box is [xmin, ymin, xmax, ymax]
crop_box = [188, 256, 656, 928]

# filters argument is optional. You can specify upto 3 filters.
# For example, if you specify filter1 = "nike", it will only return images which are indexed with
# "nike" as filter1.
filters = {"filter1" : "nike"}

# now let's call the API.
response = visual_api.search(image_url, crop_box, filters)

Visual Recommendations

Visual recommendations give visually similar image recommendations which can be used to display recommendation widget on e-commerce sites which greatly improved CTR and conversion rates.

# image_url is required field. The API will perform visual search on the image and return
id = "some_product_id"

# filters argument is optional. You can specify upto 3 filters.
# For example, if you specify filter1 = "nike", it will only return images which are indexed with
# "nike" as filter1.
filters = {"filter1" : "nike"}

# now let's call the API.
response = visual_api.recommendations(id, filters)

Run Tests

API_KEY=api_key python3 test/visualAPITest.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

turing_api-1.0.1.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

turing_api-1.0.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file turing_api-1.0.1.tar.gz.

File metadata

  • Download URL: turing_api-1.0.1.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

File hashes

Hashes for turing_api-1.0.1.tar.gz
Algorithm Hash digest
SHA256 7c9471c5768693f4dd5a5862aeb3f2816e3a33b1591c77142a10099e8e740379
MD5 3f4f845b1964fab7b850b7daabf1632a
BLAKE2b-256 73faffde1a8023680c4a08f149604d54591536d69ac56c235f797d0255104108

See more details on using hashes here.

File details

Details for the file turing_api-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: turing_api-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.1.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5

File hashes

Hashes for turing_api-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cec4096422bb4774d5170fc357459ff025eabef30145ebc26a3ae6da4c9fb7a9
MD5 3548e1f0f9f32de9616f63cae1173612
BLAKE2b-256 0c6aa7986045025f4b4030814657d749ba2441804f67f22dcbbb4f640a24330a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page