January 26, 2018

See Sharper with Clarifai's New C# Client

Table of Contents:

We’re excited to announce the immediate availability of our new official Clarifai C# client. This has been our most requested library and we’re stoked to release it!

 

As an AI company built upon the foundation of learning and innovation, we’re always looking to improve our platform and experience. So we’re excited to announce the launch of Clarifai’s C# client. This has been our most requested library so far. If you would like to see us launch any other clients, please let us know here!

Getting started with the client is super easy. You can include Clarifai in your project by using the dotnet command line tool as follows:

dotnet add package Clarifai

Then you can make predictions accordingly:

using System;
using Clarifai.API;
using Clarifai.DTOs.Inputs;

namespace hello_csharp
{
    internal class Program
    {
        public static void Main()
        {
            // With `CLARIFAI_API_KEY` defined as an environment variable
            var client = new ClarifaiClient().

            // When passed in as a string
            var client = new ClarifaiClient("YOUR_CLARIFAI_API_KEY");

            // When using async/await
            var res = await client.PublicModels.GeneralModel
                .Predict(new ClarifaiURLImage("https://samples.clarifai.com/metro-north.jpg"))
                .ExecuteAsync()

            // When synchronous
            var res = client.PublicModels.GeneralModel
                .Predict(new ClarifaiURLImage("https://samples.clarifai.com/metro-north.jpg"))
                .ExecuteAsync()
                .Result;

            // Print the concepts
            foreach (var concept in res.Get().Data)
            {
                Console.WriteLine($"{concept.Name}: {concept.Value}");
            }
        }
    }
}

 For more code samples you can check out our documentation as well as a C# sample application to get you started. Please send any feedback to hackers@clarifai.com, Happy Hacking!