Skip to content

bockholt/clarifai-python

 
 

Repository files navigation

Clarifai logo

Clarifai API Python Client

This is the official Python client for interacting with our powerful recognition API. The Clarifai API offers image and video recognition as a service. Whether you have one image or billions, you are only steps away from using artificial intelligence to recognize your visual content.

PyPi version Build Status

Installation

Install the API client:

pip install clarifai --upgrade

Note: If you cannot use pip, you can download the latest release manually or using git.

Setup

Firstly, generate your Clarifai API key on the API keys page. The client uses it for authentication.

Then, to authenticate, either:

  • initialize the ClarifaiApp with your API key
    from clarifai.rest import ClarifaiApp
    app = ClarifaiApp(api_key='YOUR_API_KEY')
  • or set the environment variable named CLARIFAI_API_KEY
  • or run the script ./scripts/clarifai config which will, after you input the API key, create a file ~/.clarifai/config with your key

Note: If you have both the environmental variable CLARIFAI_API_KEY and a file ~/.clarifai/config, the environmental variable will be used.

For AWS or Windows users, please refer to the documentation for more instructions.

Getting Started

The following example will setup the client and predict concepts on an image from a URL, using the general model

from clarifai.rest import ClarifaiApp

app = ClarifaiApp()
model = app.public_models.general_model
response = model.predict_by_url(url='https://samples.clarifai.com/metro-north.jpg')

Use model.predict_by_filename to predict concepts on a local file.

The response is a JSON structure. Here's how to print all the predicted concepts associated with the image, together with their confidence values.

concepts = response['outputs'][0]['data']['concepts']
for concept in concepts:
    print(concept['name'], concept['value'])

Documentation

See many more code examples in the developer guide and in the Python client tutorial.

Also see the Python client reference.

Packages

No packages published

Languages

  • Python 99.6%
  • Shell 0.4%