Python용 Azure Form Recognizer 클라이언트 라이브러리 - 버전 3.3.2

Azure Document Intelligence(이전에는 Form Recognizer라고 함)는 기계 학습을 사용하여 문서에서 텍스트 및 구조화된 데이터를 분석하는 클라우드 서비스입니다. 여기에는 다음과 같은 기본 기능이 포함됩니다.

  • 레이아웃 - 문서에서 콘텐츠 및 구조(예: 단어, 선택 표시, 테이블)를 추출합니다.
  • 문서 - 문서의 일반 레이아웃 외에도 키-값 쌍을 분석합니다.
  • 읽기 - 문서에서 페이지 정보를 읽습니다.
  • 미리 빌드 - 미리 빌드된 모델을 사용하여 선택한 문서 유형(예: 영수증, 청구서, 명함, ID 문서, 미국 W-2 세금 문서 등)에서 공통 필드 값을 추출합니다.
  • 사용자 지정 - 사용자 고유의 데이터에서 사용자 지정 모델을 빌드하여 문서에서 일반 레이아웃 외에도 맞춤형 필드 값을 추출합니다.
  • 분류자 - 레이아웃 및 언어 기능을 결합하여 애플리케이션 내에서 처리하는 문서를 정확하게 검색하고 식별하는 사용자 지정 분류 모델을 빌드합니다.
  • 추가 기능 - 바코드/QR 코드, 수식, 글꼴/스타일 등을 추출하거나 선택적 매개 변수가 있는 큰 문서에 대해 고해상도 모드를 사용하도록 설정합니다.

소스 코드 | 패키지(PyPI) | 패키지(Conda) | API 참조 설명서 | 제품 설명서 | 샘플

시작

필수 구성 요소

패키지 설치

pip를 사용하여 Python용 Azure Form Recognizer 클라이언트 라이브러리를 설치합니다.

pip install azure-ai-formrecognizer

참고: 이 버전의 클라이언트 라이브러리는 기본적으로 서비스 버전으로 설정됩니다 2023-07-31 .

다음 표에서는 SDK 버전 및 지원되는 API 버전의 서비스 간 관계를 보여 줍니다.

SDK 버전 지원되는 API 버전의 서비스
3.3.X - 최신 GA 릴리스 2.0, 2.1, 2022-08-31, 2023-07-31(기본값)
3.2.X 2.0, 2.1, 2022-08-31(기본값)
3.1.X 2.0, 2.1(기본값)
3.0.0 2.0

참고: 버전 3.2.X부터 Document Intelligence 서비스의 최신 기능을 활용하기 위해 새 클라이언트 집합이 도입되었습니다. 클라이언트 라이브러리 버전 이하에서 최신 버전 3.1.X 으로 애플리케이션 코드를 업데이트하는 방법에 대한 자세한 지침은 마이그레이션 가이드를 참조하세요. 또한 자세한 내용은 Changelog 를 참조하세요. 아래 표에서는 각 클라이언트와 지원되는 API 버전의 관계를 설명합니다.

API 버전 지원되는 클라이언트
2023-07-31 DocumentAnalysisClient 및 DocumentModelAdministrationClient
2022-08-31 DocumentAnalysisClient 및 DocumentModelAdministrationClient
2.1 FormRecognizerClient 및 FormTrainingClient
2.0 FormRecognizerClient 및 FormTrainingClient

Cognitive Services 또는 Form Recognizer 리소스 만들기

Document Intelligence는 다중 서비스 및 단일 서비스 액세스를 모두 지원합니다. 단일 엔드포인트/키에서 여러 Cognitive Services에 액세스하려는 경우 Cognitive Services 리소스를 만듭니다. 문서 인텔리전스 액세스에만 Form Recognizer 리소스를 만듭니다. Azure Active Directory 인증을 사용하려는 경우 단일 서비스 리소스가 필요합니다.

다음을 사용하여 리소스를 만들 수 있습니다.

다음은 CLI를 사용하여 Form Recognizer 리소스를 만드는 방법의 예입니다.

# Create a new resource group to hold the Form Recognizer resource
# if using an existing resource group, skip this step
az group create --name <your-resource-name> --location <location>
# Create form recognizer
az cognitiveservices account create \
    --name <your-resource-name> \
    --resource-group <your-resource-group-name> \
    --kind FormRecognizer \
    --sku <sku> \
    --location <location> \
    --yes

리소스를 만드는 방법 또는 위치 및 sku 정보를 가져오는 방법에 대한 자세한 내용은 여기를 참조 하세요.

클라이언트 인증

Document Intelligence 서비스와 상호 작용하려면 클라이언트의 instance 만들어야 합니다. 클라이언트 개체를 인스턴스화하려면 엔드포인트자격 증명 이 필요합니다.

엔드포인트 가져오기

Azure Portal 또는 Azure CLI를 사용하여 Form Recognizer 리소스에 대한 엔드포인트를 찾을 수 있습니다.

# Get the endpoint for the Form Recognizer resource
az cognitiveservices account show --name "resource-name" --resource-group "resource-group-name" --query "properties.endpoint"

지역 엔드포인트 또는 사용자 지정 하위 도메인을 인증에 사용할 수 있습니다. 형식은 다음과 같이 지정됩니다.

Regional endpoint: https://<region>.api.cognitive.microsoft.com/
Custom subdomain: https://<resource-name>.cognitiveservices.azure.com/

지역 엔드포인트는 지역의 모든 리소스에 대해 동일합니다. 지원되는 지역 엔드포인트의 전체 목록은 여기에서 참조할 수 있습니다. 지역 엔드포인트는 AAD 인증을 지원하지 않습니다.

반면에 사용자 지정 하위 도메인은 Form Recognizer 리소스에 고유한 이름입니다. 단일 서비스 리소스에서만 사용할 수 있습니다.

API 키 가져오기

API 키는 Azure Portal 에서 또는 다음 Azure CLI 명령을 실행하여 찾을 수 있습니다.

az cognitiveservices account keys list --name "<resource-name>" --resource-group "<resource-group-name>"

AzureKeyCredential을 사용하여 클라이언트 만들기

API 키를 매개 변수로 credential 사용하려면 AzureKeyCredential의 instance 키를 문자열로 전달합니다.

from azure.core.credentials import AzureKeyCredential
from azure.ai.formrecognizer import DocumentAnalysisClient

endpoint = "https://<my-custom-subdomain>.cognitiveservices.azure.com/"
credential = AzureKeyCredential("<api_key>")
document_analysis_client = DocumentAnalysisClient(endpoint, credential)

Azure Active Directory 자격 증명을 사용하여 클라이언트 만들기

AzureKeyCredential 인증은 이 시작 가이드의 예제에서 사용되지만 azure-identity 라이브러리를 사용하여 Azure Active Directory로 인증할 수도 있습니다. 지역 엔드포인트는 AAD 인증을 지원하지 않습니다. 이러한 유형의 인증을 사용하기 위해 리소스에 대한 사용자 지정 하위 도메인 이름을 만듭니다.

아래에 표시된 DefaultAzureCredential 형식 또는 Azure SDK와 함께 제공되는 기타 자격 증명 형식을 사용하려면 패키지를 설치 azure-identity 하세요.

pip install azure-identity

또한 새 AAD 애플리케이션을 등록하고 서비스 주체에게 역할을 할당하여 "Cognitive Services User" 문서 인텔리전스에 대한 액세스 권한을 부여해야 합니다.

완료되면 AAD 애플리케이션의 클라이언트 ID, 테넌트 ID 및 클라이언트 암호 값을 환경 변수 AZURE_CLIENT_ID, , AZURE_TENANT_IDAZURE_CLIENT_SECRET설정합니다.

"""DefaultAzureCredential will use the values from these environment
variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET
"""
from azure.ai.formrecognizer import DocumentAnalysisClient
from azure.identity import DefaultAzureCredential

endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
credential = DefaultAzureCredential()

document_analysis_client = DocumentAnalysisClient(endpoint, credential)

주요 개념

DocumentAnalysisClient

DocumentAnalysisClient는 및 begin_analyze_document_from_url API를 통해 미리 빌드된 및 사용자 지정 모델을 사용하여 입력 문서를 분석하기 begin_analyze_document 위한 작업을 제공합니다. 매개 변수를 model_id 사용하여 분석할 모델 유형을 선택합니다. 지원되는 모델의 전체 목록은 여기를 참조 하세요. 또한 는 DocumentAnalysisClientbegin_classify_document_from_url API를 통해 begin_classify_document 문서를 분류하기 위한 작업을 제공합니다. 사용자 지정 분류 모델은 입력 파일의 각 페이지를 분류하여 문서를 식별할 수 있으며, 입력 파일 내에서 여러 문서 또는 단일 문서의 여러 인스턴스를 식별할 수도 있습니다.

여기에서 DocumentAnalysisClient 예제를 사용하는 방법을 설명하기 위해 샘플 코드 조각 제공됩니다. 지원되는 기능, 로캘 및 문서 형식을 포함한 문서 분석에 대한 자세한 내용은 서비스 설명서에서 확인할 수 있습니다.

DocumentModelAdministrationClient

DocumentModelAdministrationClient는 다음에 대한 작업을 제공합니다.

  • 사용자 지정 문서에 레이블을 지정하여 지정한 특정 필드를 분석하는 사용자 지정 모델을 빌드합니다. 모델이 분석할 수 있는 문서 유형과 각 필드에 대한 예상 신뢰도를 나타내는 가 DocumentModelDetails 반환됩니다. 자세한 설명은 서비스 설명서를 참조하세요.
  • 기존 모델 컬렉션에서 구성된 모델을 만듭니다.
  • 계정에서 생성된 모델을 관리합니다.
  • 작업을 나열하거나 지난 24시간 이내에 만든 특정 모델 작업을 가져옵니다.
  • 하나의 Form Recognizer 리소스에서 다른 리소스로 사용자 지정 모델을 복사합니다.
  • 사용자 지정 분류 모델을 빌드하고 관리하여 애플리케이션 내에서 처리하는 문서를 분류합니다.

Document Intelligence Studio와 같은 그래픽 사용자 인터페이스를 사용하여 모델을 빌드할 수도 있습니다.

샘플 코드 조각은 여기에서 DocumentModelAdministrationClient 사용하는 방법을 설명하기 위해 제공됩니다.

장기 실행 작업

장기 실행 작업은 작업을 시작하기 위해 서비스로 전송된 초기 요청으로 구성된 작업이며, 그 다음에는 간격으로 서비스를 폴링하여 작업이 완료되었는지 또는 실패했는지, 성공했는지 여부를 확인하여 결과를 가져옵니다.

문서를 분석하거나, 모델을 빌드하거나, 모델을 복사/작성하는 메서드는 장기 실행 작업으로 모델링됩니다. 클라이언트는 또는 AsyncLROPollerbegin_<method-name> 반환하는 메서드를 LROPoller 노출합니다. 호출자는 메서드에서 begin_<method-name> 반환된 폴러 개체를 호출 result() 하여 작업이 완료되기를 기다려야 합니다. 샘플 코드 조각은 아래의 장기 실행 작업 를 사용하여 설명하기 위해 제공됩니다.

예제

다음 섹션에서는 다음을 포함하여 가장 일반적인 문서 인텔리전스 작업 중 일부를 다루는 몇 가지 코드 조각을 제공합니다.

레이아웃 추출

문서에서 경계 영역 좌표와 함께 텍스트, 선택 표시, 텍스트 스타일 및 테이블 구조를 추출합니다.

from azure.core.credentials import AzureKeyCredential
from azure.ai.formrecognizer import DocumentAnalysisClient

endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

document_analysis_client = DocumentAnalysisClient(
    endpoint=endpoint, credential=AzureKeyCredential(key)
)
with open(path_to_sample_documents, "rb") as f:
    poller = document_analysis_client.begin_analyze_document(
        "prebuilt-layout", document=f
    )
result = poller.result()

for idx, style in enumerate(result.styles):
    print(
        "Document contains {} content".format(
            "handwritten" if style.is_handwritten else "no handwritten"
        )
    )

for page in result.pages:
    print("----Analyzing layout from page #{}----".format(page.page_number))
    print(
        "Page has width: {} and height: {}, measured with unit: {}".format(
            page.width, page.height, page.unit
        )
    )

    for line_idx, line in enumerate(page.lines):
        words = line.get_words()
        print(
            "...Line # {} has word count {} and text '{}' within bounding polygon '{}'".format(
                line_idx,
                len(words),
                line.content,
                line.polygon,
            )
        )

        for word in words:
            print(
                "......Word '{}' has a confidence of {}".format(
                    word.content, word.confidence
                )
            )

    for selection_mark in page.selection_marks:
        print(
            "...Selection mark is '{}' within bounding polygon '{}' and has a confidence of {}".format(
                selection_mark.state,
                selection_mark.polygon,
                selection_mark.confidence,
            )
        )

for table_idx, table in enumerate(result.tables):
    print(
        "Table # {} has {} rows and {} columns".format(
            table_idx, table.row_count, table.column_count
        )
    )
    for region in table.bounding_regions:
        print(
            "Table # {} location on page: {} is {}".format(
                table_idx,
                region.page_number,
                region.polygon,
            )
        )
    for cell in table.cells:
        print(
            "...Cell[{}][{}] has content '{}'".format(
                cell.row_index,
                cell.column_index,
                cell.content,
            )
        )
        for region in cell.bounding_regions:
            print(
                "...content on page {} is within bounding polygon '{}'".format(
                    region.page_number,
                    region.polygon,
                )
            )

print("----------------------------------------")

일반 문서 모델 사용

Document Intelligence 서비스에서 제공하는 일반 문서 모델을 사용하여 문서에서 키-값 쌍, 테이블, 스타일 및 선택 표시를 분석합니다. 메서드에 전달 model_id="prebuilt-document"begin_analyze_document 하여 일반 문서 모델을 선택합니다.

from azure.core.credentials import AzureKeyCredential
from azure.ai.formrecognizer import DocumentAnalysisClient

endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

document_analysis_client = DocumentAnalysisClient(
    endpoint=endpoint, credential=AzureKeyCredential(key)
)
with open(path_to_sample_documents, "rb") as f:
    poller = document_analysis_client.begin_analyze_document(
        "prebuilt-document", document=f
    )
result = poller.result()

for style in result.styles:
    if style.is_handwritten:
        print("Document contains handwritten content: ")
        print(",".join([result.content[span.offset:span.offset + span.length] for span in style.spans]))

print("----Key-value pairs found in document----")
for kv_pair in result.key_value_pairs:
    if kv_pair.key:
        print(
                "Key '{}' found within '{}' bounding regions".format(
                    kv_pair.key.content,
                    kv_pair.key.bounding_regions,
                )
            )
    if kv_pair.value:
        print(
                "Value '{}' found within '{}' bounding regions\n".format(
                    kv_pair.value.content,
                    kv_pair.value.bounding_regions,
                )
            )

for page in result.pages:
    print("----Analyzing document from page #{}----".format(page.page_number))
    print(
        "Page has width: {} and height: {}, measured with unit: {}".format(
            page.width, page.height, page.unit
        )
    )

    for line_idx, line in enumerate(page.lines):
        words = line.get_words()
        print(
            "...Line # {} has {} words and text '{}' within bounding polygon '{}'".format(
                line_idx,
                len(words),
                line.content,
                line.polygon,
            )
        )

        for word in words:
            print(
                "......Word '{}' has a confidence of {}".format(
                    word.content, word.confidence
                )
            )

    for selection_mark in page.selection_marks:
        print(
            "...Selection mark is '{}' within bounding polygon '{}' and has a confidence of {}".format(
                selection_mark.state,
                selection_mark.polygon,
                selection_mark.confidence,
            )
        )

for table_idx, table in enumerate(result.tables):
    print(
        "Table # {} has {} rows and {} columns".format(
            table_idx, table.row_count, table.column_count
        )
    )
    for region in table.bounding_regions:
        print(
            "Table # {} location on page: {} is {}".format(
                table_idx,
                region.page_number,
                region.polygon,
            )
        )
    for cell in table.cells:
        print(
            "...Cell[{}][{}] has content '{}'".format(
                cell.row_index,
                cell.column_index,
                cell.content,
            )
        )
        for region in cell.bounding_regions:
            print(
                "...content on page {} is within bounding polygon '{}'\n".format(
                    region.page_number,
                    region.polygon,
                )
            )
print("----------------------------------------")
  • 모델에서 제공하는 기능에 대한 자세한 내용은 여기를 prebuilt-document참조하세요.

미리 빌드된 모델 사용

문서 인텔리전스 서비스에서 제공하는 미리 빌드된 모델을 사용하여 영수증, 청구서, 명함, ID 문서 및 미국 W-2 세금 문서와 같은 일부 문서 유형에서 필드를 추출합니다.

예를 들어 판매 영수증에서 필드를 분석하려면 메서드에 전달 model_id="prebuilt-receipt"begin_analyze_document 하여 제공된 미리 빌드된 영수증 모델을 사용합니다.

from azure.core.credentials import AzureKeyCredential
from azure.ai.formrecognizer import DocumentAnalysisClient

endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]

document_analysis_client = DocumentAnalysisClient(
    endpoint=endpoint, credential=AzureKeyCredential(key)
)
with open(path_to_sample_documents, "rb") as f:
    poller = document_analysis_client.begin_analyze_document(
        "prebuilt-receipt", document=f, locale="en-US"
    )
receipts = poller.result()

for idx, receipt in enumerate(receipts.documents):
    print(f"--------Analysis of receipt #{idx + 1}--------")
    print(f"Receipt type: {receipt.doc_type if receipt.doc_type else 'N/A'}")
    merchant_name = receipt.fields.get("MerchantName")
    if merchant_name:
        print(
            f"Merchant Name: {merchant_name.value} has confidence: "
            f"{merchant_name.confidence}"
        )
    transaction_date = receipt.fields.get("TransactionDate")
    if transaction_date:
        print(
            f"Transaction Date: {transaction_date.value} has confidence: "
            f"{transaction_date.confidence}"
        )
    if receipt.fields.get("Items"):
        print("Receipt items:")
        for idx, item in enumerate(receipt.fields.get("Items").value):
            print(f"...Item #{idx + 1}")
            item_description = item.value.get("Description")
            if item_description:
                print(
                    f"......Item Description: {item_description.value} has confidence: "
                    f"{item_description.confidence}"
                )
            item_quantity = item.value.get("Quantity")
            if item_quantity:
                print(
                    f"......Item Quantity: {item_quantity.value} has confidence: "
                    f"{item_quantity.confidence}"
                )
            item_price = item.value.get("Price")
            if item_price:
                print(
                    f"......Individual Item Price: {item_price.value} has confidence: "
                    f"{item_price.confidence}"
                )
            item_total_price = item.value.get("TotalPrice")
            if item_total_price:
                print(
                    f"......Total Item Price: {item_total_price.value} has confidence: "
                    f"{item_total_price.confidence}"
                )
    subtotal = receipt.fields.get("Subtotal")
    if subtotal:
        print(f"Subtotal: {subtotal.value} has confidence: {subtotal.confidence}")
    tax = receipt.fields.get("TotalTax")
    if tax:
        print(f"Total tax: {tax.value} has confidence: {tax.confidence}")
    tip = receipt.fields.get("Tip")
    if tip:
        print(f"Tip: {tip.value} has confidence: {tip.confidence}")
    total = receipt.fields.get("Total")
    if total:
        print(f"Total: {total.value} has confidence: {total.confidence}")
    print("--------------------------------------")

영수증으로 제한되지 않습니다! 미리 빌드된 몇 가지 모델 중에서 선택할 수 있으며, 각 모델에는 지원되는 필드 집합이 있습니다. 여기에서 지원되는 다른 미리 빌드된 모델을 참조 하세요.

사용자 지정 모델 빌드

사용자 고유의 문서 형식으로 사용자 지정 모델을 빌드합니다. 결과 모델을 사용하여 학습된 문서 형식의 값을 분석할 수 있습니다. 학습 문서를 저장하는 Azure Storage Blob 컨테이너에 컨테이너 SAS URL을 제공합니다.

컨테이너 및 필수 파일 구조 설정에 대한 자세한 내용은 서비스 설명서에서 확인할 수 있습니다.

from azure.ai.formrecognizer import (
    DocumentModelAdministrationClient,
    ModelBuildMode,
)
from azure.core.credentials import AzureKeyCredential

endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]
container_sas_url = os.environ["CONTAINER_SAS_URL"]

document_model_admin_client = DocumentModelAdministrationClient(
    endpoint, AzureKeyCredential(key)
)
poller = document_model_admin_client.begin_build_document_model(
    ModelBuildMode.TEMPLATE,
    blob_container_url=container_sas_url,
    description="my model description",
)
model = poller.result()

print(f"Model ID: {model.model_id}")
print(f"Description: {model.description}")
print(f"Model created on: {model.created_on}")
print(f"Model expires on: {model.expires_on}")
print("Doc types the model can recognize:")
for name, doc_type in model.doc_types.items():
    print(
        f"Doc Type: '{name}' built with '{doc_type.build_mode}' mode which has the following fields:"
    )
    for field_name, field in doc_type.field_schema.items():
        print(
            f"Field: '{field_name}' has type '{field['type']}' and confidence score "
            f"{doc_type.field_confidence[field_name]}"
        )

사용자 지정 모델을 사용하여 문서 분석

문서 필드, 테이블, 선택 표시 등을 분석합니다. 이러한 모델은 사용자 고유의 데이터로 학습되므로 문서에 맞게 조정됩니다. 최상의 결과를 위해 사용자 지정 모델이 빌드된 것과 동일한 문서 형식의 문서만 분석해야 합니다.

from azure.core.credentials import AzureKeyCredential
from azure.ai.formrecognizer import DocumentAnalysisClient

endpoint = os.environ["AZURE_FORM_RECOGNIZER_ENDPOINT"]
key = os.environ["AZURE_FORM_RECOGNIZER_KEY"]
model_id = os.getenv("CUSTOM_BUILT_MODEL_ID", custom_model_id)

document_analysis_client = DocumentAnalysisClient(
    endpoint=endpoint, credential=AzureKeyCredential(key)
)

# Make sure your document's type is included in the list of document types the custom model can analyze
with open(path_to_sample_documents, "rb") as f:
    poller = document_analysis_client.begin_analyze_document(
        model_id=model_id, document=f
    )
result = poller.result()

for idx, document in enumerate(result.documents):
    print(f"--------Analyzing document #{idx + 1}--------")
    print(f"Document has type {document.doc_type}")
    print(f"Document has document type confidence {document.confidence}")
    print(f"Document was analyzed with model with ID {result.model_id}")
    for name, field in document.fields.items():
        field_value = field.value if field.value else field.content
        print(
            f"......found field of type '{field.value_type}' with value '{field_value}' and with confidence {field.confidence}"
        )

# iterate over tables, lines, and selection marks on each page
for page in result.pages:
    print(f"\nLines found on page {page.page_number}")
    for line in page.lines:
        print(f"...Line '{line.content}'")
    for word in page.words:
        print(f"...Word '{word.content}' has a confidence of {word.confidence}")
    if page.selection_marks:
        print(f"\nSelection marks found on page {page.page_number}")
        for selection_mark in page.selection_marks:
            print(
                f"...Selection mark is '{selection_mark.state}' and has a confidence of {selection_mark.confidence}"
            )

for i, table in enumerate(result.tables):
    print(f"\nTable {i + 1} can be found on page:")
    for region in table.bounding_regions:
        print(f"...{region.page_number}")
    for cell in table.cells:
        print(
            f"...Cell[{cell.row_index}][{cell.column_index}] has text '{cell.content}'"
        )
print("-----------------------------------")

또는 문서 URL을 사용하여 메서드를 사용하여 begin_analyze_document_from_url 문서를 분석할 수도 있습니다.

document_url = "<url_of_the_document>"
poller = document_analysis_client.begin_analyze_document_from_url(model_id=model_id, document_url=document_url)
result = poller.result()

모델 관리

계정에 연결된 사용자 지정 모델을 관리합니다.

from azure.ai.formrecognizer import DocumentModelAdministrationClient
from azure.core.credentials import AzureKeyCredential
from azure.core.exceptions import ResourceNotFoundError

endpoint = "https://<my-custom-subdomain>.cognitiveservices.azure.com/"
credential = AzureKeyCredential("<api_key>")

document_model_admin_client = DocumentModelAdministrationClient(endpoint, credential)

account_details = document_model_admin_client.get_resource_details()
print("Our account has {} custom models, and we can have at most {} custom models".format(
    account_details.custom_document_models.count, account_details.custom_document_models.limit
))

# Here we get a paged list of all of our models
models = document_model_admin_client.list_document_models()
print("We have models with the following ids: {}".format(
    ", ".join([m.model_id for m in models])
))

# Replace with the custom model ID from the "Build a model" sample
model_id = "<model_id from the Build a Model sample>"

custom_model = document_model_admin_client.get_document_model(model_id=model_id)
print("Model ID: {}".format(custom_model.model_id))
print("Description: {}".format(custom_model.description))
print("Model created on: {}\n".format(custom_model.created_on))

# Finally, we will delete this model by ID
document_model_admin_client.delete_document_model(model_id=custom_model.model_id)

try:
    document_model_admin_client.get_document_model(model_id=custom_model.model_id)
except ResourceNotFoundError:
    print("Successfully deleted model with id {}".format(custom_model.model_id))

추가 기능

Document Intelligence는 보다 정교한 분석 기능을 지원합니다. 이러한 선택적 기능은 문서 추출 시나리오에 따라 사용하도록 설정하고 사용하지 않도록 설정할 수 있습니다.

다음 추가 기능 기능은 2023-07-31(GA) 이상 릴리스에 사용할 수 있습니다.

일부 추가 기능에서는 추가 요금이 발생합니다. 가격 책정을 https://azure.microsoft.com/pricing/details/ai-document-intelligence/참조하세요.

문제 해결

일반

Form Recognizer 클라이언트 라이브러리는 Azure Core에 정의된 예외를 발생합니다. 문서 인텔리전스 서비스에서 발생한 오류 코드 및 메시지는 서비스 설명서에서 찾을 수 있습니다.

로깅

이 라이브러리는 로깅에 표준 로깅 라이브러리를 사용합니다.

HTTP 세션(URL, 헤더 등)에 대한 기본 정보는 수준에서 기록됩니다 INFO .

DEBUG 요청/응답 본문 및 수정되지 않은 헤더를 포함한 자세한 수준 로깅은 클라이언트에서 또는 키워드(keyword) 인수를 logging_enable 사용하여 작업별로 사용하도록 설정할 수 있습니다.

여기에 예제가 포함된 전체 SDK 로깅 설명서를 참조 하세요.

선택적 구성

선택적 키워드(keyword) 인수는 클라이언트 및 작업별 수준에서 전달할 수 있습니다. azure-core 참조 설명서 에서는 재시도, 로깅, 전송 프로토콜 등에 사용할 수 있는 구성에 대해 설명합니다.

다음 단계

추가 샘플 코드

Form Recognizer Python API에서 사용되는 일반적인 패턴을 보여 주는 여러 코드 조각은 샘플 추가 정보 를 참조하세요.

추가 설명서

Azure AI 문서 인텔리전스에 대한 자세한 설명서는 docs.microsoft.com 대한 문서 인텔리전스 설명서를 참조하세요 .

참여

이 프로젝트에 대한 기여와 제안을 환영합니다. 대부분의 경우 기여하려면 권한을 부여하며 실제로 기여를 사용할 권한을 당사에 부여한다고 선언하는 CLA(기여자 라이선스 계약)에 동의해야 합니다. 자세한 내용은 cla.microsoft.com.

끌어오기 요청을 제출하면 CLA-bot은 CLA를 제공하고 PR을 적절하게 데코레이팅해야 하는지 여부를 자동으로 결정합니다(예: 레이블, 설명). 봇에서 제공하는 지침을 따르기만 하면 됩니다. 이 작업은 CLA를 사용하여 모든 리포지토리에서 한 번만 수행하면 됩니다.

이 프로젝트에는 Microsoft Open Source Code of Conduct(Microsoft 오픈 소스 준수 사항)가 적용됩니다. 자세한 내용은 Code of Conduct FAQ(규정 FAQ)를 참조하세요. 또는 추가 질문이나 의견은 opencode@microsoft.com으로 문의하세요.