Example #1
0
        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();
        }
Example #2
0
        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));
        }