Spaces:
Paused
Paused
Download src/file_loader.py from Ephraimmm/Avatar-chat: direct link, hf CLI and curl.
- Browser
- Download file 544 Bytes
-
https://huggingface.co/spaces/Ephraimmm/Avatar-chat/resolve/main/src/file_loader.py
- Command line
-
hf download hf://spaces/Ephraimmm/Avatar-chat/src/file_loader.py
-
curl -L -o file_loader.py https://huggingface.co/spaces/Ephraimmm/Avatar-chat/resolve/main/src/file_loader.py
544 Bytes
| from functools import lru_cache | |
| from pypdf import PdfReader | |
| def load_pdf_text(path: str) -> str: | |
| text = "" | |
| try: | |
| reader = PdfReader(path) | |
| for page in reader.pages: | |
| page_text = page.extract_text() | |
| if page_text: | |
| text += page_text | |
| except: | |
| return "" | |
| return text | |
| def load_text_file(path: str) -> str: | |
| try: | |
| with open(path, "r", encoding="utf-8") as f: | |
| return f.read() | |
| except: | |
| return "" |