diff --git a/README.md b/README.md index 586e1ad..1db7f51 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,21 @@ # file2text -read file and convert it's content to text, this modulde suport a lot of file types +this module read file and convert it's content to text, this modulde suports a lot of file types, like docx, xlsx, pptx, pdf, epub, mobi, txt, csv. -## Docx file -## Excel file -## powerpoint file -``` -python-pptx -``` -## text file -## Pdf file -## Epub file -## Mobi file +the chm and doc file not supported yet -## CHM file -1. Install libchm (if not already installed): +## Dependents +All dependented modules in requirements.txt -On Ubuntu/Debian: +## installation +Just run the following command ``` -sudo apt install libchm-bin libchm-dev +pip install git+https://git.kaiyuancloud.cn/yumoqing/file2text.git ``` -On macOS (with Homebrew): +## Usage +from file2text import fileloader -``` -brew install chmlib -``` -2. Install Python binding: - -Unfortunately, python-chm is not always available via PyPI. Instead, you might need to install it via your system package manager or from source. - -On Ubuntu/Debian: - -``` -sudo apt install python3-chm -``` - -If using macOS, you might need to build a wrapper manually (let me know if you need help with that). -📝 Notes: - - This extracts plain HTML text. You can clean it up using BeautifulSoup if needed. - - CHM files can contain a huge number of pages. Consider filtering by file path if needed. - -Would you like a version that returns cleaned text only (no HTML tags)? +text = fileloader(filepath) diff --git a/file2text/loader.py b/file2text/loader.py index 6b57ce6..6b4c6df 100644 --- a/file2text/loader.py +++ b/file2text/loader.py @@ -4,8 +4,8 @@ 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 +import python_doc +import CHM from ebooklib import epub from bs4 import BeautifulSoup from pptx import Presentation @@ -31,7 +31,7 @@ class MyChmLoader: def load(self): """Reads the CHM file and returns concatenated text from all text/html entries.""" - self.chm_file = chm.CHMFile(self.filepath) + self.chm_file = CHM.CHMFile(self.filepath) content = [] def callback(chm_item): @@ -68,7 +68,7 @@ class MyDocLoader: def load(self): """Extract plain text from a .doc file using python-doc.""" with open(self.filepath, 'rb') as f: - document = doc.Document(f) + document = python_doc.Document(f) return document.text() class MyDocxLoader: diff --git a/requirements.txt b/requirements.txt index 4eb265c..c3be2d8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,13 +1,9 @@ langchain_community unstructured pillow -# rapidocr-onnxruntime 从pdf文件中的图像中获取文字 -rapidocr-onnxruntime mobi html2text -chm python-docx -python-doc python-pptx openpyxl PyPDF2