31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
import logging
|
|
from ..document_handlers.document_factory import DocumentProcessorFactory
|
|
from ..services.ollama_client import OllamaClient
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
class DocumentService:
|
|
def __init__(self):
|
|
pass
|
|
|
|
def process_document(self, input_path: str, output_path: str) -> bool:
|
|
try:
|
|
processor = DocumentProcessorFactory.create_processor(input_path, output_path)
|
|
if not processor:
|
|
logger.error(f"Unsupported file format: {input_path}")
|
|
raise Exception(f"Unsupported file format: {input_path}")
|
|
|
|
# Read content
|
|
content = processor.read_content()
|
|
|
|
# Process with Ollama
|
|
masked_content = processor.process_content(content)
|
|
|
|
# Save processed content
|
|
processor.save_content(masked_content)
|
|
return True
|
|
|
|
except Exception as e:
|
|
logger.error(f"Error processing document {input_path}: {str(e)}")
|
|
# Re-raise the exception so the Celery task can handle it properly
|
|
raise |