async Task MakePredictionRequest(MediaFile file) //this function calls api
        {
            var client = new HttpClient();

            //client.DefaultRequestHeaders.Add("Prediction-Key", "a51ac8a57d4e4345ab0a48947a4a90ac");

            //string url = "https://southcentralus.api.cognitive.microsoft.com/customvision/v1.0/Prediction/4da1555c-14ca-4aaf-af01-d6e1e97e5fa6/image?iterationId=7bc76035-3825-4643-917e-98f9d9f79b71";

            client.DefaultRequestHeaders.Add("Prediction-Key", "430e3360ff90462a8cf63000ec2d2b54");
            string url = "https://westcentralus.api.cognitive.microsoft.com/vision/v1.0/analyze?visualFeatures=Description&subscription-key=430e3360ff90462a8cf63000ec2d2b54";


            HttpResponseMessage response;

            byte[] byteData = GetImageAsByteArray(file);

            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                response = await client.PostAsync(url, content);


                if (response.IsSuccessStatusCode)
                {
                    var responseString = await response.Content.ReadAsStringAsync();

                    JObject rss = JObject.Parse(responseString);

                    var caption     = from p in rss["description"]["captions"] select(string) p["text"];
                    var captionToDB = "test";

                    foreach (var item in caption)
                    {
                        captionLabel.Text = item;
                        captionToDB       = item;
                    }

                    ImageSenseModel model = new ImageSenseModel()
                    {
                        Caption = captionToDB
                    };

                    await AzureManager.AzureManagerInstance.PostImageSenseInformation(model);
                }
            }


            file.Dispose();
        }
Exemple #2
0
 public async Task PostImageSenseInformation(ImageSenseModel imageSenseModel)
 {
     await this.ImageSenseTable.InsertAsync(imageSenseModel);
 }