public async Task <IrisPlantPredicted[]> GetIrisPrediction(IrisPlantInput irisPlantInput) { using (var client = new HttpClient()) { var scoreRequest = new { Inputs = new Dictionary <string, List <Dictionary <string, string> > >() { { "input1", new List <Dictionary <string, string> >() { new Dictionary <string, string>() { { "Class", "1" }, { "sepal-length", irisPlantInput.SepalLength.ToString() }, { "sepal-width", irisPlantInput.SepalWidth.ToString() }, { "petal-length", irisPlantInput.PetalLength.ToString() }, { "petal-width", irisPlantInput.PetalWidth.ToString() }, } } }, }, GlobalParameters = new Dictionary <string, string>() { } }; var apiKey = _configuration["IrisApi:ApiKey"]; var baseUrl = _configuration["IrisApi:BaseAddress"]; client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey); client.BaseAddress = new Uri(baseUrl); HttpResponseMessage response = await client.PostAsJsonAsync("", scoreRequest); if (response.IsSuccessStatusCode) { string result = await response.Content.ReadAsStringAsync(); var objResult = JObject.Parse(result); return(JsonConvert.DeserializeObject <IrisPlantPredicted[]>(objResult["Results"]["output1"].ToString())); } return(new IrisPlantPredicted[0]); } }
public async Task <IActionResult> PredictIrisPlant(IrisPlantInput irisPlantInput) { if (!ModelState.IsValid) { return(BadRequest()); } var irisPlantPredicted = await _irisPredictionService.GetIrisPrediction(irisPlantInput); return(Json(irisPlantPredicted)); }
public IActionResult Index() { var model = new IrisPlantInput { SepalLength = 1D, SepalWidth = 1D, PetalLength = 1D, PetalWidth = 1D }; return(View(model)); }