repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import hashlib |
| #2 | import importlib.util |
| #3 | |
| #4 | try: |
| #5 | import unstructured # noqa: F401 |
| #6 | from langchain_community.document_loaders import UnstructuredExcelLoader |
| #7 | except ImportError: |
| #8 | raise ImportError( |
| #9 | 'Excel file requires extra dependencies. Install with `pip install "unstructured[local-inference, all-docs]"`' |
| #10 | ) from None |
| #11 | |
| #12 | if importlib.util.find_spec("openpyxl") is None and importlib.util.find_spec("xlrd") is None: |
| #13 | raise ImportError("Excel file requires extra dependencies. Install with `pip install openpyxl xlrd`") from None |
| #14 | |
| #15 | from embedchain.helpers.json_serializable import register_deserializable |
| #16 | from embedchain.loaders.base_loader import BaseLoader |
| #17 | from embedchain.utils.misc import clean_string |
| #18 | |
| #19 | |
| #20 | @register_deserializable |
| #21 | class ExcelFileLoader(BaseLoader): |
| #22 | def load_data(self, excel_url): |
| #23 | """Load data from a Excel file.""" |
| #24 | loader = UnstructuredExcelLoader(excel_url) |
| #25 | pages = loader.load_and_split() |
| #26 | |
| #27 | data = [] |
| #28 | for page in pages: |
| #29 | content = page.page_content |
| #30 | content = clean_string(content) |
| #31 | |
| #32 | metadata = page.metadata |
| #33 | metadata["url"] = excel_url |
| #34 | |
| #35 | data.append({"content": content, "meta_data": metadata}) |
| #36 | |
| #37 | doc_id = hashlib.sha256((content + excel_url).encode()).hexdigest() |
| #38 | return { |
| #39 | "doc_id": doc_id, |
| #40 | "data": data, |
| #41 | } |
| #42 |