Download how HEADdocument_processor.py from sesharaghav/ai-tutor-document-processor: direct link, hf CLI and curl.
- Browser
- Download file 800 Bytes
-
https://huggingface.co/spaces/sesharaghav/ai-tutor-document-processor/resolve/main/how%20HEAD%EF%80%BAdocument_processor.py
- Command line
-
hf download 'hf://spaces/sesharaghav/ai-tutor-document-processor/how HEADdocument_processor.py'
-
curl -L -o 'how HEADdocument_processor.py' https://huggingface.co/spaces/sesharaghav/ai-tutor-document-processor/resolve/main/how%20HEAD%EF%80%BAdocument_processor.py
800 Bytes
| from pathlib import Path | |
| import fitz | |
| class DocumentProcessor: | |
| def process(self, file_path): | |
| path = Path(file_path) | |
| if path.suffix.lower() != ".pdf": | |
| raise ValueError( | |
| f"Unsupported file type: {path.suffix}" | |
| ) | |
| return self.process_pdf(path) | |
| def process_pdf(self, path): | |
| document = fitz.open(path) | |
| pages = [] | |
| for page_number, page in enumerate(document): | |
| pages.append({ | |
| "page_number": page_number + 1, | |
| "text": page.get_text() | |
| }) | |
| return { | |
| "document": { | |
| "filename": path.name, | |
| "format": "pdf", | |
| "page_count": len(document) | |
| }, | |
| "pages": pages | |
| } |