mirror of https://github.com/hwchase17/langchain
Harrison/remote paths pdf (#1544)
Co-authored-by: Tim Asp <707699+timothyasp@users.noreply.github.com>pull/1509/head
parent
cc423f40f1
commit
357d808484
@ -1,30 +1,15 @@
|
||||
"""Loader that loads online PDF files."""
|
||||
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
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
|
||||
from langchain.document_loaders.pdf import BasePDFLoader, UnstructuredPDFLoader
|
||||
|
||||
|
||||
class OnlinePDFLoader(BaseLoader):
|
||||
class OnlinePDFLoader(BasePDFLoader):
|
||||
"""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 = Path(temp_dir) / "online_file.pdf"
|
||||
file = open(file_path, "wb")
|
||||
file.write(r.content)
|
||||
file.close()
|
||||
loader = UnstructuredPDFLoader(str(file_path))
|
||||
return loader.load()
|
||||
loader = UnstructuredPDFLoader(str(self.file_path))
|
||||
return loader.load()
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue