Esempio n. 1
0
        static async Task TrainCustomModel(CustomFormClient client)
        {
            var source = "https://chstoneforms.blob.core.windows.net/samples?st=2020-03-09T01%3A13%3A09Z&se=2030-03-09T20%3A13%3A00Z&sp=rl&sv=2018-03-28&sr=c&sig=F4IO9V78SHJwdlURXD5%2Bdvk%2Bnv9OBqT0Sdu6xJgCtUk%3D";
            var poller = await client.StartTrainingAsync(source);

            Console.WriteLine($"Waiting for model {poller.Id}...");
            var resp = await poller.WaitForCompletionAsync(TimeSpan.FromSeconds(1));

            Console.WriteLine($"{resp.Value.ModelId} | {resp.Value.TrainingStatus.CreatedOn} | {resp.Value.TrainingStatus.LastUpdatedOn} | {resp.Value.TrainingStatus.ModelId} | {resp.Value.TrainingStatus.TrainingStatus}");
            foreach (var form in resp.Value.LearnedForms)
            {
                Console.WriteLine($"FormTypeId: {form.FormTypeId}");
                foreach (var field in form.LearnedFields)
                {
                    Console.WriteLine($"- {field}");
                }
            }
            foreach (var info in resp.Value.TrainingInfo.PerDocumentInfo)
            {
                Console.WriteLine($"{info.DocumentName} | {info.Pages} | {info.Status}");
                foreach (var error in info.Errors)
                {
                    Console.WriteLine($"{error.Code} | {error.Message}");
                }
            }
        }
Esempio n. 2
0
        // static async Task GetModel(CustomFormClient client)
        // {
        //     var modelId = "91c8da74-3bde-44e5-9fd4-3d8ae150c0bf";
        //     var resp = client.StartTrainingAsync()
        // }

        static async Task DeleteModel(CustomFormClient client)
        {
            var modelId = "51ee990c-bb72-49c5-a31f-3a7f62bfc40b";
            var resp    = await client.DeleteModelAsync(modelId);

            Console.WriteLine("Deleted.");
        }
Esempio n. 3
0
        static async Task GetCustomModelPage(CustomFormClient client)
        {
            var pages = client.GetModelsAsync().AsPages().GetAsyncEnumerator();
            await pages.MoveNextAsync();

            Console.WriteLine(pages.Current.ContinuationToken);
            Console.WriteLine(pages.Current.Values.Count);
        }
Esempio n. 4
0
        static async Task ListCustomModels(CustomFormClient client)
        {
            var models = client.GetModelsAsync();

            await foreach (var model in models)
            {
                Console.WriteLine($"{model.ModelId} | {model.TrainingStatus} | {model.CreatedOn} | {model.LastUpdatedOn}");
            }
        }
Esempio n. 5
0
        static async Task GetModelSummary(CustomFormClient client)
        {
            var resp = await client.GetModelSubscriptionPropertiesAsync();

            var result = resp.Value;

            Console.WriteLine($"Count: {result.Count}");
            Console.WriteLine($"Limit: {result.Limit}");
            Console.WriteLine($"LastUpdated: {result.LastUpdatedOn}");
        }
Esempio n. 6
0
        static async Task AnalyzeWithCustomModelWithLabels(CustomFormClient client)
        {
            var modelId  = "91c8da74-3bde-44e5-9fd4-3d8ae150c0bf";
            var filePath = @"C:\Users\ctsto\Downloads\sample_data\Test\Invoice_6.pdf";

            using var stream = File.OpenRead(filePath);
            var poller = await client.StartExtractFormAsync(modelId, stream, FormContentType.Pdf, true);

            await Analyze(poller);
        }
Esempio n. 7
0
        static async Task AnalyzeWithCustomModel(CustomFormClient client)
        {
            var modelId  = "a7f013f1-13f6-4594-b5a1-1e8b9e093520";
            var filePath = @"C:\Users\ctsto\Downloads\sample_data\Test\Invoice_6.pdf";

            using var stream = File.OpenRead(filePath);
            var poller = await client.StartExtractFormAsync(modelId, stream, FormContentType.Pdf, true);

            await Analyze(poller);
        }
Esempio n. 8
0
        static async Task TrainCustomModelWithLabels(CustomFormClient client)
        {
            var source = "https://chstoneforms.blob.core.windows.net/samples2?st=2020-03-09T09%3A59%3A50Z&se=2030-03-10T03%3A59%3A00Z&sp=rl&sv=2018-03-28&sr=c&sig=PCqzIFWNvRMRcbAlMIGeLJabElSZAelS21p8Cc48exs%3D";
            var poller = await client.StartTrainingWithLabelsAsync(source);

            Console.WriteLine($"Waiting for model {poller.Id}...");
            var resp = await poller.WaitForCompletionAsync(TimeSpan.FromSeconds(1));

            Console.WriteLine($"{resp.Value.ModelId} | {resp.Value.TrainingStatus.CreatedOn} | {resp.Value.TrainingStatus.LastUpdatedOn} | {resp.Value.TrainingStatus.ModelId} | {resp.Value.TrainingStatus.TrainingStatus} | {resp.Value.AverageLabelAccuracy}");
            foreach (var field in resp.Value.LabelAccuracies)
            {
                Console.WriteLine($"- {field.Label} - {field.Accuracy}");
            }
            foreach (var info in resp.Value.TrainingInfo.PerDocumentInfo)
            {
                Console.WriteLine($"- {info.DocumentName} | {info.Pages} | {info.Status}");
                foreach (var error in info.Errors)
                {
                    Console.WriteLine($"{error.Code} | {error.Message}");
                }
            }
        }
Esempio n. 9
0
        static async Task Main(string[] args)
        {
            var endpoint = Environment.GetEnvironmentVariable(EnvEndpoint) ?? throw new ArgumentNullException(EnvEndpoint);
            var key      = Environment.GetEnvironmentVariable(EnvApiKey) ?? throw new ArgumentNullException(EnvApiKey);

            var frEndpoint = new Uri(endpoint);
            var frKey      = new FormRecognizerApiKeyCredential(key);
            var frOptions  = new FormRecognizerClientOptions(ServiceVersion.V2_0_Preview);

            var custom   = new CustomFormClient(frEndpoint, frKey, frOptions);
            var receipts = new ReceiptClient(frEndpoint, frKey, frOptions);
            var layout   = new FormLayoutClient(frEndpoint, frKey, frOptions);

            // await TrainCustomModelWithLabels(custom);
            // await AnalyzeWithCustomModelWithLabels(custom);
            // await AnalyzeLayout(layout);
            // await AnalyzeReceipt(receipts);
            // await GetModelSummary(custom);
            // await DeleteModel(custom);

            await Task.CompletedTask;
        }