Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -20,12 +20,18 @@ llm = HuggingFaceEndpoint(
|
|
20 |
llm_engine_hf = ChatHuggingFace(llm=llm)
|
21 |
|
22 |
def read_pdf(file_path):
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
text
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
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
|