<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Document AI General Document Splitter
This notebook demonstrates how to use Document Splitter to parse a simple PDF document with multiple scanned files to separate documents on page logical boundaries.
Step1:  Set your Processor Variables
Step3:  Now let's define the function to process the document with Document AI Python client
Step4:  We can now run the processor on the sample multi-document pdf.
<ASSISTANT_TASK:>
Python Code:
# Install necessary Python libraries and restart your kernel after.
!python -m pip install -r ../requirements.txt
Explanation: Document AI General Document Splitter
This notebook demonstrates how to use Document Splitter to parse a simple PDF document with multiple scanned files to separate documents on page logical boundaries.
End of explanation
# TODO(developer): Fill these variables with your values before running the sample
PROJECT_ID = "YOUR_PROJECT_ID_HERE"
LOCATION = "us"  # Format is 'us' or 'eu'
PROCESSOR_ID = "PROCESSOR_ID"  # Create processor in Cloud Console
FILE_PATH = '../resources/general/multi-document.pdf'
Explanation: Set your Processor Variables
End of explanation
# Import necessary Python modules
from google.cloud import documentai_v1 as documentai
def process_document_sample(
    project_id: str, location: str, processor_id: str, file_path: str
):
    # Instantiates a client
    opts = {"api_endpoint": f"{location}-documentai.googleapis.com"}
    client = documentai.DocumentProcessorServiceClient(client_options=opts)
    # The full resource name of the processor, e.g.:
    # projects/project-id/locations/location/processor/processor-id
    # You must create new processors in the Cloud Console first
    name = f"projects/{project_id}/locations/{location}/processors/{processor_id}"
    with open(file_path, "rb") as image:
        image_content = image.read()
    # Read the file into memory
    document = {"content": image_content, "mime_type": "application/pdf"}
    # Configure the process request
    request = {"name": name, "raw_document": document}
    # Recognizes text entities in the PDF document
    result = client.process_document(request=request)
    document = result.document
    print("Document processing complete.")
    # For a full list of Document object attributes, please reference this page: https://googleapis.dev/python/documentai/latest/_modules/google/cloud/documentai_v1beta3/types/document.html#Document
    document_pages = document.pages
    # Read the text recognition output from the processor
    text = document.text
    print("The document contains the following text (first 100 charactes):")
    print(text[:100])
    
    # Read the detected page split from the processor
    print("\nThe processor detected the following page split entities:")
    print_pages_split(text, document)
def print_pages_split(text: str, document: dict):
    
    Document AI identifies possible page splits
    in document. This function converts page splits
    to text snippets and prints it.    
    
    for i, entity in enumerate(document.entities):
        confidence = entity.confidence
        text_entity = ''
        for segment in entity.text_anchor.text_segments:
            start = segment.start_index
            end = segment.end_index
            text_entity += text[start:end]
        pages = [p.page for p in entity.page_anchor.page_refs]
        print(f"*** Entity number: {i}, Split Confidence: {confidence} ***")
        print(f"*** Pages numbers: {[p for p in pages]} ***\nText snippet: {text_entity[:100]}")
Explanation: Now let's define the function to process the document with Document AI Python client
End of explanation
process_document_sample(PROJECT_ID, LOCATION, PROCESSOR_ID, FILE_PATH)
Explanation: We can now run the processor on the sample multi-document pdf.
End of explanation
<END_TASK>