mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +00:00
Zander/online pdf loader (#984)
This commit is contained in:
parent
055a53c27f
commit
c2d1d903fa
130
docs/modules/document_loaders/examples/online_pdf.ipynb
Normal file
130
docs/modules/document_loaders/examples/online_pdf.ipynb
Normal file
File diff suppressed because one or more lines are too long
@ -49,6 +49,8 @@ There are a lot of different document loaders that LangChain supports. Below are
|
|||||||
|
|
||||||
`Gutenberg <./examples/gutenberg.html>`_: A walkthrough of how to load data from a Gutenberg ebook text.
|
`Gutenberg <./examples/gutenberg.html>`_: A walkthrough of how to load data from a Gutenberg ebook text.
|
||||||
|
|
||||||
|
`Online PDF <./examples/online_pdf.html>`_: A walkthrough of how to load data from an online PDF.
|
||||||
|
|
||||||
.. toctree::
|
.. toctree::
|
||||||
:maxdepth: 1
|
:maxdepth: 1
|
||||||
:glob:
|
:glob:
|
||||||
|
@ -14,6 +14,7 @@ from langchain.document_loaders.html import UnstructuredHTMLLoader
|
|||||||
from langchain.document_loaders.imsdb import IMSDbLoader
|
from langchain.document_loaders.imsdb import IMSDbLoader
|
||||||
from langchain.document_loaders.notion import NotionDirectoryLoader
|
from langchain.document_loaders.notion import NotionDirectoryLoader
|
||||||
from langchain.document_loaders.obsidian import ObsidianLoader
|
from langchain.document_loaders.obsidian import ObsidianLoader
|
||||||
|
from langchain.document_loaders.online_pdf import OnlinePDFLoader
|
||||||
from langchain.document_loaders.paged_pdf import PagedPDFSplitter
|
from langchain.document_loaders.paged_pdf import PagedPDFSplitter
|
||||||
from langchain.document_loaders.pdf import UnstructuredPDFLoader
|
from langchain.document_loaders.pdf import UnstructuredPDFLoader
|
||||||
from langchain.document_loaders.powerpoint import UnstructuredPowerPointLoader
|
from langchain.document_loaders.powerpoint import UnstructuredPowerPointLoader
|
||||||
@ -52,4 +53,5 @@ __all__ = [
|
|||||||
"GutenbergLoader",
|
"GutenbergLoader",
|
||||||
"PagedPDFSplitter",
|
"PagedPDFSplitter",
|
||||||
"EveryNoteLoader",
|
"EveryNoteLoader",
|
||||||
|
"OnlinePDFLoader",
|
||||||
]
|
]
|
||||||
|
29
langchain/document_loaders/online_pdf.py
Normal file
29
langchain/document_loaders/online_pdf.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
"""Loader that loads online PDF files."""
|
||||||
|
|
||||||
|
import tempfile
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
import requests
|
||||||
|
|
||||||
|
from langchain.docstore.document import Document
|
||||||
|
from langchain.document_loaders.base import BaseLoader
|
||||||
|
from langchain.document_loaders.pdf import UnstructuredPDFLoader
|
||||||
|
|
||||||
|
|
||||||
|
class OnlinePDFLoader(BaseLoader):
|
||||||
|
"""Loader that loads online PDFs."""
|
||||||
|
|
||||||
|
def __init__(self, web_path: str):
|
||||||
|
"""Initialize with file path."""
|
||||||
|
self.web_path = web_path
|
||||||
|
|
||||||
|
def load(self) -> List[Document]:
|
||||||
|
"""Load documents."""
|
||||||
|
r = requests.get(self.web_path)
|
||||||
|
with tempfile.TemporaryDirectory() as temp_dir:
|
||||||
|
file_path = f"{temp_dir}/online_file.pdf"
|
||||||
|
file = open(file_path, "wb")
|
||||||
|
file.write(r.content)
|
||||||
|
file.close()
|
||||||
|
loader = UnstructuredPDFLoader(file_path)
|
||||||
|
return loader.load()
|
Loading…
Reference in New Issue
Block a user