Chan-Y commited on
Commit
28f0884
1 Parent(s): dc3c24e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -20,12 +20,18 @@ llm = HuggingFaceEndpoint(
20
  llm_engine_hf = ChatHuggingFace(llm=llm)
21
 
22
  def read_pdf(file_path):
23
- pdf_reader = PyPDF2.PdfReader(file_path)
24
- text = ""
25
- for page in range(len(pdf_reader.pages)):
26
- text += pdf_reader.pages[page].extract_text()
27
- return text
 
 
 
 
 
28
  def read_txt(file_path):
 
29
  with open(file_path, "r", encoding="utf-8") as f:
30
  text = f.read()
31
  return text
 
20
  llm_engine_hf = ChatHuggingFace(llm=llm)
21
 
22
  def read_pdf(file_path):
23
+ print("It is a PDF file")
24
+ try:
25
+ pdf_reader = PyPDF2.PdfReader(file_path)
26
+ text = ""
27
+ for page in range(len(pdf_reader.pages)):
28
+ text += pdf_reader.pages[page].extract_text()
29
+ return text
30
+ except Exception as e:
31
+ print("Error reading file, ", e)
32
+
33
  def read_txt(file_path):
34
+ print("It is not a PDF file")
35
  with open(file_path, "r", encoding="utf-8") as f:
36
  text = f.read()
37
  return text