Spaces:
Sleeping
Sleeping
File size: 1,023 Bytes
9002555 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
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}")
|