Skip to content

Commit

Permalink
[formrecognizer] sample fixes (Azure#20964)
Browse files Browse the repository at this point in the history
* remove passing api_version in v3.1.x samples and uncomment list models

* skip mgmt samples failing due to list models
  • Loading branch information
kristapratico authored Sep 30, 2021
1 parent 78a4a8a commit 8b885da
Show file tree
Hide file tree
Showing 35 changed files with 64 additions and 60 deletions.
4 changes: 4 additions & 0 deletions scripts/devops_tasks/test_run_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@
"sample_list_translations_with_filters.py",
"sample_translation_with_custom_model.py",
"sample_translation_with_custom_model_async.py",
],
"azure-ai-formrecognizer": [
"sample_manage_custom_models.py",
"sample_manage_custom_models_async.py",
]
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def authentication_with_api_key_credential_form_recognizer_client_async(se
endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

form_recognizer_client = FormRecognizerClient(endpoint, AzureKeyCredential(key), api_version="2.1")
form_recognizer_client = FormRecognizerClient(endpoint, AzureKeyCredential(key))
# [END create_fr_client_with_key_async]
async with form_recognizer_client:
poller = await form_recognizer_client.begin_recognize_content_from_url(self.url)
Expand All @@ -62,7 +62,7 @@ async def authentication_with_azure_active_directory_form_recognizer_client_asyn
endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
credential = DefaultAzureCredential()

form_recognizer_client = FormRecognizerClient(endpoint, credential, api_version="2.1")
form_recognizer_client = FormRecognizerClient(endpoint, credential)
# [END create_fr_client_with_aad_async]
async with form_recognizer_client:
poller = await form_recognizer_client.begin_recognize_content_from_url(self.url)
Expand All @@ -75,7 +75,7 @@ async def authentication_with_api_key_credential_form_training_client_async(self
endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

form_training_client = FormTrainingClient(endpoint, AzureKeyCredential(key), api_version="2.1")
form_training_client = FormTrainingClient(endpoint, AzureKeyCredential(key))
# [END create_ft_client_with_key_async]
async with form_training_client:
properties = await form_training_client.get_account_properties()
Expand All @@ -91,7 +91,7 @@ async def authentication_with_azure_active_directory_form_training_client_async(
endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
credential = DefaultAzureCredential()

form_training_client = FormTrainingClient(endpoint, credential, api_version="2.1")
form_training_client = FormTrainingClient(endpoint, credential)
# [END create_ft_client_with_aad_async]
async with form_training_client:
properties = await form_training_client.get_account_properties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def copy_model_async(self, custom_model_id):
target_resource_id = os.environ["AZURE_FORM_RECOGNIZER_TARGET_RESOURCE_ID"]

# [START get_copy_authorization_async]
target_client = FormTrainingClient(endpoint=target_endpoint, credential=AzureKeyCredential(target_key), api_version="2.1")
target_client = FormTrainingClient(endpoint=target_endpoint, credential=AzureKeyCredential(target_key))

async with target_client:
target = await target_client.get_copy_authorization(
Expand All @@ -64,7 +64,7 @@ async def copy_model_async(self, custom_model_id):
# [END get_copy_authorization_async]

# [START copy_model_async]
source_client = FormTrainingClient(endpoint=source_endpoint, credential=AzureKeyCredential(source_key), api_version="2.1")
source_client = FormTrainingClient(endpoint=source_endpoint, credential=AzureKeyCredential(source_key))

async with source_client:
poller = await source_client.begin_copy_model(
Expand Down Expand Up @@ -93,7 +93,7 @@ async def main():
raise ValueError("Please provide endpoint and API key to run the samples.")

form_training_client = FormTrainingClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
)
async with form_training_client:
model = await (await form_training_client.begin_training(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def create_composed_model_async(self):
po_furniture = os.environ['PURCHASE_ORDER_OFFICE_FURNITURE_SAS_URL_V2']
po_cleaning_supplies = os.environ['PURCHASE_ORDER_OFFICE_CLEANING_SUPPLIES_SAS_URL_V2']

form_training_client = FormTrainingClient(endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1")
form_training_client = FormTrainingClient(endpoint=endpoint, credential=AzureKeyCredential(key))
async with form_training_client:
supplies_poller = await form_training_client.begin_training(
po_supplies, use_training_labels=True, model_name="Purchase order - Office supplies"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def test_recognize_tables_fixed_rows_async(self, custom_model_id):
model_id_fixed_rows_table = os.getenv("MODEL_ID_FIXED_ROW_TABLES", custom_model_id)

form_recognizer_client = FormRecognizerClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
)

path_to_sample_forms = os.path.abspath(os.path.join(os.path.abspath(__file__),
Expand Down Expand Up @@ -96,7 +96,7 @@ async def test_recognize_tables_dynamic_rows_async(self, custom_model_id):
model_id_dynamic_rows_table = os.getenv("MODEL_ID_DYNAMIC_ROW_TABLES", custom_model_id)

form_recognizer_client = FormRecognizerClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
)

path_to_sample_forms = os.path.abspath(os.path.join(os.path.abspath(__file__),
Expand Down Expand Up @@ -149,7 +149,7 @@ async def main():
raise ValueError("Please provide endpoint and API key to run the samples.")

form_training_client = FormTrainingClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
)

async with form_training_client:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def recognize_custom_forms(self, labeled_model_id, 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(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
) as form_recognizer_client:

with open(path_to_sample_forms, "rb") as f:
Expand Down Expand Up @@ -143,7 +143,7 @@ async def main():
raise ValueError("Please provide endpoint and API key to run the samples.")

form_training_client = FormTrainingClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
)

async with form_training_client:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async def get_bounding_boxes(self, custom_model_id):
model_id = os.getenv("CUSTOM_TRAINED_MODEL_ID", custom_model_id)

form_recognizer_client = FormRecognizerClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
)

path_to_sample_forms = os.path.abspath(os.path.join(os.path.abspath(__file__),
Expand Down Expand Up @@ -135,7 +135,7 @@ async def main():
raise ValueError("Please provide endpoint and API key to run the samples.")

form_training_client = FormTrainingClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
)
async with form_training_client:
model = await (await form_training_client.begin_training(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def manage_custom_models(self):

# [START get_account_properties_async]
async with FormTrainingClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
) as form_training_client:
# First, we see how many custom models we have, and what our limit is
account_properties = await form_training_client.get_account_properties()
Expand All @@ -52,9 +52,9 @@ async def manage_custom_models(self):
# [START list_custom_models_async]
custom_models = form_training_client.list_custom_models()

# print("We have models with the following IDs:") TODO list models is returning null for some models
# async for model in custom_models:
# print(model.model_id)
print("We have models with the following IDs:")
async for model in custom_models:
print(model.model_id)
# [END list_custom_models_async]

# let's train a model to use for this sample
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def recognize_business_card_async(self):
key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

form_recognizer_client = FormRecognizerClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
)
async with form_recognizer_client:
with open(path_to_sample_forms, "rb") as f:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def recognize_content(self):
key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

async with FormRecognizerClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
) as form_recognizer_client:

with open(path_to_sample_forms, "rb") as f:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def recognize_custom_forms(self, custom_model_id):
model_id = os.getenv("CUSTOM_TRAINED_MODEL_ID", custom_model_id)

async with FormRecognizerClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
) as form_recognizer_client:

# Make sure your form's type is included in the list of form types the custom model can recognize
Expand Down Expand Up @@ -121,7 +121,7 @@ async def main():
raise ValueError("Please provide endpoint and API key to run the samples.")

form_training_client = FormTrainingClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
)
async with form_training_client:
model = await (await form_training_client.begin_training(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def recognize_identity_documents(self):
key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

async with FormRecognizerClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
) as form_recognizer_client:

with open(path_to_sample_forms, "rb") as f:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def recognize_invoice(self):
key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

async with FormRecognizerClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
) as form_recognizer_client:
with open(path_to_sample_forms, "rb") as f:
poller = await form_recognizer_client.begin_recognize_invoices(invoice=f, locale="en-US")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async def recognize_receipts(self):
key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

async with FormRecognizerClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
) as form_recognizer_client:

with open(path_to_sample_forms, "rb") as f:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ async def recognize_receipts_from_url(self):
key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

async with FormRecognizerClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
) as form_recognizer_client:
url = "https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/formrecognizer/azure-ai-formrecognizer/tests/sample_forms/receipt/contoso-receipt.png"
poller = await form_recognizer_client.begin_recognize_receipts_from_url(receipt_url=url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def strongly_typed_receipt_async(self):
key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

async with FormRecognizerClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
) as form_recognizer_client:

with open(path_to_sample_forms, "rb") as f:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ async def train_model_with_labels(self):
container_sas_url = os.environ["CONTAINER_SAS_URL_V2"]

form_training_client = FormTrainingClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
)

async with form_training_client:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def train_model_without_labels(self):
container_sas_url = os.environ["CONTAINER_SAS_URL_V2"]

async with FormTrainingClient(
endpoint, AzureKeyCredential(key), api_version="2.1"
endpoint, AzureKeyCredential(key)
) as form_training_client:

poller = await form_training_client.begin_training(container_sas_url, use_training_labels=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def authentication_with_api_key_credential_form_recognizer_client(self):
endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

form_recognizer_client = FormRecognizerClient(endpoint, AzureKeyCredential(key), api_version="2.1")
form_recognizer_client = FormRecognizerClient(endpoint, AzureKeyCredential(key))
# [END create_fr_client_with_key]
poller = form_recognizer_client.begin_recognize_content_from_url(self.url)
result = poller.result()
Expand All @@ -60,7 +60,7 @@ def authentication_with_azure_active_directory_form_recognizer_client(self):
endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
credential = DefaultAzureCredential()

form_recognizer_client = FormRecognizerClient(endpoint, credential, api_version="2.1")
form_recognizer_client = FormRecognizerClient(endpoint, credential)
# [END create_fr_client_with_aad]
poller = form_recognizer_client.begin_recognize_content_from_url(self.url)
result = poller.result()
Expand All @@ -72,7 +72,7 @@ def authentication_with_api_key_credential_form_training_client(self):
endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

form_training_client = FormTrainingClient(endpoint, AzureKeyCredential(key), api_version="2.1")
form_training_client = FormTrainingClient(endpoint, AzureKeyCredential(key))
# [END create_ft_client_with_key]
properties = form_training_client.get_account_properties()

Expand All @@ -87,7 +87,7 @@ def authentication_with_azure_active_directory_form_training_client(self):
endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
credential = DefaultAzureCredential()

form_training_client = FormTrainingClient(endpoint, credential, api_version="2.1")
form_training_client = FormTrainingClient(endpoint, credential)
# [END create_ft_client_with_aad]
properties = form_training_client.get_account_properties()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def copy_model(self, custom_model_id):
target_resource_id = os.environ["AZURE_FORM_RECOGNIZER_TARGET_RESOURCE_ID"]

# [START get_copy_authorization]
target_client = FormTrainingClient(endpoint=target_endpoint, credential=AzureKeyCredential(target_key), api_version="2.1")
target_client = FormTrainingClient(endpoint=target_endpoint, credential=AzureKeyCredential(target_key))

target = target_client.get_copy_authorization(
resource_region=target_region,
Expand All @@ -62,7 +62,7 @@ def copy_model(self, custom_model_id):
# [END get_copy_authorization]

# [START begin_copy_model]
source_client = FormTrainingClient(endpoint=source_endpoint, credential=AzureKeyCredential(source_key), api_version="2.1")
source_client = FormTrainingClient(endpoint=source_endpoint, credential=AzureKeyCredential(source_key))

poller = source_client.begin_copy_model(
model_id=source_model_id,
Expand Down Expand Up @@ -90,7 +90,7 @@ def copy_model(self, custom_model_id):
raise ValueError("Please provide endpoint and API key to run the samples.")

form_training_client = FormTrainingClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
)
model = form_training_client.begin_training(os.getenv("CONTAINER_SAS_URL_V2"), use_training_labels=True).result()
model_id = model.model_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def create_composed_model(self):
po_furniture = os.environ['PURCHASE_ORDER_OFFICE_FURNITURE_SAS_URL_V2']
po_cleaning_supplies = os.environ['PURCHASE_ORDER_OFFICE_CLEANING_SUPPLIES_SAS_URL_V2']

form_training_client = FormTrainingClient(endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1")
form_training_client = FormTrainingClient(endpoint=endpoint, credential=AzureKeyCredential(key))
supplies_poller = form_training_client.begin_training(
po_supplies, use_training_labels=True, model_name="Purchase order - Office supplies"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_recognize_tables_fixed_rows(self, custom_model_id):
model_id_fixed_rows_table = os.getenv("MODEL_ID_FIXED_ROW_TABLES", custom_model_id)

form_recognizer_client = FormRecognizerClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
)

path_to_sample_forms = os.path.abspath(os.path.join(os.path.abspath(__file__),
Expand Down Expand Up @@ -94,7 +94,7 @@ def test_recognize_tables_dynamic_rows(self, custom_model_id):
model_id_dynamic_rows_table = os.getenv("MODEL_ID_DYNAMIC_ROW_TABLES", custom_model_id)

form_recognizer_client = FormRecognizerClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
)

path_to_sample_forms = os.path.abspath(os.path.join(os.path.abspath(__file__),
Expand Down Expand Up @@ -146,7 +146,7 @@ def test_recognize_tables_dynamic_rows(self, custom_model_id):
raise ValueError("Please provide endpoint and API key to run the samples.")

form_training_client = FormTrainingClient(
endpoint=endpoint, credential=AzureKeyCredential(key), api_version="2.1"
endpoint=endpoint, credential=AzureKeyCredential(key)
)

if fixed:
Expand Down
Loading

0 comments on commit 8b885da

Please sign in to comment.