ai-tutor-document-processor / document_processor.py
sesharaghav's picture
Add ZeroGPU support, normalizer, and schemas for HF Spaces deployment
53843a5
Raw History Blame Contribute Delete
1 kB
from pathlib import Path
from typing import Any, Dict
from docling.document_converter import DocumentConverter
class DocumentProcessor:
SUPPORTED_EXTENSIONS = {
".pdf",
".docx",
".pptx",
".html",
".htm",
".md",
".txt",
}
def __init__(self):
self.converter = DocumentConverter()
def process(
self,
file_path: str,
) -> Dict[str, Any]:
path = Path(file_path)
extension = path.suffix.lower()
if extension not in self.SUPPORTED_EXTENSIONS:
raise ValueError(
f"Unsupported file type: {extension}"
)
result = self.converter.convert(
str(path)
)
document = result.document
raw_json = document.export_to_dict()
markdown = document.export_to_markdown()
return {
"document": document,
"raw_json": raw_json,
"markdown": markdown,
}