private async void SearchBar_SearchButtonPressed(object sender, EventArgs e) { var ingredient = AzureManager.AzureManagerInstance.GetIngredient(); BarIndicator.IsVisible = true; List <recipeme123> ingredientInfo = await AzureManager.AzureManagerInstance.GetIngredientDetail(); await BarIndicator.ProgressTo(1, 80, Easing.Linear); IngredientList.ItemsSource = ingredientInfo.Where(p => String.Equals(p.MainIngredient.ToLower(), Search.Text.ToLower())).OrderBy(p => p.RecipeType); BarIndicator.IsVisible = false; BarIndicator.ProgressTo(0, 80, Easing.Linear); }
async Task MakePredictionRequest(MediaFile file) { var client = new HttpClient(); client.DefaultRequestHeaders.Add("Prediction-Key", "6b188bd282ac425a8e3755635c55f37e"); string url = "https://southcentralus.api.cognitive.microsoft.com/customvision/v1.0/Prediction/34669e80-95d0-4bc7-8062-1f1d94f76082/image?iterationId=a7ea51b3-732b-4588-b424-3a2b7af7c800"; 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(); EvaluationModel responseModel = JsonConvert.DeserializeObject <EvaluationModel>(responseString); var probability = responseModel.Predictions.OrderByDescending(probabilityH => probabilityH.Probability); var output_result = probability.Take(1).Single(); BarIndicator.IsVisible = true; if (output_result.Probability > 0.5) { TagLabel.Text = output_result.Tag; AzureManager.AzureManagerInstance.SetIngredient(output_result.Tag); await BarIndicator.ProgressTo(1, 80, Easing.Linear); BarIndicator.IsVisible = false; BarIndicator.ProgressTo(0, 80, Easing.Linear); Globals.exist = true; } else { await BarIndicator.ProgressTo(1, 80, Easing.Linear); TagLabel.Text = "Doesn't exist in the database"; BarIndicator.IsVisible = false; BarIndicator.ProgressTo(0, 80, Easing.Linear); } } file.Dispose(); } }
private async void IngredientHandler(object sender, EventArgs e) { if (Globals.checker == false) { await DisplayAlert("Error", "Please Take a picture first", "dismiss"); } else if (Globals.exist == true) { BarIndicator.IsVisible = true; var ingredient = AzureManager.AzureManagerInstance.GetIngredient(); List <recipeme123> ingredientInfo = await AzureManager.AzureManagerInstance.GetIngredientDetail(); await BarIndicator.ProgressTo(1, 80, Easing.Linear); IngredientList.ItemsSource = ingredientInfo.Where(p => String.Equals(p.MainIngredient.ToLower(), ingredient.ToLower())).OrderBy(p => p.RecipeType); BarIndicator.IsVisible = false; BarIndicator.ProgressTo(0, 80, Easing.Linear); } }