Shreyas094 commited on
Commit
412b763
1 Parent(s): 58569df

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -125,9 +125,14 @@ def load_document(file: NamedTemporaryFile, parser: str = "pypdf") -> List[Docum
125
  loader = PyPDFLoader(file.name)
126
  return loader.load_and_split()
127
  elif parser == "llamaparse":
128
- documents = llama_parser.load_data(file.name)
129
- # Convert LlamaParse output to langchain Document format
130
- return [Document(page_content=doc.text, metadata={"source": file.name}) for doc in documents]
 
 
 
 
 
131
  else:
132
  raise ValueError("Invalid parser specified. Use 'pypdf' or 'llamaparse'.")
133
 
 
125
  loader = PyPDFLoader(file.name)
126
  return loader.load_and_split()
127
  elif parser == "llamaparse":
128
+ try:
129
+ documents = llama_parser.load_data(file.name)
130
+ return [Document(page_content=doc.text, metadata={"source": file.name}) for doc in documents]
131
+ except Exception as e:
132
+ print(f"Error using Llama Parse: {str(e)}")
133
+ print("Falling back to PyPDF parser")
134
+ loader = PyPDFLoader(file.name)
135
+ return loader.load_and_split()
136
  else:
137
  raise ValueError("Invalid parser specified. Use 'pypdf' or 'llamaparse'.")
138