public async Task GetInputsStatusResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( getResponse: @" { ""status"": { ""code"": 10000, ""description"": ""Ok"" }, ""counts"": { ""processed"": 1, ""to_process"": 2, ""errors"": 3, ""processing"": 4, ""reindexed"": 5, ""to_reindex"": 6, ""reindex_errors"": 7, ""reindexing"": 8 } } "); var client = new ClarifaiClient(httpClient); ClarifaiResponse <ClarifaiInputsStatus> response = await client.GetInputsStatus().ExecuteAsync(); var status = (ClarifaiInputsStatus)response.Get(); Assert.True(response.IsSuccessful); Assert.AreEqual(status.Processed, 1); Assert.AreEqual(status.ToProcess, 2); Assert.AreEqual(status.Errors, 3); Assert.AreEqual(status.Processing, 4); }
public async Task GetConceptResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( getResponse: @" { ""status"": { ""code"": 10000, ""description"": ""Ok"" }, ""concept"": { ""id"": ""@conceptID"", ""name"": ""@conceptName"", ""created_at"": ""2017-10-02T11:34:20.419915Z"", ""language"": ""en"", ""app_id"": ""@appID"" } } "); var client = new ClarifaiClient(httpClient); var response = await client.GetConcept("").ExecuteAsync(); Assert.True(response.IsSuccessful); Concept concept = response.Get(); Assert.AreEqual("@conceptID", concept.ID); Assert.AreEqual("@conceptName", concept.Name); Assert.AreEqual("@appID", concept.AppID); }
static void Main(string[] args) { // With `CLARIFAI_API_KEY` defined as an environment variable var client = new ClarifaiClient("9b91bce106fd4d25946434b28687f915"); // 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://cdn1.vectorstock.com/i/1000x1000/32/45/cartoon-sun-with-sunglasses-vector-21573245.jpg")) .ExecuteAsync() .Result; // Print the concepts foreach (var concept in res.Get().Data) { Console.WriteLine($"{concept.Name}: {concept.Value}"); } }
public static async Task RecognizeImage(string path, ImageData imageData) { var clarifaiClient = new ClarifaiClient(CLARIFY_KEY); var res = await clarifaiClient.PublicModels.GeneralModel.Predict( new ClarifaiFileImage(File.ReadAllBytes(path) ) ).ExecuteAsync(); if (res != null) { res.Get().Data.ForEach(async it => { var concept = new Concept { imageData = imageData, value = it.Name }; //RealmService.GetInstance().RealmAdd(concept); Realm.GetInstance().Write(() => { Realm.GetInstance().Add(concept); }); //var result = Realm.GetInstance().All<ImageData>(); //Console.WriteLine(result.ToString()); //await AddDictonaryOfConcept(concept); }); Realm.GetInstance().Write(() => { imageData.IsUpdated = true; }); } }
public async Task SearchesFeedbackRequestAndResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( postResponse: @"{""status"":{""code"":10000,""description"":""Ok""}}"); var client = new ClarifaiClient(httpClient); ClarifaiResponse <EmptyResponse> response = await client.SearchesFeedback( "@inputID", "@searchID", "@endUserID", "@sessionID" ).ExecuteAsync(); var expectedRequestBody = JObject.Parse(@" { ""input"": { ""id"": ""@inputID"", ""feedback_info"": { ""event_type"": ""search_click"", ""search_id"": ""@searchID"", ""end_user_id"": ""@endUserID"", ""session_id"": ""@sessionID"" } } } "); Assert.True(JToken.DeepEquals(expectedRequestBody, httpClient.PostedBody)); Assert.True(response.IsSuccessful); Assert.AreEqual("Ok", response.Status.Description); }
public async Task GetModelVersionResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( getResponse: @" { ""status"": { ""code"": 10000, ""description"": ""Ok"" }, ""model_version"": { ""id"": ""@versionID"", ""created_at"": ""2017-01-01T00:00:00.000000Z"", ""status"": { ""code"": 21100, ""description"": ""Model trained successfully"" }, ""active_concept_count"": 2, ""metrics"": { ""status"": { ""code"": 21303, ""description"": ""@modelDESCRIPTION"" } }, ""total_input_count"": 30 } } "); var client = new ClarifaiClient(httpClient); ClarifaiResponse <ModelVersion> response = await client.GetModelVersion("@modelID", "@versionID").ExecuteAsync(); Assert.True(response.IsSuccessful); Assert.AreEqual(response.Get().ID, "@versionID"); Assert.AreEqual(response.Get().ActiveConceptCount, 2); Assert.AreEqual(response.Get().ModelMetricsStatus.Description, "@modelDESCRIPTION"); }
public void Init(IClarifaiConfigurationProvider config) { this.frameRecognizedSubject = new Subject <IFrameRecognizedEvent>(); this.modelId = config.GetModelId(); this.client = new ClarifaiClient(config.GetApiKey()); }
public async Task ModifyConceptRequestAndResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( patchResponse: @" { ""status"": { ""code"": 10000, ""description"": ""Ok"" }, ""concepts"": [{ ""id"": ""@positiveConcept1"", ""name"": ""@positiveConceptName1"", ""created_at"": ""2017-10-15T16:28:28.901994Z"", ""language"": ""en"", ""app_id"": ""@appID"" }, { ""id"": ""@positiveConcept2"", ""created_at"": ""2017-10-15T16:26:46.667104Z"", ""language"": ""en"", ""app_id"": ""@appID"" }] } "); var client = new ClarifaiClient(httpClient); ClarifaiResponse <List <Concept> > response = await client.ModifyConcepts( new List <Concept> { new Concept("@positiveConcept1", "@positiveConceptName1"), new Concept("@positiveConcept2") } ).ExecuteAsync(); var expectedRequestBody = JObject.Parse(@" { ""action"": ""overwrite"", ""concepts"": [ { ""id"": ""@positiveConcept1"", ""name"": ""@positiveConceptName1"" }, { ""id"": ""@positiveConcept2"", ""name"": null } ] } "); Assert.True(JToken.DeepEquals(expectedRequestBody, httpClient.PatchedBody)); Assert.True(response.IsSuccessful); Assert.AreEqual("Ok", response.Status.Description); Assert.AreEqual(response.Get()[0].ID, "@positiveConcept1"); Assert.AreEqual(response.Get()[0].Name, "@positiveConceptName1"); Assert.AreEqual(response.Get()[1].ID, "@positiveConcept2"); }
private async void Screen_Anal_Button_Click(object sender, EventArgs e) { int rowsin = Images_Compare_Grid.RowCount - 1; progressBar1.Maximum = rowsin; var client = new ClarifaiClient("f5d04074f20343b787952a2605d34b3a"); MySqlConnection conn = DBUtils.GetDBConnection(); MySqlCommand cmd = conn.CreateCommand(); cmd.Connection.Open(); string truncate = "TRUNCATE `an_base_our_screens`;"; cmd.CommandText = truncate; for (int n = 0; n < (rowsin); n++) { string links = Images_Compare_Grid[0, n].Value.ToString(); var res = await client.PublicModels.GeneralModel.Predict(new ClarifaiURLImage(links)).ExecuteAsync(); try { var res2 = await client.PublicModels.FocusModel.Predict(new ClarifaiURLImage(links)).ExecuteAsync(); int vid_id = Convert.ToInt32(Images_Compare_Grid[1, n].Value.ToString()); try { foreach (var concept in res.Get().Data) { Screen_Analyze_Grid.Rows.Add($"{concept.Name}", $"{concept.Value}", links, vid_id); string sql = "INSERT INTO an_base_our_screens (name,value,img_link,vid_id) VALUES (@name,@val,@link,@img_id)"; using (MySqlCommand cmd1 = new MySqlCommand(sql, conn)) { cmd1.Parameters.AddWithValue("@name", concept.Name); cmd1.Parameters.AddWithValue("@val", concept.Value); cmd1.Parameters.AddWithValue("@link", links); cmd1.Parameters.AddWithValue("@img_id", vid_id); cmd1.ExecuteNonQuery(); } } } catch (MySqlException ex) { Mini_Log.AppendText("Error: \r\n{ 0}" + ex.ToString()); } Mini_Log.AppendText(">> Analyzed: " + n + " images \n"); progressBar1.Value = n + 1; } catch (Exception exps) { } } Mini_Log.AppendText(">> Analyzing completed successfully! \n"); MessageBox.Show("Analyze Completed Successfully!", "Success!", MessageBoxButtons.OK); }
public async Task TrainModelRequestAndResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( postResponse: @" { ""status"": { ""code"": 10000, ""description"": ""Ok"" }, ""model"": { ""id"": ""some-model-id"", ""name"": ""some-model-name"", ""created_at"": ""2017-05-16T19:20:38.733764Z"", ""app_id"": ""main"", ""output_info"": { ""data"": { ""concepts"": [{ ""id"": ""some-concept-id"", ""name"": ""safe"", ""created_at"": ""2017-05-16T19:20:38.450157Z"", ""language"": ""en"", ""app_id"": ""main"" }] }, ""type"": ""concept"", ""type_ext"": ""concept"" }, ""model_version"": { ""id"": ""some-model-version-id"", ""created_at"": ""2017-05-16T19:20:38.733764Z"", ""status"": { ""code"": 21100, ""description"": ""Model trained successfully"" }, ""active_concept_count"": 5 }, ""display_name"": ""Moderation"" } } "); var client = new ClarifaiClient(httpClient); ClarifaiResponse <IModel <Concept> > response = await client.TrainModel <Concept>("some-model-id").ExecuteAsync(); var expectedRequestBody = JObject.Parse(@" {} "); Assert.True(JToken.DeepEquals(expectedRequestBody, httpClient.PostedBody)); Assert.True(response.IsSuccessful); Assert.AreEqual("Ok", response.Status.Description); Assert.AreEqual(response.Get().Name, "some-model-name"); Assert.AreEqual(response.Get().ModelID, "some-model-id"); Assert.AreEqual(response.Get().ModelVersion.ID, "some-model-version-id"); }
static void Main(string[] args) { ClarifaiClient c = new ClarifaiClient("Wads5t98mMepkTuQFLbQvdYBPH0xIBz_7KqdhMIp", "Igqe-qov2dbcS8EQDHoI8DxRR0PiEN3y3Tj4Vu2m"); var task_r_ntf = c.GenerateToken(); task_r_ntf.ConfigureAwait(true) .GetAwaiter() .OnCompleted(() => { try { if (task_r_ntf.IsCompleted) { if (task_r_ntf.Status == TaskStatus.RanToCompletion) { Task.Run(async() => { var p = await c.PredictByFolderPath(@"C:\My Files\work\Ashraf\LogoDetection\test-positive"); Console.WriteLine(p.Status.Code); Console.WriteLine(p.Status.Description); if (p.Status.Code == 10000) { foreach (var d in p.Outputs) { Console.WriteLine(d.Data.Concepts[0].ImageName); Console.WriteLine(d.Data.Concepts[0].Prediction); } } }); } else { Console.WriteLine("completed with errors " + task_r_ntf.Status); if (task_r_ntf.Exception != null) { if (task_r_ntf.Exception.InnerException != null) { Console.WriteLine("Excepion : " + task_r_ntf.Exception.Message + " - Details : " + task_r_ntf.Exception.InnerException.Message); } else { Console.WriteLine("Excepion : " + task_r_ntf.Exception.Message); } } } } else { Console.WriteLine("serving notifications failed"); } } catch (Exception e) { Console.WriteLine("Excepion : " + e.Message); } }); Console.ReadLine(); }
public async Task DeleteModelResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( deleteResponse: @"{""status"":{""code"":10000,""description"":""Ok""}}"); var client = new ClarifaiClient(httpClient); ClarifaiResponse <EmptyResponse> response = await client.DeleteModel("@modelID").ExecuteAsync(); Assert.True(response.IsSuccessful); Assert.AreEqual("Ok", response.Status.Description); }
public static async Task <string> Predict(byte[] byteImage) { var client = new ClarifaiClient("d7b04a99342b4c9ea11f5f127879583f"); var res = await client.PublicModels.FoodModel.Predict( new ClarifaiFileImage(byteImage)) .ExecuteAsync(); return(res.RawBody); }
public async Task GetModelResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( getResponse: @" { ""status"": { ""code"": 10000, ""description"": ""Ok"" }, ""model"": { ""id"": ""some-model-id"", ""name"": ""some-model-name"", ""created_at"": ""2017-05-16T19:20:38.733764Z"", ""app_id"": ""main"", ""output_info"": { ""data"": { ""concepts"": [{ ""id"": ""some-concept-id"", ""name"": ""safe"", ""created_at"": ""2017-05-16T19:20:38.450157Z"", ""language"": ""en"", ""app_id"": ""main"" }] }, ""type"": ""concept"", ""type_ext"": ""concept"" }, ""model_version"": { ""id"": ""some-model-version-id"", ""created_at"": ""2017-05-16T19:20:38.733764Z"", ""status"": { ""code"": 21100, ""description"": ""Model trained successfully"" }, ""active_concept_count"": 5 }, ""display_name"": ""Moderation"" } } "); var client = new ClarifaiClient(httpClient); var response = await client.GetModel <Concept>("").ExecuteAsync(); var model = (ConceptModel)response.Get(); Assert.True(response.IsSuccessful); Assert.AreEqual("some-model-id", model.ModelID); Assert.AreEqual("some-model-name", model.Name); Assert.AreEqual("some-concept-id", model.OutputInfo.Concepts.First().ID); Assert.AreEqual("some-model-version-id", model.ModelVersion.ID); }
public async Task SearchModelsByNameAndTypeRequestAndResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( postResponse: @" { ""status"": { ""code"": 10000, ""description"": ""Ok"" }, ""models"": [{ ""id"": ""@modelID"", ""name"": ""color"", ""created_at"": ""2017-03-06T22:57:00.660603Z"", ""app_id"": ""main"", ""output_info"": { ""message"": ""Show output_info with: GET /models/{model_id}/output_info"", ""type"": ""color"", ""type_ext"": ""color"" }, ""model_version"": { ""id"": ""@modelVersionID"", ""created_at"": ""2017-03-06T22:57:00.684652Z"", ""status"": { ""code"": 21100, ""description"": ""Model trained successfully"" } }, ""display_name"": ""Color"" }] } "); var client = new ClarifaiClient(httpClient); var response = await client.SearchModels("*", ModelType.Color).ExecuteAsync(); var expectedRequestBody = JObject.Parse(@" { ""model_query"": { ""name"": ""*"", ""type"": ""color"" } } "); Assert.True(JToken.DeepEquals(expectedRequestBody, httpClient.PostedBody)); List <IModel> models = response.Get(); Assert.True(response.IsSuccessful); Assert.AreEqual(1, models.Count); Assert.AreEqual("@modelID", models[0].ModelID); Assert.AreEqual("@modelVersionID", models[0].ModelVersion.ID); }
public async Task SearchModelsByNameRequestAndResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( postResponse: @" { ""status"": { ""code"": 10000, ""description"": ""Ok"" }, ""models"": [{ ""id"": ""@modelID"", ""name"": ""celeb-v1.3"", ""created_at"": ""2016-10-25T19:30:38.541073Z"", ""app_id"": ""main"", ""output_info"": { ""message"": ""Show output_info with: GET /models/{model_id}/output_info"", ""type"": ""concept"", ""type_ext"": ""facedetect-identity"" }, ""model_version"": { ""id"": ""@modelVersionID"", ""created_at"": ""2016-10-25T19:30:38.541073Z"", ""status"": { ""code"": 21100, ""description"": ""Model trained successfully"" }, ""active_concept_count"": 10554 }, ""display_name"": ""Celebrity"" }] } "); var client = new ClarifaiClient(httpClient); var response = await client.SearchModels("celeb*").ExecuteAsync(); var expectedRequestBody = JObject.Parse(@" { ""model_query"": { ""name"": ""celeb*"" } } "); Assert.True(JToken.DeepEquals(expectedRequestBody, httpClient.PostedBody)); List <IModel> models = response.Get(); Assert.True(response.IsSuccessful); Assert.AreEqual(1, models.Count); Assert.AreEqual("@modelID", models[0].ModelID); Assert.AreEqual("@modelVersionID", models[0].ModelVersion.ID); }
static void Main1(string[] args) { ClarifaiClient c = new ClarifaiClient("JU5zeSv_YJQG5THfAHwUvuD_oDFI13PqFKTXjKoS", "GQynbkt8D5mQcXUlZhcPqw7SAyQbTjj3WC1SYpkM"); var task_r_ntf = c.GetToken(); task_r_ntf.ConfigureAwait(true) .GetAwaiter() .OnCompleted(() => { try { if (task_r_ntf.IsCompleted) { if (task_r_ntf.Status == TaskStatus.RanToCompletion) { var res = task_r_ntf.Result; if (res is TokenError) { Console.WriteLine(((TokenError)res).Status_Msg); } else { Console.WriteLine(((Token)res).Access_Token); } } else { Console.WriteLine("completed with errors " + task_r_ntf.Status); if (task_r_ntf.Exception != null) { if (task_r_ntf.Exception.InnerException != null) { Console.WriteLine("Excepion : " + task_r_ntf.Exception.Message + " - Details : " + task_r_ntf.Exception.InnerException.Message); } else { Console.WriteLine("Excepion : " + task_r_ntf.Exception.Message); } } } } else { Console.WriteLine("serving notifications failed"); } } catch (Exception e) { Console.WriteLine("Excepion : " + e.Message); } }); Console.ReadLine(); }
static void Main2(string[] args) { ClarifaiClient c = new ClarifaiClient("JU5zeSv_YJQG5THfAHwUvuD_oDFI13PqFKTXjKoS", "GQynbkt8D5mQcXUlZhcPqw7SAyQbTjj3WC1SYpkM"); var task_r_ntf = c.GenerateToken(); task_r_ntf.ConfigureAwait(true) .GetAwaiter() .OnCompleted(() => { try { if (task_r_ntf.IsCompleted) { if (task_r_ntf.Status == TaskStatus.RanToCompletion) { Task.Run(async() => { var p = await c.PredictByImgURL(new List <string> { "https://samples.clarifai.com/metro-north.jpg" }); Console.WriteLine(p.Status.Code); Console.WriteLine(p.Status.Description); }); } else { Console.WriteLine("completed with errors " + task_r_ntf.Status); if (task_r_ntf.Exception != null) { if (task_r_ntf.Exception.InnerException != null) { Console.WriteLine("Excepion : " + task_r_ntf.Exception.Message + " - Details : " + task_r_ntf.Exception.InnerException.Message); } else { Console.WriteLine("Excepion : " + task_r_ntf.Exception.Message); } } } } else { Console.WriteLine("serving notifications failed"); } } catch (Exception e) { Console.WriteLine("Excepion : " + e.Message); } }); Console.ReadLine(); }
private async void button16_Click(object sender, EventArgs e) { var client = new ClarifaiClient("f5d04074f20343b787952a2605d34b3a"); int rowsin = Images_Compare_Grid.RowCount - 1; MySqlConnection conn = DBUtils.GetDBConnection(); MySqlCommand cmd = conn.CreateCommand(); cmd.Connection.Open(); string truncate = "TRUNCATE `an_base_our_screens`;"; cmd.CommandText = truncate; for (int n = 0; n < (rowsin); n++) { string links = Images_Compare_Grid[0, n].Value.ToString(); int vid_id = Convert.ToInt32(Images_Compare_Grid[1, n].Value.ToString()); //MessageBox.Show(links); if (Images_Compare_Grid[0, n].Value.ToString() != null) { try { var resor = await client.PublicModels.FocusModel.Predict(new ClarifaiURLImage(Images_Compare_Grid[0, n].Value.ToString())).ExecuteAsync(); //MessageBox.Show(resor.Get().Data.ToString()); if (resor != null) { foreach (var concept in resor.Get().Data) { if (Convert.ToDouble(concept.Value) != 0) { Screen_Analyze_Grid.Rows.Add($"Focus Value", $"{concept.Value}", links, vid_id); string sql = "INSERT INTO an_base_our_screens (name,value,img_link,vid_id) VALUES (@name,@val,@link,@img_id)"; using (MySqlCommand cmd1 = new MySqlCommand(sql, conn)) { cmd1.Parameters.AddWithValue("@name", "Focus Value"); cmd1.Parameters.AddWithValue("@val", concept.Value); cmd1.Parameters.AddWithValue("@link", links); cmd1.Parameters.AddWithValue("@img_id", vid_id); cmd1.ExecuteNonQuery(); } } } } } catch (Exception ext) { } } } }
public async Task GetInputResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( getResponse: @" { ""status"": { ""code"": 10000, ""description"": ""Ok"" }, ""input"": { ""id"": ""@inputID"", ""data"": { ""image"": { ""url"": ""@imageURL"" }, ""concepts"": [ { ""id"": ""@positiveConcept"", ""value"": 1 }, { ""id"": ""@negativeConcept1"", ""value"": 0 }, { ""id"": ""@negativeConcept2"", ""value"": 0 } ] }, ""created_at"": ""2017-10-13T20:53:00.253139Z"", ""modified_at"": ""2017-10-13T20:53:00.868659782Z"", ""status"": { ""code"": 30200, ""description"": ""Input image modification success"" } } } "); var client = new ClarifaiClient(httpClient); ClarifaiResponse <IClarifaiInput> response = await client.GetInput("@inputID").ExecuteAsync(); var input = (ClarifaiURLImage)response.Get(); Assert.True(response.IsSuccessful); Assert.AreEqual(input.ID, "@inputID"); Assert.AreEqual(input.URL, "@imageURL"); Assert.AreEqual(input.PositiveConcepts.ElementAt(0).ID, "@positiveConcept"); Assert.AreEqual(input.NegativeConcepts.ElementAt(0).ID, "@negativeConcept1"); Assert.AreEqual(input.NegativeConcepts.ElementAt(1).ID, "@negativeConcept2"); }
// Use this for initialization void Start() { shopperButton.GetComponent <Image>().CrossFadeAlpha(0f, 0f, true); loadRing.GetComponent <Image>().CrossFadeAlpha(0f, 0f, true); _allowNewRequest = false; // We set this callback in order to allow doing HTTPS requests which are done against the // Clarifai API endpoint. ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallback; // You can skip the API key argument if you have an environmental variable set called // CLARIFAI_API_KEY that contains your Clarifai API key. _client = new ClarifaiClient(_clarifaiApiKey); //ClarifaiRequestTimer(); }
public async Task ModelFeedbackRequestAndResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( postResponse: @"{""status"":{""code"":10000,""description"":""Ok""}}"); var client = new ClarifaiClient(httpClient); ClarifaiResponse <EmptyResponse> response = await client.ModelFeedback( "@modelID", "@imageURL", "@inputID", "@outputID", "@endUserID", "@sessionID", new List <ConceptFeedback> { new ConceptFeedback("dog", true), new ConceptFeedback("cat", false) }).ExecuteAsync(); var expectedRequestBody = JObject.Parse(@" { ""input"": { ""id"": ""@inputID"", ""data"": { ""image"": { ""url"": ""@imageURL"" }, ""concepts"": [ { ""id"": ""dog"", ""value"": true }, { ""id"": ""cat"", ""value"": false } ] }, ""feedback_info"": { ""event_type"": ""annotation"", ""output_id"": ""@outputID"", ""end_user_id"": ""@endUserID"", ""session_id"": ""@sessionID"" } } } "); Assert.True(JToken.DeepEquals(expectedRequestBody, httpClient.PostedBody)); Assert.True(response.IsSuccessful); Assert.AreEqual("Ok", response.Status.Description); }
public async Task ModelEvaluationResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( postResponse: @" { ""status"": { ""code"": 10000, ""description"": ""Ok"" }, ""model_version"": { ""id"": ""@versionID"", ""created_at"": ""2017-01-01T00:00:00.000000Z"", ""status"": { ""code"": 21100, ""description"": ""Model trained successfully"" }, ""active_concept_count"": 2, ""metrics"": { ""status"": { ""code"": 21303, ""description"": ""Model is queued for evaluation."" } }, ""total_input_count"": 30 } } "); var client = new ClarifaiClient(httpClient); ClarifaiResponse <ModelVersion> response = await client.ModelEvaluation( "", "").ExecuteAsync(); Assert.True(response.IsSuccessful); Assert.AreEqual("Ok", response.Status.Description); ModelVersion modelVersion = response.Get(); Assert.AreEqual("@versionID", modelVersion.ID); Assert.AreEqual(21100, modelVersion.Status.StatusCode); Assert.AreEqual("Model trained successfully", modelVersion.Status.Description); Assert.AreEqual(21303, modelVersion.ModelMetricsStatus.StatusCode); Assert.AreEqual("Model is queued for evaluation.", modelVersion.ModelMetricsStatus.Description); Assert.AreEqual(2, modelVersion.ActiveConceptCount); Assert.AreEqual(30, modelVersion.TotalInputCount); }
public async Task GetConceptsResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( getResponse: @" { ""status"": { ""code"": 10000, ""description"": ""Ok"" }, ""concepts"": [{ ""id"": ""@conceptID1"", ""name"": ""@conceptName1"", ""created_at"": ""2017-10-15T16:28:28.901994Z"", ""language"": ""en"", ""app_id"": ""@appID"" }, { ""id"": ""@conceptID2"", ""name"": ""@conceptName2"", ""created_at"": ""2017-10-15T16:26:46.667104Z"", ""language"": ""en"", ""app_id"": ""@appID"" }] } "); var client = new ClarifaiClient(httpClient); var response = await client.GetConcepts().ExecuteAsync(); Assert.True(response.IsSuccessful); List <Concept> concepts = response.Get(); Assert.AreEqual(2, concepts.Count); Concept concept1 = concepts[0]; Concept concept2 = concepts[1]; Assert.AreEqual("@conceptID1", concept1.ID); Assert.AreEqual("@conceptName1", concept1.Name); Assert.AreEqual("@appID", concept1.AppID); Assert.AreEqual("@conceptID2", concept2.ID); Assert.AreEqual("@conceptName2", concept2.Name); Assert.AreEqual("@appID", concept2.AppID); }
public static void RefreshAPIKey() { var apiKey = PersistanceUtil.RetreiveSetting(Setting.ApiKey); if (apiKey == "") { SetAPIKeyViaDialog(); } else { httpClient = new HttpClient(); httpClient.BaseAddress = new Uri(@"https://api.clarifai.com/v2/models/"); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Key", apiKey); httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); clarifaiClient = new ClarifaiClient(apiKey); } }
// Use this for initialization void Start() { // We set this callback in order to allow doing HTTPS requests which are done against the // Clarifai API endpoint. ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallback; // You can skip the API key argument if you have an environmental variable set called // CLARIFAI_API_KEY that contains your Clarifai API key. _client = new ClarifaiClient(_clarifaiApiKey); _labelStyle = new GUIStyle { fontSize = 20, normal = { textColor = UnityEngine.Color.white }, }; ClarifaiRequestTimer(); }
public async Task SearchConceptsRequestAndResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( postResponse: @" { ""status"": { ""code"": 10000, ""description"": ""Ok"" }, ""concepts"": [{ ""id"": ""@positiveConcept1"", ""name"": ""@positiveConceptName1"", ""created_at"": ""2017-10-15T16:28:28.901994Z"", ""language"": ""en"", ""app_id"": ""@appID"" }, { ""id"": ""@positiveConcept2"", ""created_at"": ""2017-10-15T16:26:46.667104Z"", ""language"": ""en"", ""app_id"": ""@appID"" }] } "); var client = new ClarifaiClient(httpClient); var response = await client.SearchConcepts("positives", "en").ExecuteAsync(); var expectedRequestBody = JObject.Parse(@" { ""concept_query"": { ""name"": ""positives"", ""language"": ""en"" } } "); Assert.True(JToken.DeepEquals(expectedRequestBody, httpClient.PostedBody)); Assert.True(response.IsSuccessful); Assert.AreEqual(response.Get()[0].ID, "@positiveConcept1"); Assert.AreEqual(response.Get()[0].Name, "@positiveConceptName1"); Assert.AreEqual(response.Get()[1].ID, "@positiveConcept2"); }
public async Task GetModelInputsResponseShouldBeCorrect() { var httpClient = new FkClarifaiHttpClient( getResponse: @" { ""status"": { ""code"": 10000, ""description"": ""Ok"" }, ""inputs"": [{ ""id"": ""@inputID"", ""data"": { ""image"": { ""url"": ""@imageURL"" }, ""concepts"": [{ ""id"": ""@conceptID"", ""name"": ""@conceptName"", ""value"": 1, ""app_id"": ""@conceptAppID"" }] }, ""created_at"": ""2017-10-15T16:30:52.964888Z"", ""status"": { ""code"": 30000, ""description"": ""Download complete"" } }] } "); var client = new ClarifaiClient(httpClient); ClarifaiResponse <List <IClarifaiInput> > response = await client.GetModelInputs( "", "").ExecuteAsync(); Assert.True(response.IsSuccessful); Assert.AreEqual("Ok", response.Status.Description); IClarifaiInput input = response.Get()[0]; Assert.AreEqual("@inputID", input.ID); Assert.AreEqual("@conceptID", input.PositiveConcepts.First().ID); }
public async Task <TwiMLResult> Index(SmsRequest request) { // TODO: Define the environment variable or plug your api key in var CLARIFAI_API_KEY = System.Environment.GetEnvironmentVariable("CLARIFAI_API_KEY") ?? "YOUR_CLARIFAI_API_KEY_HERE"; var response = new MessagingResponse(); var url = Request.Form["MediaUrl0"]; if (string.IsNullOrEmpty(url)) { response.Message("Picture not found. Please send one."); return(TwiML(response)); } try { var client = new ClarifaiClient(CLARIFAI_API_KEY); var image = new ClarifaiURLImage(url); var result = await client.PublicModels.GeneralModel.Predict(image, maxConcepts : 5).ExecuteAsync(); if (result.IsSuccessful) { var concepts = result.Get()[0].Data.Select(c => $"{c.Name}:{c.Value}"); var body = string.Join(", ", concepts); response.Message(body); } else { response.Message($"The request was not successful: {result.Status.Description}"); } } catch (Exception e) { response.Message($"Something went wrong: {e.Message}"); } return(TwiML(response)); }
public async Task <Dictionary <string, double> > GetPredictionsForProperty() { var Client = new ClarifaiClient(Constants.ApiKey); var imagesResult = new List <IClarifaiInput>(); foreach (var picture in _pictures) { imagesResult.Add(new ClarifaiURLImage(picture)); } var response = await Client.Predict <Concept>( Client.PublicModels.GeneralModel.ModelID, imagesResult, null, null, null, 50) .ExecuteAsync(); predictions = GetPredictionModel(response.RawBody); keyWords = new List <string>(GetKeyWords(predictions.Pictures)); return(GetVector(predictions)); }