GithubHelp home page GithubHelp logo

silky / clarifai-hs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from caneroj1/clarifai-hs

0.0 2.0 0.0 17 KB

Haskell API Client for Clarifai.

Home Page: https://developer.clarifai.com/guide/#api-clients

License: MIT License

Haskell 100.00%

clarifai-hs's Introduction

clarifai-hs

Haskell API Client for Clarifai.

Documentation hosted on Hackage.

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.

clarifai-hs's People

Contributors

caneroj1 avatar mwotton avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.