Beispiel #1
0
        public async Task DeleteAllInputsRequestShouldBeSuccessful()
        {
            ClarifaiResponse <EmptyResponse> response = await Client.DeleteAllInputs()
                                                        .ExecuteAsync();

            AssertResponseSuccess(response);
        }
Beispiel #2
0
        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");
        }
Beispiel #3
0
        public async Task AllVideoModelsShouldPredictSuccessfully()
        {
            List <Model> videoModels = new List <Model>
            {
                Client.PublicModels.ApparelVideoModel,
                Client.PublicModels.FoodVideoModel,
                Client.PublicModels.GeneralVideoModel,
                Client.PublicModels.NsfwVideoModel,
                Client.PublicModels.TravelVideoModel,
                Client.PublicModels.WeddingVideoModel,
            };

            foreach (Model model in videoModels)
            {
                ClarifaiResponse <List <ClarifaiOutput <Frame> > > response =
                    await Client.Predict <Frame>(
                        model.ModelID,
                        new List <IClarifaiInput> {
                    new ClarifaiURLVideo(GIF1)
                })
                    .ExecuteAsync();

                Assert.True(response.IsSuccessful, $"Predict on {model.Name} not successful.");
            }
        }
        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 ModifyConceptRequestShouldUpdateConceptName()
        {
            string conceptID           = "someConceptID";
            string originalConceptName = "originalConceptName";
            string newConceptName      = "newConceptName";

            try
            {
                // Create a concept. It's fine if it already exists.
                await Client.AddConcepts(new Concept(conceptID, originalConceptName))
                .ExecuteAsync();

                // Modify the concept.
                ClarifaiResponse <List <Concept> > modifyResponse = await Client.ModifyConcepts(
                    new Concept(conceptID, newConceptName))
                                                                    .ExecuteAsync();

                Assert.True(modifyResponse.IsSuccessful);
                Assert.AreEqual(newConceptName, modifyResponse.Get()[0].Name);

                // Get the modified concept again to make sure the name was really updated.
                ClarifaiResponse <Concept> getResponse = await Client.GetConcept(conceptID)
                                                         .ExecuteAsync();

                Assert.AreEqual(newConceptName, getResponse.Get().Name);
            }
            finally
            {
                // Revert the concept's name back to the original name.
                await Client.ModifyConcepts(new Concept(conceptID, originalConceptName))
                .ExecuteAsync();
            }
        }
Beispiel #6
0
        public async Task OverwrittingConceptsForInputShouldBeSuccessful()
        {
            string inputID = GenerateRandomID();
            ClarifaiResponse <List <IClarifaiInput> > addResponse =
                await AddInputWithConcept1AndConcept2(inputID);

            AssertResponseSuccess(addResponse);

            try
            {
                await WaitForSpecificInputsUpload(inputID);

                ClarifaiResponse <IClarifaiInput> modifyResponse = await Client.ModifyInput(
                    inputID,
                    ModifyAction.Overwrite,
                    positiveConcepts : new List <Concept> {
                    new Concept("concept3")
                })
                                                                   .ExecuteAsync();

                AssertResponseSuccess(modifyResponse);

                List <Concept> concepts = await GetConcepts(inputID);

                Assert.AreEqual(1, concepts.Count);
                Assert.Contains("concept3", concepts.Select(c => c.ID).ToList());
            }
            finally
            {
                /*
                 * Delete the input.
                 */
                await DeleteInput(inputID);
            }
        }
        public async Task ShorthandGetModelInputsShouldBeSuccessful()
        {
            /*
             * Create a model.
             */
            string modelID = GenerateRandomID();
            ClarifaiResponse <ConceptModel> createModelResponse = await Client.CreateModel(
                modelID,
                concepts : new List <Concept> {
                new Concept("cat")
            })
                                                                  .ExecuteAsync();

            Assert.True(createModelResponse.IsSuccessful);

            try
            {
                ConceptModel model = createModelResponse.Get();
                var          getModelInputsResponse = await model.GetModelInputs().ExecuteAsync();

                Assert.True(getModelInputsResponse.IsSuccessful);
                Assert.NotNull(getModelInputsResponse.Get());
            }
            finally
            {
                /*
                 * Delete the model.
                 */
                var deleteResponse = await Client.DeleteModel(modelID)
                                     .ExecuteAsync();

                Assert.True(deleteResponse.IsSuccessful);
            }
        }
        public async Task GetConceptsShouldBeSuccessful()
        {
            ClarifaiResponse <List <Concept> > response = await Client.GetConcepts().ExecuteAsync();

            Assert.True(response.IsSuccessful);
            Assert.NotNull(response.Get());
        }
Beispiel #9
0
        public async Task ImageModelFeedbackWithRegionsShouldBeSuccessful()
        {
            ClarifaiResponse <EmptyResponse> response = await Client.ModelFeedback(
                modelID : Client.PublicModels.CelebrityModel.ModelID,
                imageUrl : CELEB1,
                inputID : "@inputID",
                outputID : "@outputID",
                endUserID : "@endUserID",
                sessionID : "@sessionID",
                concepts : new List <ConceptFeedback>
            {
                new ConceptFeedback("freeman", true), new ConceptFeedback("eminem", false)
            },
                regions : new List <RegionFeedback>
            {
                new RegionFeedback(
                    new Crop(0.1m, 0.1m, 0.2m, 0.2m),
                    Feedback.NotDetected,
                    new List <ConceptFeedback>
                {
                    new ConceptFeedback("freeman", true),
                    new ConceptFeedback("eminem", false)
                })
            }
                ).ExecuteAsync();

            Assert.True(response.IsSuccessful);
        }
        public async Task DeleteAllModelsRequestShouldBeSuccessful()
        {
            ClarifaiResponse <EmptyResponse> response = await Client.DeleteAllModels()
                                                        .ExecuteAsync();

            Assert.True(response.IsSuccessful);
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
        public async Task ShorthandDeleteModelVersionRequestShouldBeSuccessful()
        {
            string modelID = GenerateRandomID();

            ClarifaiResponse <ConceptModel> createResponse
                = await Client.CreateModel(
                      modelID,
                      name : modelID,
                      concepts : new List <Concept> {
                new Concept("dog"), new Concept("cat")
            })
                  .ExecuteAsync();

            AssertResponseSuccess(createResponse);

            ConceptModel model = createResponse.Get();

            ClarifaiResponse <ModelVersion> getVersionResponse =
                await Client.GetModelVersion(modelID, model.ModelVersion.ID).ExecuteAsync();

            string modelVersionID = getVersionResponse.Get().ID;

            ClarifaiResponse <EmptyResponse> deleteVersionResponse =
                await model.DeleteModelVersion(modelVersionID).ExecuteAsync();

            AssertResponseSuccess(deleteVersionResponse);

            /*
             * The model version should not exist anymore.
             */
            ClarifaiResponse <ModelVersion> getVersionResponse2 =
                await Client.GetModelVersion(modelID, modelVersionID).ExecuteAsync();

            Assert.False(getVersionResponse2.IsSuccessful);
        }
Beispiel #13
0
        public async Task AddingImageFileWithCropShouldBeSuccessful()
        {
            string inputID = GenerateRandomID();

            try
            {
                /*
                 * Add input with concepts.
                 */
                ClarifaiResponse <List <IClarifaiInput> > addResponse = await Client.AddInputs(
                    new ClarifaiFileImage(
                        ReadResource(BALLOONS_IMAGE_FILE),
                        id : inputID,
                        crop : new Crop(0.1M, 0.2M, 0.3M, 0.4M)))
                                                                        .ExecuteAsync();

                Assert.True(addResponse.IsSuccessful);

                ClarifaiURLImage input = (ClarifaiURLImage)addResponse.Get()[0];
                Assert.AreEqual(new Crop(0.1M, 0.2M, 0.3M, 0.4M), input.Crop);
            }
            finally
            {
                /*
                 * Delete the input.
                 */
                await DeleteInput(inputID);
            }
        }
Beispiel #14
0
        public async Task AddingImageUrlWithCropShouldBeSuccessful()
        {
            string inputID = GenerateRandomID();

            try
            {
                /*
                 * Add input with concepts.
                 */
                ClarifaiResponse <List <IClarifaiInput> > addResponse = await Client.AddInputs(
                    new ClarifaiURLImage(
                        CELEB1,
                        id : inputID,
                        crop : new Crop(0.1M, 0.2M, 0.3M, 0.4M),
                        allowDuplicateUrl : true))
                                                                        .ExecuteAsync();

                Assert.True(addResponse.IsSuccessful);
                var input = (ClarifaiURLImage)addResponse.Get()[0];
                Assert.AreEqual(new Crop(0.1M, 0.2M, 0.3M, 0.4M), input.Crop);
            }
            finally
            {
                /*
                 * Delete the input.
                 */
                await DeleteInput(inputID);
            }
        }
Beispiel #15
0
        public async Task RemovingConceptsForInputShouldBeSuccessful()
        {
            string inputID = GenerateRandomID();
            ClarifaiResponse <List <IClarifaiInput> > addResponse =
                await AddInputWithConcept1AndConcept2(inputID);

            Assert.True(addResponse.IsSuccessful);

            try
            {
                ClarifaiResponse <IClarifaiInput> modifyResponse = await Client.ModifyInput(
                    inputID,
                    ModifyAction.Remove,
                    new List <Concept> {
                    new Concept("concept2")
                })
                                                                   .ExecuteAsync();

                Assert.True(modifyResponse.IsSuccessful);

                List <Concept> concepts = await GetConcepts(inputID);

                Assert.AreEqual(1, concepts.Count);
                List <string> conceptIDs = concepts.Select(c => c.ID).ToList();
                Assert.Contains("concept1", conceptIDs);
            }
            finally
            {
                /*
                 * Delete the input.
                 */
                await DeleteInput(inputID);
            }
        }
Beispiel #16
0
        public async Task AllConceptModelsShouldPredictSuccessfully()
        {
            List <Model> conceptModels = new List <Model>
            {
                Client.PublicModels.ApparelModel,
                Client.PublicModels.FoodModel,
                Client.PublicModels.GeneralModel,
                Client.PublicModels.LandscapeQualityModel,
                Client.PublicModels.ModerationModel,
                Client.PublicModels.NsfwModel,
                Client.PublicModels.PortraitQualityModel,
                Client.PublicModels.TexturesAndPatternsModel,
                Client.PublicModels.TravelModel,
                Client.PublicModels.WeddingModel,
            };

            foreach (Model model in conceptModels)
            {
                ClarifaiResponse <List <ClarifaiOutput <Concept> > > response =
                    await Client.Predict <Concept>(
                        model.ModelID,
                        new List <IClarifaiInput> {
                    new ClarifaiURLImage(CAT1)
                })
                    .ExecuteAsync();

                Assert.True(response.IsSuccessful, $"Predict on {model.Name} not successful.");
            }
        }
Beispiel #17
0
        public async Task AddingInputWithConceptsShouldBeSuccessful()
        {
            string inputID = GenerateRandomID();

            try
            {
                /*
                 * Add input with concepts.
                 */
                ClarifaiResponse <List <IClarifaiInput> > addResponse = await Client.AddInputs(
                    new ClarifaiURLImage(
                        CELEB1,
                        id : inputID,
                        positiveConcepts : new List <Concept>
                {
                    new Concept("concept1"), new Concept("concept2"),
                },
                        allowDuplicateUrl : true))
                                                                        .ExecuteAsync();

                AssertResponseSuccess(addResponse);

                await WaitForSpecificInputsUpload(inputID);
            }
            finally
            {
                /*
                 * Delete the input.
                 */
                await DeleteInput(inputID);
            }
        }
        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");
        }
Beispiel #19
0
        public async Task SearchesFeedbackShouldBeSuccessful()
        {
            ClarifaiResponse <EmptyResponse> response = await Client.SearchesFeedback("@inputID",
                                                                                      "@searchID", "@endUserID", "@sessionID")
                                                        .ExecuteAsync();

            Assert.True(response.IsSuccessful);
        }
Beispiel #20
0
        public async Task SearchModelsByNameShouldBeSuccessful()
        {
            ClarifaiResponse <List <IModel> > response = await Client.SearchModels("celeb*")
                                                         .ExecuteAsync();

            Assert.NotNull(response.Get());
            Assert.True(response.Get().Count > 0);
        }
Beispiel #21
0
        public async Task SearchConceptsShouldBeSuccessful()
        {
            ClarifaiResponse <List <Concept> > response = await Client.SearchConcepts("conc*")
                                                          .ExecuteAsync();

            AssertResponseSuccess(response);
            Assert.IsNotNull(response.Get());
        }
Beispiel #22
0
        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");
        }
        public async Task SearchByConceptNameShouldBeSuccessful()
        {
            ClarifaiResponse <SearchInputsResult> response =
                await Client.SearchInputs(SearchBy.ConceptName("cat"))
                .ExecuteAsync();

            // The search is either successful or nothing has been found.
            Assert.True(response.IsSuccessful || response.Status.StatusCode == 40002);
        }
        public async Task SearchByUserTaggedConceptIDShouldBeSuccessful()
        {
            ClarifaiResponse <SearchInputsResult> response =
                await Client.SearchInputs(SearchBy.UserTaggedConceptID("cat"))
                .ExecuteAsync();

            AssertResponseSuccess(response);
            Assert.NotNull(response.Get().SearchHits);
        }
        public async Task SearchVisuallyByImageUrlUsingImageShouldBeSuccessful()
        {
            ClarifaiResponse <SearchInputsResult> response =
                await Client.SearchInputs(SearchBy.ImageVisually(new ClarifaiURLImage(CELEB1)))
                .ExecuteAsync();

            AssertResponseSuccess(response);
            Assert.NotNull(response.Get().SearchHits);
        }
        public async Task SearchConceptsWithLanguageShouldBeSuccessful()
        {
            ClarifaiResponse <List <Concept> > response = await Client.SearchConcepts("狗*",
                                                                                      language : "zh") // "zh" = Chinese
                                                          .ExecuteAsync();

            Assert.True(response.IsSuccessful);
            Assert.IsNotNull(response.Get());
        }
        public async Task SearchByConceptIDShouldBeSuccessful()
        {
            ClarifaiResponse <SearchInputsResult> response =
                await Client.SearchInputs(SearchBy.ConceptID("ai_mFqxrph2"))
                .ExecuteAsync();

            Assert.True(response.IsSuccessful);
            Assert.NotNull(response.Get().SearchHits);
        }
        public async Task SearchByImageUrlShouldBeSuccessful()
        {
            ClarifaiResponse <SearchInputsResult> response =
                await Client.SearchInputs(SearchBy.ImageURL(CELEB1))
                .ExecuteAsync();

            Assert.True(response.IsSuccessful);
            Assert.NotNull(response.Get().SearchHits);
        }
Beispiel #29
0
        public async Task SearchModelsByTypeShouldBeSuccessful()
        {
            ClarifaiResponse <List <IModel> > response = await Client.SearchModels("*",
                                                                                   ModelType.Color)
                                                         .ExecuteAsync();

            AssertResponseSuccess(response);
            Assert.NotNull(response.Get());
            Assert.True(response.Get().Count > 0);
        }
        public async Task SearchVisuallyByImageFileShouldBeSuccessful()
        {
            ClarifaiResponse <SearchInputsResult> response =
                await Client.SearchInputs(SearchBy.ImageVisually(
                                              new ClarifaiFileImage(ReadResource(BALLOONS_IMAGE_FILE))))
                .ExecuteAsync();

            AssertResponseSuccess(response);
            Assert.NotNull(response.Get().SearchHits);
        }