I can't use the query fields in Azure Document Intelligence layout mode.

Jonata Henrique 20 Reputation points
2024-12-05T00:30:42.2+00:00

I have already downloaded several versions of the azure-ai-formrecognizer library, but it always gives the error regarding this code snippet model to obtain the query fields in layout mode.

This is the model that queries are obtained from, but it will always give the error that will be at the end of my text

# Analyze a document at a URL:
formUrl = "https://github.com/Azure-Samples/document-intelligence-code-samples/blob/main/Data/invoice/simple-invoice.png?raw=true"
poller = document_intelligence_client.begin_analyze_document(
    "prebuilt-layout",
    AnalyzeDocumentRequest(url_source=formUrl),
    features=[DocumentAnalysisFeature.QUERY_FIELDS],    # Specify which add-on capabilities to enable.
    query_fields=["Address", "InvoiceNumber"],  # Set the features and provide a comma-separated list of field names.
)
result: AnalyzeResult = poller.result()
print("Here are extra fields in result:\n")
if result.documents:
    for doc in result.documents:
        if doc.fields and doc.fields["Address"]:
            print(f"Address: {doc.fields['Address'].value_string}")
        if doc.fields and doc.fields["InvoiceNumber"]:
            print(f"Invoice number: {doc.fields['InvoiceNumber'].value_string}")  

ERROR: from azure.ai.formrecognizer import DocumentAnalysisClient, DocumentAnalysisFeature

ImportError: cannot import name 'DocumentAnalysisClient' from 'azure.ai.formrecognizer' (C:\Users\aline\AppData\Roaming\Python\Python312\site-packages\azure\ai\formrecognizer_init_.py)

Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
2,100 questions
{count} votes

Accepted answer
  1. kothapally Snigdha 3,020 Reputation points Microsoft External Staff Moderator
    2024-12-10T02:07:11.97+00:00

    Hi Jonata Henrique

    • Ensure that the version of the library you are trying to install is compatible with your project’s dependencies and environment.
    • Sometimes, cached files can cause issues. Clear the cache for your package manager.
    • Review your environment for any other libraries that might conflict with the one you're trying to use. You can do this by listing all installed.
    • Look at the installation logs for any warnings or errors that might indicate what went wrong during the installation process.
    • Consider creating a new virtual environment to isolate your project dependencies. This can help eliminate conflicts. I hope this helps you. Thankyou!
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

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.