[Python] Document AI not returning tax_rate

Discussão em 'Python' iniciado por Stack, Janeiro 19, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to use the Invoice Parser Processor of Document AI. The problem is that I am not getting the tax_rate field in the response when I use the API in my code. However, when I upload the same invoice in the "try docai" web the tax_rate is always returned.

    This is my code to make the API call

    # Initialize the client
    client_options = {"api_endpoint": f"{location}-documentai.googleapis.com"}
    client = documentai.DocumentProcessorServiceClient(client_options=client_options)

    # The full resource name of the processor
    name = client.processor_path(project_id, location, processor_id)

    # Read the file into memory
    with open(file_path, "rb") as pdf_file:
    pdf_content = pdf_file.read()

    # Load the input document
    raw_document = documentai.RawDocument(
    content=pdf_content,
    mime_type=mime_type
    )

    request = documentai.ProcessRequest(
    name=name,
    raw_document=raw_document
    )


    And this is the vat info I get in the response

    text_anchor {
    text_segments {
    start_index: 445
    end_index: 451
    }
    }
    type_: "vat"
    mention_text: "900,00"
    confidence: 1
    page_anchor {
    page_refs {
    bounding_poly {
    normalized_vertices {
    x: 0.277810812
    y: 0.455004215
    }
    normalized_vertices {
    x: 0.332540154
    y: 0.455004215
    }
    normalized_vertices {
    x: 0.332540154
    y: 0.465517253
    }
    normalized_vertices {
    x: 0.277810812
    y: 0.465517253
    }
    }
    }
    }
    id: "0"
    properties {
    text_anchor {
    text_segments {
    start_index: 445
    end_index: 451
    }
    content: "900,00"
    }
    type_: "vat/amount"
    mention_text: "900,00"
    confidence: 0.501076162
    page_anchor {
    page_refs {
    bounding_poly {
    normalized_vertices {
    x: 0.277810812
    y: 0.455004215
    }
    normalized_vertices {
    x: 0.332540154
    y: 0.455004215
    }
    normalized_vertices {
    x: 0.332540154
    y: 0.465517253
    }
    normalized_vertices {
    x: 0.277810812
    y: 0.465517253
    }
    }
    }
    }
    id: "1"
    normalized_value {
    text: "900"
    }
    }


    NOTE: The invoice is in Spanish and I have not been able to set the language. However, I have read somewhere that the language is automatically detected.

    How can I obtain the tax_rate when calling the API?

    Continue reading...

Compartilhe esta Página