Beispiel #1
0
        internal async Task <PredictionRoot> MakePredictionUriAsync(string imageUri)
        {
            using (var rq = new HttpRequestMessage(HttpMethod.Post, _predictionImageUrl))
            {
                var rqObj = new PredictionUriRequest
                {
                    Url = imageUri
                };

                rq.Content = new StringContent(JsonConvert.SerializeObject(rqObj));
                rq.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

                var response = await _client.SendAsync(rq);

                _logger.LogInformation("prediction response {Status}", response.StatusCode);

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    _logger.LogError("Status code different from ok {StatusCode}", response.StatusCode);
                }

                PredictionRoot result = JsonConvert.DeserializeObject <PredictionRoot>(await response.Content.ReadAsStringAsync());

                return(result);
            }
        }
Beispiel #2
0
        internal async Task <PredictionRoot> MakePredictionAsync(byte[] imageBytes)
        {
            using (var rq = new HttpRequestMessage(HttpMethod.Post, _predictionImageFile))
            {
                rq.Content = new ByteArrayContent(imageBytes);
                rq.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

                var response = await _client.SendAsync(rq);

                _logger.LogInformation($"prediction response = {response.StatusCode}");

                if (response.StatusCode != HttpStatusCode.OK)
                {
                    _logger.LogError("Status code different from ok {StatusCode}", response.StatusCode);
                }

                PredictionRoot result =
                    JsonConvert.DeserializeObject <PredictionRoot>(await response.Content.ReadAsStringAsync());

                return(result);
            }
        }