bugfix
This commit is contained in:
parent
2854849729
commit
6e7398448b
47
README.md
47
README.md
@ -1,48 +1,21 @@
|
|||||||
# file2text
|
# 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
|
the chm and doc file not supported yet
|
||||||
## Excel file
|
|
||||||
## powerpoint file
|
|
||||||
```
|
|
||||||
python-pptx
|
|
||||||
```
|
|
||||||
## text file
|
|
||||||
## Pdf file
|
|
||||||
## Epub file
|
|
||||||
## Mobi file
|
|
||||||
|
|
||||||
## CHM file
|
## Dependents
|
||||||
1. Install libchm (if not already installed):
|
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:
|
text = fileloader(filepath)
|
||||||
|
|
||||||
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)?
|
|
||||||
|
@ -4,8 +4,8 @@ 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 python_doc
|
||||||
# import chm
|
import CHM
|
||||||
from ebooklib import epub
|
from ebooklib import epub
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from pptx import Presentation
|
from pptx import Presentation
|
||||||
@ -31,7 +31,7 @@ class MyChmLoader:
|
|||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
"""Reads the CHM file and returns concatenated text from all text/html entries."""
|
"""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 = []
|
content = []
|
||||||
|
|
||||||
def callback(chm_item):
|
def callback(chm_item):
|
||||||
@ -68,7 +68,7 @@ class MyDocLoader:
|
|||||||
def load(self):
|
def load(self):
|
||||||
"""Extract plain text from a .doc file using python-doc."""
|
"""Extract plain text from a .doc file using python-doc."""
|
||||||
with open(self.filepath, 'rb') as f:
|
with open(self.filepath, 'rb') as f:
|
||||||
document = doc.Document(f)
|
document = python_doc.Document(f)
|
||||||
return document.text()
|
return document.text()
|
||||||
|
|
||||||
class MyDocxLoader:
|
class MyDocxLoader:
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
langchain_community
|
langchain_community
|
||||||
unstructured
|
unstructured
|
||||||
pillow
|
pillow
|
||||||
# rapidocr-onnxruntime 从pdf文件中的图像中获取文字
|
|
||||||
rapidocr-onnxruntime
|
|
||||||
mobi
|
mobi
|
||||||
html2text
|
html2text
|
||||||
chm
|
|
||||||
python-docx
|
python-docx
|
||||||
python-doc
|
|
||||||
python-pptx
|
python-pptx
|
||||||
openpyxl
|
openpyxl
|
||||||
PyPDF2
|
PyPDF2
|
||||||
|
Loading…
Reference in New Issue
Block a user