bugfix
This commit is contained in:
parent
034fb514c4
commit
2854849729
@ -4,6 +4,7 @@ from datetime import datetime
|
|||||||
from langchain_community.document_loaders.csv_loader import CSVLoader
|
from langchain_community.document_loaders.csv_loader import CSVLoader
|
||||||
from langchain_community.document_loaders.text import TextLoader
|
from langchain_community.document_loaders.text import TextLoader
|
||||||
from docx import Document
|
from docx import Document
|
||||||
|
import doc
|
||||||
# import chm
|
# import chm
|
||||||
from ebooklib import epub
|
from ebooklib import epub
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
@ -60,7 +61,17 @@ class MyPdfLoader:
|
|||||||
text += page.extract_text() or ''
|
text += page.extract_text() or ''
|
||||||
return ' '.join(text.split('\t'))
|
return ' '.join(text.split('\t'))
|
||||||
|
|
||||||
class MyWordLoader:
|
class MyDocLoader:
|
||||||
|
def __init__(self, file_path):
|
||||||
|
self.filepath = file_path
|
||||||
|
|
||||||
|
def load(self):
|
||||||
|
"""Extract plain text from a .doc file using python-doc."""
|
||||||
|
with open(self.filepath, 'rb') as f:
|
||||||
|
document = doc.Document(f)
|
||||||
|
return document.text()
|
||||||
|
|
||||||
|
class MyDocxLoader:
|
||||||
def __init__(self, file_path):
|
def __init__(self, file_path):
|
||||||
self.filepath = file_path
|
self.filepath = file_path
|
||||||
self.document = None
|
self.document = None
|
||||||
@ -134,10 +145,11 @@ def fileloader(file_path):
|
|||||||
# Load the PDF file and split the data into chunks
|
# Load the PDF file and split the data into chunks
|
||||||
data = None
|
data = None
|
||||||
if file_path.lower().endswith('.pdf'):
|
if file_path.lower().endswith('.pdf'):
|
||||||
# loader = PyPDFLoader(file_path=file_path)
|
|
||||||
loader = MyPdfLoader(file_path=file_path)
|
loader = MyPdfLoader(file_path=file_path)
|
||||||
elif file_path.lower().endswith('.docx') or file_path.lower().endswith('.doc'):
|
elif file_path.lower().endswith('.docx'):
|
||||||
loader = MyWordLoader(file_path=file_path)
|
loader = MyDocxLoader(file_path=file_path)
|
||||||
|
elif file_path.lower().endswith('.doc'):
|
||||||
|
loader = MyDocLoader(file_path=file_path)
|
||||||
elif file_path.lower().endswith('.pptx') or file_path.lower().endswith('.pptx'):
|
elif file_path.lower().endswith('.pptx') or file_path.lower().endswith('.pptx'):
|
||||||
loader = MyPptLoader(file_path=file_path)
|
loader = MyPptLoader(file_path=file_path)
|
||||||
elif file_path.lower().endswith('.xlsx') or file_path.lower().endswith('.xls'):
|
elif file_path.lower().endswith('.xlsx') or file_path.lower().endswith('.xls'):
|
||||||
|
@ -7,6 +7,7 @@ mobi
|
|||||||
html2text
|
html2text
|
||||||
chm
|
chm
|
||||||
python-docx
|
python-docx
|
||||||
|
python-doc
|
||||||
python-pptx
|
python-pptx
|
||||||
openpyxl
|
openpyxl
|
||||||
PyPDF2
|
PyPDF2
|
||||||
|
Loading…
Reference in New Issue
Block a user