Code Monkey home page Code Monkey logo

clarifai-hs's People

Contributors

caneroj1 avatar mwotton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mwotton silky

clarifai-hs's Issues

transformers api?

Hi,

I've been playing around with this this morning and thought it might be helpful to have a transformers-based api on it - means you don't have to keep checking for errors & repeating the client argument everywhere.

client code looks like this

runFunc :: String -> String -> IO ()
runFunc id secret = do
  runClarifaiT (id,secret) $ do
    infoM >>= liftIO . print
    tagsets <- tagM ["./eastern.jpg", "./cat.jpg"]
    liftIO $ print tagsets 

lib code behind it looks like this:


import Control.Monad (liftM, void)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Trans.Class (lift)
import Control.Monad.Trans.Either (EitherT(..), left, runEitherT)
import Control.Monad.Trans.Reader (ReaderT, ask, runReaderT)
import Network.Clarifai
import Data.Vector (Vector)

type ClientError = (Int,String)

newtype ClarifaiT m a = ClarifaiT {
  unCreateClient :: ReaderT Client
                    (EitherT ClientError m) a }
                          deriving (Functor, Applicative, Monad, MonadIO)

runClarifaiT :: MonadIO m => (String,String) -> ClarifaiT m a -> m (Either ClientError a)
runClarifaiT (id,secret) f = do
  (r :: Either ClientError Client) <- liftIO   $ authorize (App id secret)
  case r of
   Left e -> return $ Left e
   Right r ->  runEitherT $ runReaderT  (unCreateClient f) r

wrap :: MonadIO m => (Client-> IO (Either ClientError a0)) -> ClarifaiT m a0
wrap f = ClarifaiT $ either (lift.left) return =<< liftIO . f =<< ask

infoM :: MonadIO m => ClarifaiT m Info
infoM = wrap info

tagM :: MonadIO m => [FilePath] -> ClarifaiT m (Vector TagSet)
tagM fn = wrap (`tag` fn)

thought i'd check with you before bothering to wrap up the rest of the API - I know it looks a bit forbidding, but the client code really does look a lot nicer to my eyes.

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.