https://www.boundaryml.com logo
🟑 Not sure where to put this, but I need to extra...
# questions
b
Not sure where to put this, but I need to extract information from a PDF or scan there of. And need to know where / bounding box this information came from. Has anyone done this before with BAML?
a
Unfortunately if I recall correctly all of our PDF handling comes from the individual model providers (we don’t extract text or run OCR, just leave it up to Anthropic, OpenAI, etc)
i think something like pypdf (or any other PDF library) would be able to extract text with bounding box and then you could feed that into BAML for classification
anything with OCR (from a scan) would be much more finicky because the grouping of the text is up to the algorithm
p
I'm processing PDFs with llamacloud parse to get OCR/bboxes and then using BAML with the results. Works great!
b
ah okay so something like
Copy code
import json

# Initialize the parser and ensure it returns JSON
parser = LlamaParse(
    api_key="your-llama-cloud-api-key",
    result_type="json" # Crucial to get bbox and spatial data
)

# Parse the document
document_json = parser.get_json_results("your_document.pdf")

# Access the bounding box of the first text item/page
for page in document_json[0]['pages']:
    for item in page.get('items', []):
        content_type = item.get('type')
        bbox_coords = item.get('bbox')
        
        print(f"Type: {content_type}")
        print(f"Bounding Box: {bbox_coords}")
@phren0logy ? Unfortunately, because compliance etc. I can not use any non german cloud, or service provider so llamacloud is out of the game
I will give it a try with Gemma4, and ask it to spit out coordinates, I will report here, once I get something working
p
I also got good results from Aure Docment Intelligence using the Layout model
b
yeah, also a Azure --> Microsoft --> US Company. And everything that touches the US Clout Act, is not compliant for my use case, which is stupid, to say the least because it slows things down a lot, and I can just google a solution for these things πŸ˜‰
p
@User For local processing, check out liteparse, which can use whatever OCR engine you like. Docling is also pretty good, but I had trouble getting it to scale.