Spaces:
Paused
Paused
Download src/readers/text.py from CGIAR/PERI-AI-dev: direct link, hf CLI and curl.
- Browser
- Download file 423 Bytes
-
https://huggingface.co/spaces/CGIAR/PERI-AI-dev/resolve/main/src/readers/text.py
- Command line
-
hf download hf://spaces/CGIAR/PERI-AI-dev/src/readers/text.py
-
curl -L -o text.py https://huggingface.co/spaces/CGIAR/PERI-AI-dev/resolve/main/src/readers/text.py
423 Bytes
| """Reader for plain text files: .txt, .md, .json, .do""" | |
| def read_text(file_path: str) -> list[dict]: | |
| try: | |
| with open(file_path, "r", encoding="utf-8", errors="replace") as f: | |
| text = f.read() | |
| if not text.strip(): | |
| return [] | |
| return [{"page": 1, "text": text.strip()}] | |
| except Exception as e: | |
| print(f"Warning: Could not read {file_path}: {e}") | |
| return [] | |