Use a unique name for the temp PDF generated

This commit is contained in:
sabaimran
2023-12-04 19:27:00 -05:00
parent d20746613a
commit d2ddbef08f

View File

@@ -3,6 +3,7 @@ import base64
import logging import logging
import os import os
from typing import List, Tuple from typing import List, Tuple
from datetime import datetime
# External Packages # External Packages
from langchain.document_loaders import PyMuPDFLoader from langchain.document_loaders import PyMuPDFLoader
@@ -66,7 +67,8 @@ class PdfToEntries(TextToEntries):
for pdf_file in pdf_files: for pdf_file in pdf_files:
try: try:
# Write the PDF file to a temporary file, as it is stored in byte format in the pdf_file object and the PDF Loader expects a file path # Write the PDF file to a temporary file, as it is stored in byte format in the pdf_file object and the PDF Loader expects a file path
tmp_file = f"tmp_pdf_file.pdf" timestamp_now = datetime.utcnow().timestamp()
tmp_file = f"tmp_pdf_file_{timestamp_now}.pdf"
with open(f"{tmp_file}", "wb") as f: with open(f"{tmp_file}", "wb") as f:
bytes = pdf_files[pdf_file] bytes = pdf_files[pdf_file]
f.write(bytes) f.write(bytes)