Spaces:
Sleeping
Sleeping
Download src/agents/text_agent.py from NandiniKodali/docpipe: direct link, hf CLI and curl.
- Browser
- Download file 673 Bytes
-
https://huggingface.co/spaces/NandiniKodali/docpipe/resolve/main/src/agents/text_agent.py
- Command line
-
hf download hf://spaces/NandiniKodali/docpipe/src/agents/text_agent.py
-
curl -L -o text_agent.py https://huggingface.co/spaces/NandiniKodali/docpipe/resolve/main/src/agents/text_agent.py
673 Bytes
| from pathlib import Path | |
| class TextAgent: | |
| SUPPORTED_EXTENSIONS = {".txt", ".md", ".rst"} | |
| def process(self, file_path: Path) -> dict: | |
| content = file_path.read_text(encoding="utf-8", errors="replace") | |
| if file_path.suffix == ".txt": | |
| title = file_path.stem.replace("_", " ").replace("-", " ") | |
| markdown = f"# {title}\n\n{content}" | |
| else: | |
| markdown = content | |
| return { | |
| "markdown": markdown, | |
| "metadata": { | |
| "source_file": str(file_path), | |
| "file_type": file_path.suffix.lstrip("."), | |
| "title": file_path.stem, | |
| }, | |
| } | |