Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -23,11 +23,18 @@ def clean_text(text):
|
|
23 |
|
24 |
# Function to extract text from PDF files
|
25 |
def extract_text(pdf_file):
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
# Function to split text into chunks of a specified size
|
33 |
def split_text(text, chunk_size=1024):
|
|
|
23 |
|
24 |
# Function to extract text from PDF files
|
25 |
def extract_text(pdf_file):
|
26 |
+
try:
|
27 |
+
pdf_reader = PdfReader(pdf_file)
|
28 |
+
if pdf_reader.is_encrypted:
|
29 |
+
print(f"Skipping encrypted file: {pdf_file}")
|
30 |
+
return None
|
31 |
+
text = ''
|
32 |
+
for page in pdf_reader.pages:
|
33 |
+
text += page.extract_text() or ''
|
34 |
+
return text
|
35 |
+
except Exception as e:
|
36 |
+
print(f"Error extracting text from {pdf_file}: {e}")
|
37 |
+
return None
|
38 |
|
39 |
# Function to split text into chunks of a specified size
|
40 |
def split_text(text, chunk_size=1024):
|