bugfix
This commit is contained in:
parent
321cec19c8
commit
b030aab5b7
36
file2text/loader.py
Normal file
36
file2text/loader.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
from langchain_community.document_loaders.csv_loader import CSVLoader
|
||||||
|
from langchain_community.document_loaders.text import TextLoader
|
||||||
|
from langchain_community.document_loaders import UnstructuredPDFLoader
|
||||||
|
from langchain_community.document_loaders import UnstructuredWordDocumentLoader
|
||||||
|
from langchain_community.document_loaders import UnstructuredExcelLoader
|
||||||
|
from langchain_community.document_loaders import UnstructuredPowerPointLoader
|
||||||
|
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
||||||
|
|
||||||
|
def fileloader(file_path):
|
||||||
|
# Load the PDF file and split the data into chunks
|
||||||
|
data = None
|
||||||
|
if file_path.lower().endswith('.pdf'):
|
||||||
|
loader = UnstructuredPDFLoader(file_path=file_path)
|
||||||
|
elif file_path.lower().endswith('.docx') or file_path.lower().endswith('.doc'):
|
||||||
|
loader = UnstructuredWordDocumentLoader(file_path=file_path)
|
||||||
|
elif file_path.lower().endswith('.pptx') or file_path.lower().endswith('.pptx'):
|
||||||
|
loader = UnstructuredPowerPointLoader(file_path=file_path)
|
||||||
|
elif file_path.lower().endswith('.xlsx') or file_path.lower().endswith('.xls'):
|
||||||
|
loader = UnstructuredExcelLoader(file_path=file_path)
|
||||||
|
elif file_path.lower().endswith('.csv'):
|
||||||
|
loader = CSVLoader(file_path=file_path)
|
||||||
|
else:
|
||||||
|
loader = TextLoader(file_path=file_path)
|
||||||
|
data = loader.load()
|
||||||
|
return data
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import sys
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
print(f'{sys.argv[0]} file\nload a file and get its text')
|
||||||
|
sys.exit(1)
|
||||||
|
text = fileloader(sys.argv[1])
|
||||||
|
print(f'{text}')
|
||||||
|
|
Loading…
Reference in New Issue
Block a user