MathPixPDFLoader
Inspired by Daniel Gross's snippet here:https://gist.github.com/danielgross/3ab4104e14faccc12b49200843adab21
Overview
Integration details
Class | Package | Local | Serializable | JS support |
---|---|---|---|---|
MathPixPDFLoader | langchain_community | ✅ | ❌ | ❌ |
Loader features
Source | Document Lazy Loading | Native Async Support |
---|---|---|
MathPixPDFLoader | ✅ | ❌ |
Setup
Credentials
Sign up for Mathpix andcreate an API key to set theMATHPIX_API_KEY
variables in your environment
import getpass
import os
if"MATHPIX_API_KEY"notin os.environ:
os.environ["MATHPIX_API_KEY"]= getpass.getpass("Enter your Mathpix API key: ")
To enable automated tracing of your model calls, set yourLangSmith API key:
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
# os.environ["LANGSMITH_TRACING"] = "true"
Installation
Installlangchain_community.
%pip install-qU langchain_community
Initialization
Now we are ready to initialize our loader:
from langchain_community.document_loadersimport MathpixPDFLoader
file_path="./example_data/layout-parser-paper.pdf"
loader= MathpixPDFLoader(file_path)
API Reference:MathpixPDFLoader
Load
docs= loader.load()
docs[0]
print(docs[0].metadata)
Lazy Load
page=[]
for docin loader.lazy_load():
page.append(doc)
iflen(page)>=10:
# do some paged operation, e.g.
# index.upsert(page)
page=[]
API reference
For detailed documentation of all MathpixPDFLoader features and configurations head to the API reference:https://python.langchain.com/api_reference/community/document_loaders/langchain_community.document_loaders.pdf.MathpixPDFLoader.html
Related
- Document loaderconceptual guide
- Document loaderhow-to guides