Download agentcourse_unit4/tools/pdf_reader.py from mrpe24/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 547 Bytes
-
https://huggingface.co/spaces/mrpe24/Final_Assignment_Template/resolve/main/agentcourse_unit4/tools/pdf_reader.py
- Command line
-
hf download hf://spaces/mrpe24/Final_Assignment_Template/agentcourse_unit4/tools/pdf_reader.py
-
curl -L -o pdf_reader.py https://huggingface.co/spaces/mrpe24/Final_Assignment_Template/resolve/main/agentcourse_unit4/tools/pdf_reader.py
547 Bytes
| from pdfminer.high_level import extract_text | |
| from smolagents import Tool | |
| class PdfReaderTool(Tool): | |
| name = "pdf_reader" | |
| description = "Extract PDF content. Supported file extensions: .pdf" | |
| inputs = { | |
| "file_path": { | |
| "type": "string", | |
| "description": "Path to the PDF file", | |
| } | |
| } | |
| output_type = "string" | |
| def forward(self, file_path) -> str: | |
| try: | |
| return extract_text(file_path) | |
| except Exception as e: | |
| return f"Error processing PDF file: {str(e)}" | |