Form recognizer custom model - Python connection issue

William Peterson 0 Reputation points
2023-06-06T17:54:29.4+00:00

I am trying to connect python to my custom form recognizer in order to pull data off of pdfs, but I am running into an error when I try to connect. I found my endpoint and key from Azure Portal, and I believed I could use the name of my model in Form Recognizer Studio, but this indicates otherwise. My project is called Entegrity-custom-parser and the Model ID inside that is called first_five_model. How can I fix this to connect?

Error:

azure.core.exceptions.ResourceNotFoundError: (NotFound) Resource not found.
Code: NotFound
Message: Resource not found.
Inner error: {
    "code": "ModelNotFound",
    "message": "The requested model was not found."
}

My code:

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

def pdf_to_bytes(file_path):
    with open(file_path, 'rb') as file:
        pdf_bytes = file.read()
    return pdf_bytes

endpoint = 'https://southcentralus.api.cognitive.microsoft.com/'
key = ''
custom_model_id = 'first_five_model'

path = 'C:/Users/william.peterson/Desktop/training-files/normal.pdf'

document_analysis_client = DocumentAnalysisClient(
    endpoint=endpoint, credential=AzureKeyCredential(key)
    )
    
poller = document_analysis_client.begin_analyze_document(custom_model_id, pdf_to_bytes(path))
invoices = poller.result()

for idx, invoice in enumerate(invoices.documents):
    print(idx,invoice)
Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
1,666 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Toshikazu Oki 0 Reputation points
    2024-09-26T08:38:27.71+00:00

    I faced the same issue. I was able to solve the problem by changing the API version specified from “2023-07-31 (GA)” to “2024-07-31 (Preview)” when creating the custom model.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.