public static async Task AnalyzeFile(string option, string frService, string suscriptionKey) { if (option.Equals("1")) { var form = File.OpenRead("../../../../Shared/Samples/Form_1.jpg"); FormRecognizerService frClient = new FormRecognizerService(frService, suscriptionKey); Console.WriteLine("Introduzca el modelo de entrenamiento:"); var model = Console.ReadLine(); if (string.IsNullOrEmpty(model)) { var formContent = await frClient.AnalyzeFormFromStream(form); PrintForm(formContent); } else { var formContent = await frClient.AnalyzeCustomFormFromStream(form, model); PrintCustomForm(formContent); } } else { var receipt = File.OpenRead("../../../../Shared/Samples/contoso-allinone.jpg"); FormRecognizerService frClient = new FormRecognizerService(frService, suscriptionKey); var receiptContent = await frClient.AnalyzeReceiptFromStream(receipt); PrintReceipt(receiptContent); } Console.ReadLine(); }
public void OpenScenarioSetupForm(FormRecognizerService formRecognizerService) { this.hostGrid.Height = Window.Current.Bounds.Height; this.hostGrid.Width = Window.Current.Bounds.Width; this.formRecognizerService = formRecognizerService; this.newFormScenario.IsOpen = true; }
public static async Task TestFormRecognizerApiKeyAsync(string key, string apiEndpoint) { bool isUri = !string.IsNullOrEmpty(apiEndpoint) ? Uri.IsWellFormedUriString(apiEndpoint, UriKind.Absolute) : false; if (!isUri) { throw new ArgumentException("Invalid URI"); } else { var service = new FormRecognizerService(key, apiEndpoint); await service.GetCustomModelsAsync(); } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { bool enableFormRecognizerKeys = !string.IsNullOrEmpty(SettingsHelper.Instance.FormRecognizerApiKey) && !string.IsNullOrEmpty(SettingsHelper.Instance.FormRecognizerApiKeyEndpoint); this.newScenarioButton.IsEnabled = enableFormRecognizerKeys; if (enableFormRecognizerKeys) { this.formRecognizerService = new FormRecognizerService(SettingsHelper.Instance.FormRecognizerApiKey, SettingsHelper.Instance.FormRecognizerApiKeyEndpoint); await LoadModelsAsync(); } else { await new MessageDialog("Missing Form Recognizer Key. Please enter the key in the Settings page.", "Missing API Key").ShowAsync(); } base.OnNavigatedTo(e); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { bool enableFormRecognizerKeys = !string.IsNullOrEmpty(SettingsHelper.Instance.FormRecognizerApiKey) && !string.IsNullOrEmpty(SettingsHelper.Instance.FormRecognizerApiKeyEndpoint); bool enableCustomVisionKeys = !string.IsNullOrEmpty(SettingsHelper.Instance.CustomVisionTrainingApiKey) && !string.IsNullOrEmpty(SettingsHelper.Instance.CustomVisionPredictionApiKey) && !string.IsNullOrEmpty(SettingsHelper.Instance.CustomVisionPredictionResourceId); bool enableModelIds = FormRecognizerModelId != Guid.Empty && ObjectDetectionModelId != Guid.Empty && ObjectClassificationModelId != Guid.Empty; if (enableFormRecognizerKeys) { TempStorageFolder = await ApplicationData.Current.TemporaryFolder.CreateFolderAsync("InsuranceClaimAutomation", CreationCollisionOption.OpenIfExists); this.formRecognizerService = new FormRecognizerService(SettingsHelper.Instance.FormRecognizerApiKey, SettingsHelper.Instance.FormRecognizerApiKeyEndpoint); } if (enableCustomVisionKeys) { trainingApi = new CustomVisionTrainingClient(new Microsoft.Azure.CognitiveServices.Vision.CustomVision.Training.ApiKeyServiceClientCredentials(SettingsHelper.Instance.CustomVisionTrainingApiKey)) { Endpoint = SettingsHelper.Instance.CustomVisionTrainingApiKeyEndpoint }; predictionApi = new CustomVisionPredictionClient(new Microsoft.Azure.CognitiveServices.Vision.CustomVision.Prediction.ApiKeyServiceClientCredentials(SettingsHelper.Instance.CustomVisionPredictionApiKey)) { Endpoint = SettingsHelper.Instance.CustomVisionPredictionApiKeyEndpoint }; } if (!enableFormRecognizerKeys || !enableCustomVisionKeys || !enableModelIds) { this.mainPage.IsEnabled = false; await new MessageDialog("Please enter Custom Vision / Form Recognizer API Keys / Model Ids in the code behind of this demo.", "Missing API Keys").ShowAsync(); } else { this.mainPage.IsEnabled = true; await LoadDataGridCollectionAsync(); this.claimId = DataGridCollection.OrderByDescending(x => x.ClaimId).Select(x => x.ClaimId).FirstOrDefault(); } base.OnNavigatedTo(e); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { string fileName = req.Query["fileName"]; string model = req.Query["model"]; var container = Environment.GetEnvironmentVariable("BlobUrl"); var sass = Environment.GetEnvironmentVariable("Sassblob"); var file = await GetDocumentFromStorage(fileName, container, sass); var streamFile = new MemoryStream(file); var frService = Environment.GetEnvironmentVariable("FormRecognizerService"); var suscriptionKey = Environment.GetEnvironmentVariable("SuscriptionKeyForms"); FormRecognizerService frClient = new FormRecognizerService(frService, suscriptionKey); var dataForm = await frClient.AnalyzeCustomFormFromStream(streamFile, model); var mappingForm = MappingForm(dataForm.FirstOrDefault()); return(new OkObjectResult(mappingForm)); }
protected override async void OnNavigatedTo(NavigationEventArgs e) { bool enableFormRecognizerKeys = !string.IsNullOrEmpty(FormRecognizerApiKey) && !string.IsNullOrEmpty(FormRecognizerEndpoint); bool enableCustomVisionKeys = !string.IsNullOrEmpty(SettingsHelper.Instance.CustomVisionTrainingApiKey) && !string.IsNullOrEmpty(SettingsHelper.Instance.CustomVisionPredictionApiKey); if (enableFormRecognizerKeys) { TempStorageFolder = await ApplicationData.Current.TemporaryFolder.CreateFolderAsync("InsuranceClaimAutomation", CreationCollisionOption.OpenIfExists); this.formRecognizerService = new FormRecognizerService(FormRecognizerApiKey, FormRecognizerEndpoint); } if (enableCustomVisionKeys) { trainingApi = new CustomVisionTrainingClient { Endpoint = SettingsHelper.Instance.CustomVisionTrainingApiKeyEndpoint, ApiKey = SettingsHelper.Instance.CustomVisionTrainingApiKey }; predictionApi = new CustomVisionPredictionClient { Endpoint = SettingsHelper.Instance.CustomVisionPredictionApiKeyEndpoint, ApiKey = SettingsHelper.Instance.CustomVisionPredictionApiKey }; } if (!enableFormRecognizerKeys || !enableCustomVisionKeys) { this.mainPage.IsEnabled = false; await new MessageDialog("Please enter Custom Vision / Form Recognizer API Keys in the code behind of this demo.", "Missing API Keys").ShowAsync(); } else { this.mainPage.IsEnabled = true; await LoadDataGridCollectionAsync(); this.claimId = DataGridCollection.OrderByDescending(x => x.ClaimId).Select(x => x.ClaimId).FirstOrDefault(); } base.OnNavigatedTo(e); }