Spaces:
Runtime error
Runtime error
Download src/chunking.py from MuhammadAzfar/ResearchMind-AI: direct link, hf CLI and curl.
- Browser
- Download file 788 Bytes
-
https://huggingface.co/spaces/MuhammadAzfar/ResearchMind-AI/resolve/main/src/chunking.py
- Command line
-
hf download hf://spaces/MuhammadAzfar/ResearchMind-AI/src/chunking.py
-
curl -L -o chunking.py https://huggingface.co/spaces/MuhammadAzfar/ResearchMind-AI/resolve/main/src/chunking.py
788 Bytes
| from langchain_text_splitters import RecursiveCharacterTextSplitter | |
| def split_text(text: str, chunk_size: int = 500, chunk_overlap: int = 100) -> list: | |
| """Splits raw input text into overlapping chunks using LangChain's RecursiveCharacterTextSplitter.""" | |
| if not text or not isinstance(text, str) or not text.strip(): | |
| print("[DEBUG WARNING] Empty or non-string input passed to split_text.") | |
| return [] | |
| try: | |
| splitter = RecursiveCharacterTextSplitter( | |
| chunk_size=chunk_size, | |
| chunk_overlap=chunk_overlap, | |
| separators=["\n\n", "\n", " ", ""] | |
| ) | |
| chunks = splitter.split_text(text) | |
| return chunks | |
| except Exception as e: | |
| print(f"[DEBUG ERROR] Failed to split text: {e}") | |
| return [] |