This commit is contained in:
yumoqing 2025-05-13 17:05:30 +08:00
parent 034fb514c4
commit 2854849729
2 changed files with 17 additions and 4 deletions

View File

@ -4,6 +4,7 @@ from datetime import datetime
from langchain_community.document_loaders.csv_loader import CSVLoader
from langchain_community.document_loaders.text import TextLoader
from docx import Document
import doc
# import chm
from ebooklib import epub
from bs4 import BeautifulSoup
@ -60,7 +61,17 @@ class MyPdfLoader:
text += page.extract_text() or ''
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):
self.filepath = file_path
self.document = None
@ -134,10 +145,11 @@ def fileloader(file_path):
# Load the PDF file and split the data into chunks
data = None
if file_path.lower().endswith('.pdf'):
# loader = PyPDFLoader(file_path=file_path)
loader = MyPdfLoader(file_path=file_path)
elif file_path.lower().endswith('.docx') or file_path.lower().endswith('.doc'):
loader = MyWordLoader(file_path=file_path)
elif file_path.lower().endswith('.docx'):
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'):
loader = MyPptLoader(file_path=file_path)
elif file_path.lower().endswith('.xlsx') or file_path.lower().endswith('.xls'):

View File

@ -7,6 +7,7 @@ mobi
html2text
chm
python-docx
python-doc
python-pptx
openpyxl
PyPDF2