ai-tutor-document-processor / how HEADdocument_processor.py
sesharaghav's picture
Make document processor ZeroGPU compatible
4c793dd
Raw History Blame Contribute Delete
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
}