Download augmentoolkit/utils/head_tail_truncate.py from Leon4gr45/agent-0: direct link, hf CLI and curl.
- Browser
- Download file 432 Bytes
-
https://huggingface.co/spaces/Leon4gr45/agent-0/resolve/main/augmentoolkit/utils/head_tail_truncate.py
- Command line
-
hf download hf://spaces/Leon4gr45/agent-0/augmentoolkit/utils/head_tail_truncate.py
-
curl -L -o head_tail_truncate.py https://huggingface.co/spaces/Leon4gr45/agent-0/resolve/main/augmentoolkit/utils/head_tail_truncate.py
432 Bytes
| import math | |
| def head_tail_truncate(text, max_length=510): | |
| """ | |
| Truncate the text using the head+tail method. | |
| Keep the first head_length characters and the last (max_length - head_length) characters. | |
| """ | |
| head_length = math.floor(0.2 * max_length) | |
| tail_length = max_length - head_length | |
| if len(text) <= max_length: | |
| return text | |
| return text[:head_length] + text[-(tail_length - head_length) :] | |