import tempfile import os from llama_parse import LlamaParse from llama_index.core.node_parser import SimpleNodeParser class JournalUploader: def __init__(self): pass def parser_journal(self): if local_file_name is None: local_file_name = "downloaded_pdf_file.pdf" # Default file name try: # Create a temporary directory to store the file temp_dir = tempfile.mkdtemp() file_path = os.path.join(temp_dir, local_file_name) with open(file_path, 'wb') as temp_file: self.s3_client.download_fileobj(self.bucket_name, object_name, temp_file) documents = LlamaParse(result_type="markdown").load_data(file_path) return documents except Exception as e: # Handle specific exceptions or fallback to generic one print(f"Error reading PDF file: {e}") raise RuntimeError(f"Failed to process the uploaded file: {e}")