-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from LyzrCore/change-pdf-parser
changed pdf parser to Layout Pdf Parser
- Loading branch information
Showing
12 changed files
with
146 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
from typing import List | ||
|
||
from langchain.document_loaders import PDFMinerLoader | ||
from llmsherpa.readers import LayoutPDFReader | ||
from llama_index.readers.base import BaseReader | ||
from llama_index.schema import Document | ||
|
||
|
||
class LyzrPDFReader(BaseReader): | ||
def __init__(self) -> None: | ||
try: | ||
from pdfminer.high_level import extract_text | ||
from llmsherpa.readers import LayoutPDFReader | ||
except ImportError: | ||
raise ImportError( | ||
"`pdfminer` package not found, please install it with " | ||
"`pip install pdfminer.six`" | ||
"`llmsherpa` package not found, please install it with " | ||
"`pip install llmsherpa`" | ||
) | ||
|
||
def load_data(self, file_path: str, extra_info: dict = None) -> List[Document]: | ||
loader = PDFMinerLoader(str(file_path)) | ||
langchain_documents = loader.load() | ||
llmsherpa_api_url = "https://readers.llmsherpa.com/api/document/developer/parseDocument?renderFormat=all" | ||
loader = LayoutPDFReader(llmsherpa_api_url) | ||
|
||
doc = loader.read_pdf(str(file_path)) | ||
metadata = {"source": str(file_path)} | ||
documents = [] | ||
for langchain_document in langchain_documents: | ||
doc = Document.from_langchain_format(langchain_document) | ||
|
||
if extra_info is not None: | ||
doc.metadata.update(extra_info) | ||
|
||
documents.append(doc) | ||
for chunk in doc.chunks(): | ||
document = Document(text=chunk.to_context_text(), metadata=metadata) | ||
documents.append(document) | ||
|
||
return documents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file renamed
BIN
+46.7 KB
dist/lyzr-0.1.23-py3-none-any.whl → dist/lyzr-0.1.24-py3-none-any.whl
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
asyncio | ||
nest_asyncio | ||
openai==1.3.4 | ||
beautifulsoup4==4.12.2 | ||
langchain==0.0.339 | ||
litellm==1.2.0 | ||
llama-index==0.9.4 | ||
langchain==0.0.339 | ||
python-dotenv>=1.0.0 | ||
beautifulsoup4==4.12.2 | ||
pandas==2.0.2 | ||
matplotlib==3.8.2 | ||
nest_asyncio | ||
openai==1.3.4 | ||
pandas==2.0.2 | ||
python-dotenv>=1.0.0 | ||
weaviate-client==3.25.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,29 @@ | ||
from typing import List | ||
|
||
from langchain.document_loaders import PDFMinerLoader | ||
from llmsherpa.readers import LayoutPDFReader | ||
from llama_index.readers.base import BaseReader | ||
from llama_index.schema import Document | ||
|
||
|
||
class LyzrPDFReader(BaseReader): | ||
def __init__(self) -> None: | ||
try: | ||
from pdfminer.high_level import extract_text | ||
from llmsherpa.readers import LayoutPDFReader | ||
except ImportError: | ||
raise ImportError( | ||
"`pdfminer` package not found, please install it with " | ||
"`pip install pdfminer.six`" | ||
"`llmsherpa` package not found, please install it with " | ||
"`pip install llmsherpa`" | ||
) | ||
|
||
def load_data(self, file_path: str, extra_info: dict = None) -> List[Document]: | ||
loader = PDFMinerLoader(str(file_path)) | ||
langchain_documents = loader.load() | ||
llmsherpa_api_url = "https://readers.llmsherpa.com/api/document/developer/parseDocument?renderFormat=all" | ||
loader = LayoutPDFReader(llmsherpa_api_url) | ||
|
||
doc = loader.read_pdf(str(file_path)) | ||
metadata = {"source": str(file_path)} | ||
documents = [] | ||
for langchain_document in langchain_documents: | ||
doc = Document.from_langchain_format(langchain_document) | ||
|
||
if extra_info is not None: | ||
doc.metadata.update(extra_info) | ||
|
||
documents.append(doc) | ||
for chunk in doc.chunks(): | ||
document = Document(text=chunk.to_context_text(), metadata=metadata) | ||
documents.append(document) | ||
|
||
return documents |
Oops, something went wrong.