Spaces:
Runtime error
Runtime error
File size: 523 Bytes
1400669 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | from __future__ import annotations
def chunk_text(text: str, chunk_size: int = 1200, overlap: int = 200) -> list[str]:
if not text:
return []
text = text.strip()
if chunk_size <= 0:
return [text]
chunks = []
start = 0
n = len(text)
while start < n:
end = min(start + chunk_size, n)
chunk = text[start:end].strip()
if chunk:
chunks.append(chunk)
if end == n:
break
start = max(0, end - overlap)
return chunks |