diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/README.md b/sdk/formrecognizer/azure-ai-formrecognizer/samples/README.md index e42fbb22eb04..452b8212973e 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/README.md +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/README.md @@ -44,7 +44,7 @@ All of these samples need the endpoint to your Form Recognizer resource ([instru 1. Install the Azure Form Recognizer client library for Python with [pip][pip]: ```bash -pip install azure-ai-formrecognizer --pre +pip install azure-ai-formrecognizer ``` 2. Clone or download this sample repository diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_authentication_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_authentication_async.py index 3c266c69db27..7c359c9c3cfe 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_authentication_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_authentication_async.py @@ -28,7 +28,6 @@ 3) AZURE_CLIENT_ID - the client ID of your active directory application. 4) AZURE_TENANT_ID - the tenant ID of your active directory application. 5) AZURE_CLIENT_SECRET - the secret of your active directory application. - 6) AZURE_FORM_RECOGNIZER_AAD_ENDPOINT - the endpoint to your Form Recognizer resource for using AAD. """ import os @@ -60,7 +59,7 @@ async def authentication_with_azure_active_directory_form_recognizer_client_asyn from azure.ai.formrecognizer.aio import FormRecognizerClient from azure.identity.aio import DefaultAzureCredential - endpoint = os.environ["AZURE_FORM_RECOGNIZER_AAD_ENDPOINT"] + endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"] credential = DefaultAzureCredential() form_recognizer_client = FormRecognizerClient(endpoint, credential) @@ -89,7 +88,7 @@ async def authentication_with_azure_active_directory_form_training_client_async( from azure.ai.formrecognizer.aio import FormTrainingClient from azure.identity.aio import DefaultAzureCredential - endpoint = os.environ["AZURE_FORM_RECOGNIZER_AAD_ENDPOINT"] + endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"] credential = DefaultAzureCredential() form_training_client = FormTrainingClient(endpoint, credential) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_copy_model_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_copy_model_async.py index a57c569cf314..7425b6e84d41 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_copy_model_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_copy_model_async.py @@ -14,6 +14,9 @@ to a target Form Recognizer resource. The resource id and the resource region can be found in the azure portal. + The model used in this sample can be created in the sample_train_model_with_labels_async.py using the + training files in https://aka.ms/azsdk/formrecognizer/sampletrainingfiles + USAGE: python sample_copy_model_async.py @@ -23,6 +26,9 @@ 3) AZURE_FORM_RECOGNIZER_TARGET_ENDPOINT - the endpoint to your target Form Recognizer resource. 4) AZURE_FORM_RECOGNIZER_TARGET_KEY - your target Form Recognizer API key 5) AZURE_SOURCE_MODEL_ID - the model ID from the source resource to be copied over to the target resource. + - OR - + CONTAINER_SAS_URL - The shared access signature (SAS) Url of your Azure Blob Storage container with your forms. + A model will be trained and used to run the sample. 6) AZURE_FORM_RECOGNIZER_TARGET_REGION - the region the target resource was created in 7) AZURE_FORM_RECOGNIZER_TARGET_RESOURCE_ID - the entire resource ID to the target resource """ @@ -33,7 +39,7 @@ class CopyModelSampleAsync(object): - async def copy_model_async(self): + async def copy_model_async(self, custom_model_id): from azure.core.credentials import AzureKeyCredential from azure.ai.formrecognizer.aio import FormTrainingClient @@ -41,7 +47,7 @@ async def copy_model_async(self): source_key = os.environ["AZURE_FORM_RECOGNIZER_KEY"] target_endpoint = os.environ["AZURE_FORM_RECOGNIZER_TARGET_ENDPOINT"] target_key = os.environ["AZURE_FORM_RECOGNIZER_TARGET_KEY"] - source_model_id = os.environ["AZURE_SOURCE_MODEL_ID"] + source_model_id = os.getenv("AZURE_SOURCE_MODEL_ID", custom_model_id) target_region = os.environ["AZURE_FORM_RECOGNIZER_TARGET_REGION"] target_resource_id = os.environ["AZURE_FORM_RECOGNIZER_TARGET_RESOURCE_ID"] @@ -74,7 +80,27 @@ async def copy_model_async(self): async def main(): sample = CopyModelSampleAsync() - await sample.copy_model_async() + model_id = None + if os.getenv("CONTAINER_SAS_URL"): + + from azure.core.credentials import AzureKeyCredential + from azure.ai.formrecognizer.aio import FormTrainingClient + + endpoint = os.getenv("AZURE_FORM_RECOGNIZER_ENDPOINT") + key = os.getenv("AZURE_FORM_RECOGNIZER_KEY") + + if not endpoint or not key: + raise ValueError("Please provide endpoint and API key to run the samples.") + + form_training_client = FormTrainingClient( + endpoint=endpoint, credential=AzureKeyCredential(key) + ) + async with form_training_client: + model = await (await form_training_client.begin_training( + os.getenv("CONTAINER_SAS_URL"), use_training_labels=True)).result() + model_id = model.model_id + + await sample.copy_model_async(model_id) if __name__ == '__main__': diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_differentiate_output_labeled_tables_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_differentiate_output_labeled_tables_async.py index dc95cc9547f4..46a42ba128f3 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_differentiate_output_labeled_tables_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_differentiate_output_labeled_tables_async.py @@ -12,9 +12,8 @@ DESCRIPTION: This sample demonstrates the differences in output that arise when begin_recognize_custom_forms is called with custom models trained with fixed vs. dynamic table tags. - The models used in this sample can be created in the sample_train_model_with_labels.py using the - training files in - https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_forms/labeled_tables + The models used in this sample can be created in the sample_train_model_with_labels_async.py using the + training files in https://aka.ms/azsdk/formrecognizer/sampletabletrainingfiles Note that Form Recognizer automatically finds and extracts all tables in your documents whether the tables are tagged/labeled or not. Tables extracted automatically by Form Recognizer will be included in the @@ -30,7 +29,13 @@ 1) AZURE_FORM_RECOGNIZER_ENDPOINT - the endpoint to your Cognitive Services resource. 2) AZURE_FORM_RECOGNIZER_KEY - your Form Recognizer API key 3) MODEL_ID_FIXED_ROW_TABLES - the ID of your custom model trained with labels on fixed row tables + -OR- + CONTAINER_SAS_URL_FIXED - The shared access signature (SAS) Url of your Azure Blob Storage container with + your labeled data containing a fixed row table. A model will be trained and used to run the sample. 4) MODEL_ID_DYNAMIC_ROW_TABLES - the ID of your custom model trained with labels on dynamic row tables + -OR- + CONTAINER_SAS_URL_DYNAMIC - The shared access signature (SAS) Url of your Azure Blob Storage container with + your labeled data containing a dynamic row table. A model will be trained and used to run the sample. """ import os @@ -39,13 +44,13 @@ class TestDifferentiateOutputLabeledTablesAsync(object): - async def test_recognize_tables_fixed_rows_async(self): + async def test_recognize_tables_fixed_rows_async(self, custom_model_id): from azure.core.credentials import AzureKeyCredential from azure.ai.formrecognizer.aio import FormRecognizerClient endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"] key = os.environ["AZURE_FORM_RECOGNIZER_KEY"] - model_id_fixed_rows_table = os.environ["MODEL_ID_FIXED_ROW_TABLES"] + model_id_fixed_rows_table = os.getenv("MODEL_ID_FIXED_ROW_TABLES", custom_model_id) form_recognizer_client = FormRecognizerClient( endpoint=endpoint, credential=AzureKeyCredential(key) @@ -82,13 +87,13 @@ async def test_recognize_tables_fixed_rows_async(self): field.confidence )) - async def test_recognize_tables_dynamic_rows_async(self): + async def test_recognize_tables_dynamic_rows_async(self, custom_model_id): from azure.core.credentials import AzureKeyCredential from azure.ai.formrecognizer.aio import FormRecognizerClient endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"] key = os.environ["AZURE_FORM_RECOGNIZER_KEY"] - model_id_dynamic_rows_table = os.environ["MODEL_ID_DYNAMIC_ROW_TABLES"] + model_id_dynamic_rows_table = os.getenv("MODEL_ID_DYNAMIC_ROW_TABLES", custom_model_id) form_recognizer_client = FormRecognizerClient( endpoint=endpoint, credential=AzureKeyCredential(key) @@ -128,8 +133,35 @@ async def test_recognize_tables_dynamic_rows_async(self): async def main(): sample = TestDifferentiateOutputLabeledTablesAsync() - await sample.test_recognize_tables_fixed_rows_async() - await sample.test_recognize_tables_dynamic_rows_async() + fixed_model_id = None + dynamic_model_id = None + if os.getenv("CONTAINER_SAS_URL_FIXED") or os.getenv("CONTAINER_SAS_URL_DYNAMIC"): + + from azure.core.credentials import AzureKeyCredential + from azure.ai.formrecognizer.aio import FormTrainingClient + + endpoint = os.getenv("AZURE_FORM_RECOGNIZER_ENDPOINT") + key = os.getenv("AZURE_FORM_RECOGNIZER_KEY") + fixed = os.getenv("CONTAINER_SAS_URL_FIXED") + dynamic = os.getenv("CONTAINER_SAS_URL_DYNAMIC") + + if not endpoint or not key: + raise ValueError("Please provide endpoint and API key to run the samples.") + + form_training_client = FormTrainingClient( + endpoint=endpoint, credential=AzureKeyCredential(key) + ) + + async with form_training_client: + if fixed: + model = await (await form_training_client.begin_training(fixed, use_training_labels=True)).result() + fixed_model_id = model.model_id + if dynamic: + model = await (await form_training_client.begin_training(dynamic, use_training_labels=True)).result() + dynamic_model_id = model.model_id + + await sample.test_recognize_tables_fixed_rows_async(fixed_model_id) + await sample.test_recognize_tables_dynamic_rows_async(dynamic_model_id) if __name__ == '__main__': diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_differentiate_output_models_trained_with_and_without_labels_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_differentiate_output_models_trained_with_and_without_labels_async.py index 9274de07b965..7d77d2398b4d 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_differentiate_output_models_trained_with_and_without_labels_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_differentiate_output_models_trained_with_and_without_labels_async.py @@ -13,6 +13,7 @@ This sample demonstrates the differences in output that arise when begin_recognize_custom_forms is called with custom models trained with labels and without labels. The models used in this sample can be created in sample_train_model_with_labels_async.py and sample_train_model_without_labels_async.py + using the training files found here: https://aka.ms/azsdk/formrecognizer/sampletrainingfiles For a more general example of recognizing custom forms, see sample_recognize_custom_forms_async.py @@ -26,7 +27,13 @@ 1) AZURE_FORM_RECOGNIZER_ENDPOINT - the endpoint to your Cognitive Services resource. 2) AZURE_FORM_RECOGNIZER_KEY - your Form Recognizer API key 3) ID_OF_MODEL_TRAINED_WITH_LABELS - the ID of your custom model trained with labels + -OR- + CONTAINER_SAS_URL_WITH_LABELS - The shared access signature (SAS) Url of your Azure Blob Storage container with + your labeled data. A model will be trained and used to run the sample. 4) ID_OF_MODEL_TRAINED_WITHOUT_LABELS - the ID of your custom model trained without labels + -OR- + CONTAINER_SAS_URL_WITHOUT_LABELS - The shared access signature (SAS) Url of your Azure Blob Storage container with + your forms. A model will be trained and used to run the sample. """ import os @@ -41,14 +48,14 @@ def format_bounding_box(bounding_box): class DifferentiateOutputModelsTrainedWithAndWithoutLabelsSampleAsync(object): - async def recognize_custom_forms(self): + async def recognize_custom_forms(self, labeled_model_id, unlabeled_model_id): from azure.core.credentials import AzureKeyCredential from azure.ai.formrecognizer.aio import FormRecognizerClient endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"] key = os.environ["AZURE_FORM_RECOGNIZER_KEY"] - model_trained_with_labels_id = os.environ["ID_OF_MODEL_TRAINED_WITH_LABELS"] - model_trained_without_labels_id = os.environ["ID_OF_MODEL_TRAINED_WITHOUT_LABELS"] + model_trained_with_labels_id = os.getenv("ID_OF_MODEL_TRAINED_WITH_LABELS", labeled_model_id) + model_trained_without_labels_id = os.getenv("ID_OF_MODEL_TRAINED_WITHOUT_LABELS", unlabeled_model_id) path_to_sample_forms = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", "./sample_forms/forms/Form_1.jpg")) async with FormRecognizerClient( @@ -120,7 +127,34 @@ async def recognize_custom_forms(self): async def main(): sample = DifferentiateOutputModelsTrainedWithAndWithoutLabelsSampleAsync() - await sample.recognize_custom_forms() + labeled_model_id = None + unlabeled_model_id = None + if os.getenv("CONTAINER_SAS_URL_WITH_LABELS") or os.getenv("CONTAINER_SAS_URL_WITHOUT_LABELS"): + + from azure.core.credentials import AzureKeyCredential + from azure.ai.formrecognizer.aio import FormTrainingClient + + endpoint = os.getenv("AZURE_FORM_RECOGNIZER_ENDPOINT") + key = os.getenv("AZURE_FORM_RECOGNIZER_KEY") + labeled = os.getenv("CONTAINER_SAS_URL_WITH_LABELS") + unlabeled = os.getenv("CONTAINER_SAS_URL_WITHOUT_LABELS") + + if not endpoint or not key: + raise ValueError("Please provide endpoint and API key to run the samples.") + + form_training_client = FormTrainingClient( + endpoint=endpoint, credential=AzureKeyCredential(key) + ) + + async with form_training_client: + if labeled: + model = await (await form_training_client.begin_training(labeled, use_training_labels=True)).result() + labeled_model_id = model.model_id + if unlabeled: + model = await (await form_training_client.begin_training(unlabeled, use_training_labels=False)).result() + unlabeled_model_id = model.model_id + + await sample.recognize_custom_forms(labeled_model_id, unlabeled_model_id) if __name__ == '__main__': diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_get_bounding_boxes_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_get_bounding_boxes_async.py index addaaeca5b8e..c16b01cc62dd 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_get_bounding_boxes_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_get_bounding_boxes_async.py @@ -12,6 +12,10 @@ DESCRIPTION: This sample demonstrates how to get detailed information to visualize the outlines of form content and fields, which can be used for manual validation and drawing UI as part of an application. + + The model used in this sample can be created in the sample_train_model_without_labels_async.py using the + training files in https://aka.ms/azsdk/formrecognizer/sampletrainingfiles + USAGE: python sample_get_bounding_boxes_async.py @@ -19,6 +23,9 @@ 1) AZURE_FORM_RECOGNIZER_ENDPOINT - the endpoint to your Cognitive Services resource. 2) AZURE_FORM_RECOGNIZER_KEY - your Form Recognizer API key 3) CUSTOM_TRAINED_MODEL_ID - the ID of your custom trained model + -OR- + CONTAINER_SAS_URL - The shared access signature (SAS) Url of your Azure Blob Storage container with your forms. + A model will be trained and used to run the sample. """ import os @@ -35,13 +42,13 @@ def format_bounding_box(bounding_box): class GetBoundingBoxesSampleAsync(object): - async def get_bounding_boxes(self): + async def get_bounding_boxes(self, custom_model_id): from azure.core.credentials import AzureKeyCredential from azure.ai.formrecognizer.aio import FormRecognizerClient endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"] key = os.environ["AZURE_FORM_RECOGNIZER_KEY"] - model_id = os.environ["CUSTOM_TRAINED_MODEL_ID"] + model_id = os.getenv("CUSTOM_TRAINED_MODEL_ID", custom_model_id) form_recognizer_client = FormRecognizerClient( endpoint=endpoint, credential=AzureKeyCredential(key) @@ -115,7 +122,26 @@ async def get_bounding_boxes(self): async def main(): sample = GetBoundingBoxesSampleAsync() - await sample.get_bounding_boxes() + model_id = None + if os.getenv("CONTAINER_SAS_URL"): + + from azure.core.credentials import AzureKeyCredential + from azure.ai.formrecognizer.aio import FormTrainingClient + + endpoint = os.getenv("AZURE_FORM_RECOGNIZER_ENDPOINT") + key = os.getenv("AZURE_FORM_RECOGNIZER_KEY") + + if not endpoint or not key: + raise ValueError("Please provide endpoint and API key to run the samples.") + + form_training_client = FormTrainingClient( + endpoint=endpoint, credential=AzureKeyCredential(key) + ) + async with form_training_client: + model = await (await form_training_client.begin_training( + os.getenv("CONTAINER_SAS_URL"), use_training_labels=False)).result() + model_id = model.model_id + await sample.get_bounding_boxes(model_id) if __name__ == '__main__': diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_recognize_custom_forms_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_recognize_custom_forms_async.py index ab653906c9d8..86921c05620f 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_recognize_custom_forms_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_recognize_custom_forms_async.py @@ -15,6 +15,9 @@ was trained on. To learn how to train your own models, look at sample_train_model_without_labels_async.py and sample_train_model_with_labels_async.py + The model can be trained using the training files found here: + https://aka.ms/azsdk/formrecognizer/sampletrainingfiles + USAGE: python sample_recognize_custom_forms_async.py @@ -22,6 +25,9 @@ 1) AZURE_FORM_RECOGNIZER_ENDPOINT - the endpoint to your Cognitive Services resource. 2) AZURE_FORM_RECOGNIZER_KEY - your Form Recognizer API key 3) CUSTOM_TRAINED_MODEL_ID - the ID of your custom trained model + -OR- + CONTAINER_SAS_URL - The shared access signature (SAS) Url of your Azure Blob Storage container with your forms. + A model will be trained and used to run the sample. """ import os @@ -30,7 +36,7 @@ class RecognizeCustomFormsSampleAsync(object): - async def recognize_custom_forms(self): + async def recognize_custom_forms(self, custom_model_id): path_to_sample_forms = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", "./sample_forms/forms/Form_1.jpg")) # [START recognize_custom_forms_async] @@ -39,7 +45,7 @@ async def recognize_custom_forms(self): endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"] key = os.environ["AZURE_FORM_RECOGNIZER_KEY"] - model_id = os.environ["CUSTOM_TRAINED_MODEL_ID"] + model_id = os.getenv("CUSTOM_TRAINED_MODEL_ID", custom_model_id) async with FormRecognizerClient( endpoint=endpoint, credential=AzureKeyCredential(key) @@ -102,7 +108,27 @@ async def recognize_custom_forms(self): async def main(): sample = RecognizeCustomFormsSampleAsync() - await sample.recognize_custom_forms() + model_id = None + if os.getenv("CONTAINER_SAS_URL"): + + from azure.core.credentials import AzureKeyCredential + from azure.ai.formrecognizer.aio import FormTrainingClient + + endpoint = os.getenv("AZURE_FORM_RECOGNIZER_ENDPOINT") + key = os.getenv("AZURE_FORM_RECOGNIZER_KEY") + + if not endpoint or not key: + raise ValueError("Please provide endpoint and API key to run the samples.") + + form_training_client = FormTrainingClient( + endpoint=endpoint, credential=AzureKeyCredential(key) + ) + async with form_training_client: + model = await (await form_training_client.begin_training( + os.getenv("CONTAINER_SAS_URL"), use_training_labels=True)).result() + model_id = model.model_id + + await sample.recognize_custom_forms(model_id) if __name__ == '__main__': diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_train_model_with_labels_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_train_model_with_labels_async.py index f406535ee349..0d69c2d90a44 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_train_model_with_labels_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_train_model_with_labels_async.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to train a model with labels. For this sample, you can use the training - forms found in https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_forms/training + forms found in https://aka.ms/azsdk/formrecognizer/sampletrainingfiles Upload the forms to your storage container and then generate a container SAS URL using these instructions: https://docs.microsoft.com/azure/cognitive-services/form-recognizer/quickstarts/python-labeled-data#train-a-model-using-labeled-data diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_train_model_without_labels_async.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_train_model_without_labels_async.py index 8e993ec9ac66..a442589cfe94 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_train_model_without_labels_async.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/async_samples/sample_train_model_without_labels_async.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to train a model with unlabeled data. For this sample, you can use the training - forms found in https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_forms/training + forms found in https://aka.ms/azsdk/formrecognizer/sampletrainingfiles Upload the forms to your storage container and then generate a container SAS URL using these instructions: https://docs.microsoft.com/azure/cognitive-services/form-recognizer/quickstarts/python-labeled-data#train-a-model-using-labeled-data diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_authentication.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_authentication.py index ee21ddcec43c..15fc7e864c74 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_authentication.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_authentication.py @@ -28,7 +28,6 @@ 3) AZURE_CLIENT_ID - the client ID of your active directory application. 4) AZURE_TENANT_ID - the tenant ID of your active directory application. 5) AZURE_CLIENT_SECRET - the secret of your active directory application. - 6) AZURE_FORM_RECOGNIZER_AAD_ENDPOINT - the endpoint to your Form Recognizer resource for using AAD. """ import os @@ -58,7 +57,7 @@ def authentication_with_azure_active_directory_form_recognizer_client(self): from azure.ai.formrecognizer import FormRecognizerClient from azure.identity import DefaultAzureCredential - endpoint = os.environ["AZURE_FORM_RECOGNIZER_AAD_ENDPOINT"] + endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"] credential = DefaultAzureCredential() form_recognizer_client = FormRecognizerClient(endpoint, credential) @@ -85,7 +84,7 @@ def authentication_with_azure_active_directory_form_training_client(self): from azure.ai.formrecognizer import FormTrainingClient from azure.identity import DefaultAzureCredential - endpoint = os.environ["AZURE_FORM_RECOGNIZER_AAD_ENDPOINT"] + endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"] credential = DefaultAzureCredential() form_training_client = FormTrainingClient(endpoint, credential) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_copy_model.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_copy_model.py index 5abae79870b7..5f00ee53abfc 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_copy_model.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_copy_model.py @@ -14,6 +14,9 @@ to a target Form Recognizer resource. The resource id and the resource region can be found in the azure portal. + The model used in this sample can be created in the sample_train_model_with_labels.py using the + training files in https://aka.ms/azsdk/formrecognizer/sampletrainingfiles + USAGE: python sample_copy_model.py @@ -23,6 +26,9 @@ 3) AZURE_FORM_RECOGNIZER_TARGET_ENDPOINT - the endpoint to your target Form Recognizer resource. 4) AZURE_FORM_RECOGNIZER_TARGET_KEY - your target Form Recognizer API key 5) AZURE_SOURCE_MODEL_ID - the model ID from the source resource to be copied over to the target resource. + - OR - + CONTAINER_SAS_URL - The shared access signature (SAS) Url of your Azure Blob Storage container with your forms. + A model will be trained and used to run the sample. 6) AZURE_FORM_RECOGNIZER_TARGET_REGION - the region the target resource was created in 7) AZURE_FORM_RECOGNIZER_TARGET_RESOURCE_ID - the entire resource ID to the target resource """ @@ -32,7 +38,7 @@ class CopyModelSample(object): - def copy_model(self): + def copy_model(self, custom_model_id): from azure.core.credentials import AzureKeyCredential from azure.ai.formrecognizer import FormTrainingClient @@ -40,7 +46,7 @@ def copy_model(self): source_key = os.environ["AZURE_FORM_RECOGNIZER_KEY"] target_endpoint = os.environ["AZURE_FORM_RECOGNIZER_TARGET_ENDPOINT"] target_key = os.environ["AZURE_FORM_RECOGNIZER_TARGET_KEY"] - source_model_id = os.environ["AZURE_SOURCE_MODEL_ID"] + source_model_id = os.getenv("AZURE_SOURCE_MODEL_ID", custom_model_id) target_region = os.environ["AZURE_FORM_RECOGNIZER_TARGET_REGION"] target_resource_id = os.environ["AZURE_FORM_RECOGNIZER_TARGET_RESOURCE_ID"] @@ -71,4 +77,22 @@ def copy_model(self): if __name__ == '__main__': sample = CopyModelSample() - sample.copy_model() + model_id = None + if os.getenv("CONTAINER_SAS_URL"): + + from azure.core.credentials import AzureKeyCredential + from azure.ai.formrecognizer import FormTrainingClient + + endpoint = os.getenv("AZURE_FORM_RECOGNIZER_ENDPOINT") + key = os.getenv("AZURE_FORM_RECOGNIZER_KEY") + + if not endpoint or not key: + raise ValueError("Please provide endpoint and API key to run the samples.") + + form_training_client = FormTrainingClient( + endpoint=endpoint, credential=AzureKeyCredential(key) + ) + model = form_training_client.begin_training(os.getenv("CONTAINER_SAS_URL"), use_training_labels=True).result() + model_id = model.model_id + + sample.copy_model(model_id) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_differentiate_output_labeled_tables.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_differentiate_output_labeled_tables.py index 5513ca092849..beab3be62f58 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_differentiate_output_labeled_tables.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_differentiate_output_labeled_tables.py @@ -13,8 +13,7 @@ This sample demonstrates the differences in output that arise when begin_recognize_custom_forms is called with custom models trained with fixed vs. dynamic table tags. The models used in this sample can be created in the sample_train_model_with_labels.py using the - training files in - https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_forms/labeled_tables + training files in https://aka.ms/azsdk/formrecognizer/sampletabletrainingfiles Note that Form Recognizer automatically finds and extracts all tables in your documents whether the tables are tagged/labeled or not. Tables extracted automatically by Form Recognizer will be included in the @@ -30,7 +29,13 @@ 1) AZURE_FORM_RECOGNIZER_ENDPOINT - the endpoint to your Cognitive Services resource. 2) AZURE_FORM_RECOGNIZER_KEY - your Form Recognizer API key 3) MODEL_ID_FIXED_ROW_TABLES - the ID of your custom model trained with labels on fixed row tables + -OR- + CONTAINER_SAS_URL_FIXED - The shared access signature (SAS) Url of your Azure Blob Storage container with + your labeled data containing a fixed row table. A model will be trained and used to run the sample. 4) MODEL_ID_DYNAMIC_ROW_TABLES - the ID of your custom model trained with labels on dynamic row tables + -OR- + CONTAINER_SAS_URL_DYNAMIC - The shared access signature (SAS) Url of your Azure Blob Storage container with + your labeled data containing a dynamic row table. A model will be trained and used to run the sample. """ import os @@ -38,13 +43,13 @@ class TestDifferentiateOutputLabeledTables(object): - def test_recognize_tables_fixed_rows(self): + def test_recognize_tables_fixed_rows(self, custom_model_id): from azure.core.credentials import AzureKeyCredential from azure.ai.formrecognizer import FormRecognizerClient endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"] key = os.environ["AZURE_FORM_RECOGNIZER_KEY"] - model_id_fixed_rows_table = os.environ["MODEL_ID_FIXED_ROW_TABLES"] + model_id_fixed_rows_table = os.getenv("MODEL_ID_FIXED_ROW_TABLES", custom_model_id) form_recognizer_client = FormRecognizerClient( endpoint=endpoint, credential=AzureKeyCredential(key) @@ -80,13 +85,13 @@ def test_recognize_tables_fixed_rows(self): field.confidence )) - def test_recognize_tables_dynamic_rows(self): + def test_recognize_tables_dynamic_rows(self, custom_model_id): from azure.core.credentials import AzureKeyCredential from azure.ai.formrecognizer import FormRecognizerClient endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"] key = os.environ["AZURE_FORM_RECOGNIZER_KEY"] - model_id_dynamic_rows_table = os.environ["MODEL_ID_DYNAMIC_ROW_TABLES"] + model_id_dynamic_rows_table = os.getenv("MODEL_ID_DYNAMIC_ROW_TABLES", custom_model_id) form_recognizer_client = FormRecognizerClient( endpoint=endpoint, credential=AzureKeyCredential(key) @@ -125,5 +130,31 @@ def test_recognize_tables_dynamic_rows(self): if __name__ == '__main__': sample = TestDifferentiateOutputLabeledTables() - sample.test_recognize_tables_fixed_rows() - sample.test_recognize_tables_dynamic_rows() + fixed_model_id = None + dynamic_model_id = None + if os.getenv("CONTAINER_SAS_URL_FIXED") or os.getenv("CONTAINER_SAS_URL_DYNAMIC"): + + from azure.core.credentials import AzureKeyCredential + from azure.ai.formrecognizer import FormTrainingClient + + endpoint = os.getenv("AZURE_FORM_RECOGNIZER_ENDPOINT") + key = os.getenv("AZURE_FORM_RECOGNIZER_KEY") + fixed = os.getenv("CONTAINER_SAS_URL_FIXED") + dynamic = os.getenv("CONTAINER_SAS_URL_DYNAMIC") + + if not endpoint or not key: + raise ValueError("Please provide endpoint and API key to run the samples.") + + form_training_client = FormTrainingClient( + endpoint=endpoint, credential=AzureKeyCredential(key) + ) + + if fixed: + model = form_training_client.begin_training(fixed, use_training_labels=True).result() + fixed_model_id = model.model_id + if dynamic: + model = form_training_client.begin_training(dynamic, use_training_labels=True).result() + dynamic_model_id = model.model_id + + sample.test_recognize_tables_fixed_rows(fixed_model_id) + sample.test_recognize_tables_dynamic_rows(dynamic_model_id) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_differentiate_output_models_trained_with_and_without_labels.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_differentiate_output_models_trained_with_and_without_labels.py index 87e2a8778511..c295744b7159 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_differentiate_output_models_trained_with_and_without_labels.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_differentiate_output_models_trained_with_and_without_labels.py @@ -13,6 +13,7 @@ This sample demonstrates the differences in output that arise when begin_recognize_custom_forms is called with custom models trained with labeled and unlabeled data. The models used in this sample can be created in sample_train_model_with_labels.py and sample_train_model_without_labels.py + using the training files found here: https://aka.ms/azsdk/formrecognizer/sampletrainingfiles For a more general example of recognizing custom forms, see sample_recognize_custom_forms.py @@ -26,7 +27,13 @@ 1) AZURE_FORM_RECOGNIZER_ENDPOINT - the endpoint to your Cognitive Services resource. 2) AZURE_FORM_RECOGNIZER_KEY - your Form Recognizer API key 3) ID_OF_MODEL_TRAINED_WITH_LABELS - the ID of your custom model trained with labels + -OR- + CONTAINER_SAS_URL_WITH_LABELS - The shared access signature (SAS) Url of your Azure Blob Storage container + with your labeled data. A model will be trained and used to run the sample. 4) ID_OF_MODEL_TRAINED_WITHOUT_LABELS - the ID of your custom model trained without labels + -OR- + CONTAINER_SAS_URL_WITHOUT_LABELS - The shared access signature (SAS) Url of your Azure Blob Storage container + with your forms. A model will be trained and used to run the sample. """ import os @@ -39,14 +46,14 @@ def format_bounding_box(bounding_box): class DifferentiateOutputModelsTrainedWithAndWithoutLabels(object): - def recognize_custom_forms(self): + def recognize_custom_forms(self, labeled_model_id, unlabeled_model_id): from azure.core.credentials import AzureKeyCredential from azure.ai.formrecognizer import FormRecognizerClient endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"] key = os.environ["AZURE_FORM_RECOGNIZER_KEY"] - model_trained_with_labels_id = os.environ["ID_OF_MODEL_TRAINED_WITH_LABELS"] - model_trained_without_labels_id = os.environ["ID_OF_MODEL_TRAINED_WITHOUT_LABELS"] + model_trained_with_labels_id = os.getenv("ID_OF_MODEL_TRAINED_WITH_LABELS", labeled_model_id) + model_trained_without_labels_id = os.getenv("ID_OF_MODEL_TRAINED_WITHOUT_LABELS", unlabeled_model_id) form_recognizer_client = FormRecognizerClient( endpoint=endpoint, credential=AzureKeyCredential(key) @@ -120,4 +127,30 @@ def recognize_custom_forms(self): if __name__ == '__main__': sample = DifferentiateOutputModelsTrainedWithAndWithoutLabels() - sample.recognize_custom_forms() + labeled_model_id = None + unlabeled_model_id = None + if os.getenv("CONTAINER_SAS_URL_WITH_LABELS") or os.getenv("CONTAINER_SAS_URL_WITHOUT_LABELS"): + + from azure.core.credentials import AzureKeyCredential + from azure.ai.formrecognizer import FormTrainingClient + + endpoint = os.getenv("AZURE_FORM_RECOGNIZER_ENDPOINT") + key = os.getenv("AZURE_FORM_RECOGNIZER_KEY") + labeled = os.getenv("CONTAINER_SAS_URL_WITH_LABELS") + unlabeled = os.getenv("CONTAINER_SAS_URL_WITHOUT_LABELS") + + if not endpoint or not key: + raise ValueError("Please provide endpoint and API key to run the samples.") + + form_training_client = FormTrainingClient( + endpoint=endpoint, credential=AzureKeyCredential(key) + ) + + if labeled: + model = form_training_client.begin_training(labeled, use_training_labels=True).result() + labeled_model_id = model.model_id + if unlabeled: + model = form_training_client.begin_training(unlabeled, use_training_labels=False).result() + unlabeled_model_id = model.model_id + + sample.recognize_custom_forms(labeled_model_id, unlabeled_model_id) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_get_bounding_boxes.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_get_bounding_boxes.py index 46d819ca62be..cec27723dd70 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_get_bounding_boxes.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_get_bounding_boxes.py @@ -12,6 +12,10 @@ DESCRIPTION: This sample demonstrates how to get detailed information to visualize the outlines of form content and fields, which can be used for manual validation and drawing UI as part of an application. + + The model used in this sample can be created in the sample_train_model_without_labels.py using the + training files in https://aka.ms/azsdk/formrecognizer/sampletrainingfiles + USAGE: python sample_get_bounding_boxes.py @@ -19,6 +23,9 @@ 1) AZURE_FORM_RECOGNIZER_ENDPOINT - the endpoint to your Cognitive Services resource. 2) AZURE_FORM_RECOGNIZER_KEY - your Form Recognizer API key 3) CUSTOM_TRAINED_MODEL_ID - the ID of your custom trained model + -OR- + CONTAINER_SAS_URL - The shared access signature (SAS) Url of your Azure Blob Storage container with your forms. + A model will be trained and used to run the sample. """ import os @@ -34,13 +41,13 @@ def format_bounding_box(bounding_box): class GetBoundingBoxesSample(object): - def get_bounding_boxes(self): + def get_bounding_boxes(self, custom_model_id): from azure.core.credentials import AzureKeyCredential from azure.ai.formrecognizer import FormRecognizerClient endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"] key = os.environ["AZURE_FORM_RECOGNIZER_KEY"] - model_id = os.environ["CUSTOM_TRAINED_MODEL_ID"] + model_id = os.getenv("CUSTOM_TRAINED_MODEL_ID", custom_model_id) form_recognizer_client = FormRecognizerClient( endpoint=endpoint, credential=AzureKeyCredential(key) @@ -111,4 +118,22 @@ def get_bounding_boxes(self): if __name__ == '__main__': sample = GetBoundingBoxesSample() - sample.get_bounding_boxes() + model_id = None + if os.getenv("CONTAINER_SAS_URL"): + + from azure.core.credentials import AzureKeyCredential + from azure.ai.formrecognizer import FormTrainingClient + + endpoint = os.getenv("AZURE_FORM_RECOGNIZER_ENDPOINT") + key = os.getenv("AZURE_FORM_RECOGNIZER_KEY") + + if not endpoint or not key: + raise ValueError("Please provide endpoint and API key to run the samples.") + + form_training_client = FormTrainingClient( + endpoint=endpoint, credential=AzureKeyCredential(key) + ) + model = form_training_client.begin_training(os.getenv("CONTAINER_SAS_URL"), use_training_labels=False).result() + model_id = model.model_id + + sample.get_bounding_boxes(model_id) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_custom_forms.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_custom_forms.py index 1d69d8037ae9..2fc286c1e7b2 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_custom_forms.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_recognize_custom_forms.py @@ -15,6 +15,9 @@ was trained on. To learn how to train your own models, look at sample_train_model_without_labels.py and sample_train_model_with_labels.py + The model can be trained using the training files found here: + https://aka.ms/azsdk/formrecognizer/sampletrainingfiles + USAGE: python sample_recognize_custom_forms.py @@ -22,6 +25,9 @@ 1) AZURE_FORM_RECOGNIZER_ENDPOINT - the endpoint to your Cognitive Services resource. 2) AZURE_FORM_RECOGNIZER_KEY - your Form Recognizer API key 3) CUSTOM_TRAINED_MODEL_ID - the ID of your custom trained model + -OR- + CONTAINER_SAS_URL - The shared access signature (SAS) Url of your Azure Blob Storage container with your forms. + A model will be trained and used to run the sample. """ import os @@ -29,7 +35,7 @@ class RecognizeCustomForms(object): - def recognize_custom_forms(self): + def recognize_custom_forms(self, custom_model_id): path_to_sample_forms = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "./sample_forms/forms/Form_1.jpg")) # [START recognize_custom_forms] @@ -38,7 +44,7 @@ def recognize_custom_forms(self): endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"] key = os.environ["AZURE_FORM_RECOGNIZER_KEY"] - model_id = os.environ["CUSTOM_TRAINED_MODEL_ID"] + model_id = os.getenv("CUSTOM_TRAINED_MODEL_ID", custom_model_id) form_recognizer_client = FormRecognizerClient( endpoint=endpoint, credential=AzureKeyCredential(key) @@ -101,4 +107,22 @@ def recognize_custom_forms(self): if __name__ == '__main__': sample = RecognizeCustomForms() - sample.recognize_custom_forms() + model_id = None + if os.getenv("CONTAINER_SAS_URL"): + + from azure.core.credentials import AzureKeyCredential + from azure.ai.formrecognizer import FormTrainingClient + + endpoint = os.getenv("AZURE_FORM_RECOGNIZER_ENDPOINT") + key = os.getenv("AZURE_FORM_RECOGNIZER_KEY") + + if not endpoint or not key: + raise ValueError("Please provide endpoint and API key to run the samples.") + + form_training_client = FormTrainingClient( + endpoint=endpoint, credential=AzureKeyCredential(key) + ) + model = form_training_client.begin_training(os.getenv("CONTAINER_SAS_URL"), use_training_labels=True).result() + model_id = model.model_id + + sample.recognize_custom_forms(model_id) diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_train_model_with_labels.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_train_model_with_labels.py index 44a31ae8ab9f..d009a73a1534 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_train_model_with_labels.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_train_model_with_labels.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to train a model with labels. For this sample, you can use the training - forms found in https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_forms/training + forms found in https://aka.ms/azsdk/formrecognizer/sampletrainingfiles Upload the forms to your storage container and then generate a container SAS URL using these instructions: https://docs.microsoft.com/azure/cognitive-services/form-recognizer/quickstarts/python-labeled-data#train-a-model-using-labeled-data diff --git a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_train_model_without_labels.py b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_train_model_without_labels.py index 2a993a03dd3f..cc566be6e51a 100644 --- a/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_train_model_without_labels.py +++ b/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_train_model_without_labels.py @@ -11,7 +11,7 @@ DESCRIPTION: This sample demonstrates how to train a model with unlabeled data. For this sample, you can use the training - forms found in https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/formrecognizer/azure-ai-formrecognizer/samples/sample_forms/training + forms found in https://aka.ms/azsdk/formrecognizer/sampletrainingfiles Upload the forms to your storage container and then generate a container SAS URL using these instructions: https://docs.microsoft.com/azure/cognitive-services/form-recognizer/quickstarts/python-labeled-data#train-a-model-using-labeled-data diff --git a/sdk/formrecognizer/test-resources.json b/sdk/formrecognizer/test-resources.json index ed991b471483..c73e87d8bd3e 100644 --- a/sdk/formrecognizer/test-resources.json +++ b/sdk/formrecognizer/test-resources.json @@ -260,6 +260,58 @@ "PURCHASE_ORDER_OFFICE_CLEANING_SUPPLIES_SAS_URL": { "type": "string", "value": "[concat(reference(parameters('blobResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('trainingDataContainer'), '?', listServiceSas(parameters('blobResourceId'), '2019-06-01', parameters('trainingDataSasProperties')).serviceSasToken)]" + }, + "AZURE_FORM_RECOGNIZER_ENDPOINT": { + "type": "string", + "value": "[variables('azureFormRecognizerUrl')]" + }, + "AZURE_FORM_RECOGNIZER_KEY": { + "type": "string", + "value": "[listKeys(resourceId('Microsoft.CognitiveServices/accounts', variables('formRecognizerBaseName')), variables('formRecognizerApiVersion')).key1]" + }, + "AZURE_FORM_RECOGNIZER_SOURCE_ENDPOINT": { + "type": "string", + "value": "[variables('azureFormRecognizerUrl')]" + }, + "AZURE_FORM_RECOGNIZER_SOURCE_KEY": { + "type": "string", + "value": "[listKeys(resourceId('Microsoft.CognitiveServices/accounts', variables('formRecognizerBaseName')), variables('formRecognizerApiVersion')).key1]" + }, + "AZURE_FORM_RECOGNIZER_TARGET_ENDPOINT": { + "type": "string", + "value": "[variables('azureFormRecognizerUrl')]" + }, + "AZURE_FORM_RECOGNIZER_TARGET_KEY": { + "type": "string", + "value": "[listKeys(resourceId('Microsoft.CognitiveServices/accounts', variables('formRecognizerBaseName')), variables('formRecognizerApiVersion')).key1]" + }, + "AZURE_FORM_RECOGNIZER_TARGET_REGION": { + "type": "string", + "value": "[parameters('location')]" + }, + "AZURE_FORM_RECOGNIZER_TARGET_RESOURCE_ID": { + "type": "string", + "value": "[resourceId('Microsoft.CognitiveServices/accounts', variables('formRecognizerBaseName'))]" + }, + "CONTAINER_SAS_URL": { + "type": "string", + "value": "[concat(reference(parameters('blobResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('trainingDataContainer'), '?', listServiceSas(parameters('blobResourceId'), '2019-06-01', parameters('trainingDataSasProperties')).serviceSasToken)]" + }, + "CONTAINER_SAS_URL_WITH_LABELS": { + "type": "string", + "value": "[concat(reference(parameters('blobResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('trainingDataContainer'), '?', listServiceSas(parameters('blobResourceId'), '2019-06-01', parameters('trainingDataSasProperties')).serviceSasToken)]" + }, + "CONTAINER_SAS_URL_WITHOUT_LABELS": { + "type": "string", + "value": "[concat(reference(parameters('blobResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('trainingDataContainer'), '?', listServiceSas(parameters('blobResourceId'), '2019-06-01', parameters('trainingDataSasProperties')).serviceSasToken)]" + }, + "CONTAINER_SAS_URL_FIXED": { + "type": "string", + "value": "[concat(reference(parameters('blobResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('labelTablesFixedRowsContainer'), '?', listServiceSas(parameters('blobResourceId'), '2019-06-01', parameters('labelTablesFixedRowsSasProperties')).serviceSasToken)]" + }, + "CONTAINER_SAS_URL_DYNAMIC": { + "type": "string", + "value": "[concat(reference(parameters('blobResourceId'), '2019-06-01').primaryEndpoints.blob, parameters('labelTablesVariableRowsContainer'), '?', listServiceSas(parameters('blobResourceId'), '2019-06-01', parameters('labelTablesVariableRowsSasProperties')).serviceSasToken)]" } } } diff --git a/sdk/formrecognizer/tests.yml b/sdk/formrecognizer/tests.yml index e2223a0663b3..fd3c339edf8f 100644 --- a/sdk/formrecognizer/tests.yml +++ b/sdk/formrecognizer/tests.yml @@ -30,19 +30,3 @@ stages: TEST_MODE: 'RunLiveNoRecord' AZURE_SKIP_LIVE_RECORDING: 'True' AZURE_TEST_RUN_LIVE: 'true' - # EnvVars for samples to run. TODO: These use an existing FR resource. Fix samples so they don't have to - AZURE_FORM_RECOGNIZER_AAD_ENDPOINT: $(python-formrecognizer-test-aad-endpoint) - AZURE_FORM_RECOGNIZER_ENDPOINT: $(python-formrecognizer-test-endpoint) - AZURE_FORM_RECOGNIZER_KEY: $(python-formrecognizer-test-endpoint-key) - CUSTOM_TRAINED_MODEL_ID: $(python-formrecognizer-test-model-trained-without-labels) - AZURE_SOURCE_MODEL_ID: $(python-formrecognizer-test-model-trained-with-labels) - ID_OF_MODEL_TRAINED_WITH_LABELS: $(python-formrecognizer-test-model-trained-with-labels) - ID_OF_MODEL_TRAINED_WITHOUT_LABELS: $(python-formrecognizer-test-model-trained-without-labels) - AZURE_FORM_RECOGNIZER_SOURCE_ENDPOINT: $(python-formrecognizer-test-endpoint) - AZURE_FORM_RECOGNIZER_SOURCE_KEY: $(python-formrecognizer-test-endpoint-key) - AZURE_FORM_RECOGNIZER_TARGET_ENDPOINT: $(python-formrecognizer-test-endpoint) - AZURE_FORM_RECOGNIZER_TARGET_KEY: $(python-formrecognizer-test-endpoint-key) - AZURE_FORM_RECOGNIZER_TARGET_REGION: $(python-formrecognizer-test-target-region) - AZURE_FORM_RECOGNIZER_TARGET_RESOURCE_ID: $(python-formrecognizer-test-target-resource-id) - MODEL_ID_FIXED_ROW_TABLES: $(python-formrecognizer-test-model-id-fixed-row-tables) - MODEL_ID_DYNAMIC_ROW_TABLES: $(python-formrecognizer-test-model-id-dynamic-row-tables)