Need Python SDK to call Form Recognizer Service for document classification

Abhijeet Pratap Singh 55 Reputation points
2023-06-21T14:54:46.0533333+00:00

Hi ,

I am doing one POC where i need to classify scanned documents. To achieve this I am using Azure form recognizer Custom Classification Model. In Studio i am able to train the model and able to test it but how we can do it using python. Do you have python SDK for this.

I googled i found some code but it's not working and giving me some error . How we can solve it ? Any tip or suggestion.

Python Code :

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

endpoint = [My Azure Service End point ]
key = [Key]
classifier_id = [classifier_id]
path_to_sample_documents = [My Local File Path]
document_analysis_client = DocumentAnalysisClient(
    endpoint=endpoint, credential=AzureKeyCredential(key)
)
with open(path_to_sample_documents, "rb") as f:
    poller = document_analysis_client.begin_classify_document(
        classifier_id, document=f
    )
result = poller.result()

print("----Classified documents----")

Error :

    poller = document_analysis_client.begin_classify_document(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'DocumentAnalysisClient' object has no attribute 'begin_classify_document'. Did you mean: 'begin_analyze_document'?

Thanks
Abhijeet

Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
1,462 questions
0 comments No comments
{count} votes

Accepted answer
  1. romungi-MSFT 43,246 Reputation points Microsoft Employee
    2023-06-22T09:14:21.7533333+00:00

    @Abhijeet Pratap Singh begin_classify_document() method will be available in the pre-release version of the SDK 3.3.0.b1since this is equivalent to custom classification model of FR, please check if you have installed this version and try again.

    If you have just started using the python SDK, then please try the GA version 3.2.0 and there are several examples on the GitHub repo to analyze documents with the prebuilt or custom models.

    For SDK reference, please use this link and select the required SDK version to lookup the reference.

    I hope this helps!!

    If this answers your query, do click Accept Answer and Yes for was this answer helpful. And, if you have any further query do let us know.


0 additional answers

Sort by: Most helpful