caneroj1 / clarifai-hs Goto Github PK
View Code? Open in Web Editor NEWHaskell API Client for Clarifai.
Home Page: https://developer.clarifai.com/guide/#api-clients
License: MIT License
Haskell API Client for Clarifai.
Home Page: https://developer.clarifai.com/guide/#api-clients
License: MIT License
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.