MyNixOS website logo
Description

API Client for the Clarifai API.

Provides functionality for interacting with Clarifai's Image Tagging API. Users need a Clarifai account to use this, as the endpoints require an access token.

clarifai-hs

Haskell API Client for Clarifai.

Clarifai provides image/video recognition services, and this library provides a web client to their API.

All endpoints other than the feedback endpoint are implemented. This includes

  • /info
  • /token
  • /tag

Installation

cabal install clarifai

Example Usage

Authorization

First create an App and then call the authorize function to authenticate your application. You must provide your client id and client secret.


import Network.Clarifai
import Data.Either

clientID = "id"
clientSecret = "secret"

main = do
  let myApp = App clientID clientSecret
  resp <- authorize myApp

Then you can check the response for errors, or use the access token it provides back in the form of a Client.

Getting API Info

-- Omitted previous code
main = do
  -- Be sure to check for errors
  let client = head $ rights [resp]
  infoResponse <- info client

If there are no errors, you will get back an Info containing various information about the statistics and limits of the Clarifai API, like maximum video size, maximum image size, etc. You can use this verify any files you may want to tag, before you send a tagging request.

Verification

When going to verify batch sizes, it is important not to mix and match between videos and images. The batch sizes for images and videos are different, so you cannot verify the sizes of the batches together even though you can send them in the same request. I don't do any differentiating between what kind of file the FilePath points to.

If you are calling the verifyFiles function, however, you can have a list of both videos AND images, as long as the extensions of each FilePath indicate the type of the file.

-- Omitted previous code
main = do
  -- Be sure to check for errors
  let apiInfo = head $ rights [infoResponse]
  let filePaths = [filePath1, filePath2, filePath3]

  -- Verify the image batch size
  -- The return value is a Bool indicating whether your list is of appropriate size for the API.
  verifyImageBatchSize apiInfo filePaths

  -- Verify the sizes of the files in the list. As long as each FilePath indicates whether the file is a video or an image,
  -- the size of the file will be checked to make sure it is within the appropriate bounds according to the API Info.
  verifyFiles infoData fileNames

Tagging

We can send a tag request with our list of FilePaths. I've omitted any steps where we may have filtered out which files verifyFiles marked as inappropriate for the request.

-- Omitted previous code
tagResponse <- tag client fileNames

Contributing

I'll gladly take contributions/improvements/pull requests.

License

The MIT License (MIT)

Copyright (c) 2015 Joe Canero

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Metadata

Version

0.2.0.0

License

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows