Mavhas commited on
Commit
044b536
·
verified ·
1 Parent(s): 0adcf3b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -7,14 +7,18 @@ from langchain.vectorstores import FAISS
7
  import os
8
  from groq import Groq
9
  from io import BytesIO
 
10
 
11
- # Load PDF (with error handling)
12
  def load_pdf(uploaded_file):
13
  try:
14
  bytes_data = uploaded_file.getvalue()
15
- pdf_buffer = BytesIO(bytes_data)
16
- loader = PyPDFLoader(pdf_buffer)
 
 
17
  documents = loader.load()
 
18
  return documents
19
  except Exception as e:
20
  st.error(f"Error loading PDF: {e}")
 
7
  import os
8
  from groq import Groq
9
  from io import BytesIO
10
+ import tempfile
11
 
12
+ # Load PDF (Corrected)
13
  def load_pdf(uploaded_file):
14
  try:
15
  bytes_data = uploaded_file.getvalue()
16
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as temp_file:
17
+ temp_file.write(bytes_data)
18
+ temp_file_path = temp_file.name
19
+ loader = PyPDFLoader(temp_file_path)
20
  documents = loader.load()
21
+ os.remove(temp_file_path) # Clean up
22
  return documents
23
  except Exception as e:
24
  st.error(f"Error loading PDF: {e}")