Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,7 +27,7 @@ def extract_text_from_pdf(file_path):
|
|
| 27 |
reader_pdf = PdfReader(file_path)
|
| 28 |
text = ""
|
| 29 |
for page in reader_pdf.pages:
|
| 30 |
-
t = page
|
| 31 |
if t:
|
| 32 |
text += t + "\n"
|
| 33 |
return text.strip()
|
|
@@ -40,9 +40,12 @@ def extract_text_from_scanned_pdf(file_path):
|
|
| 40 |
pages = convert_from_path(file_path, dpi=150)
|
| 41 |
text = ""
|
| 42 |
for page in pages:
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
| 46 |
return text.strip()
|
| 47 |
|
| 48 |
# -----------------------------
|
|
|
|
| 27 |
reader_pdf = PdfReader(file_path)
|
| 28 |
text = ""
|
| 29 |
for page in reader_pdf.pages:
|
| 30 |
+
t = getattr(page, 'extract_text', lambda: None)()
|
| 31 |
if t:
|
| 32 |
text += t + "\n"
|
| 33 |
return text.strip()
|
|
|
|
| 40 |
pages = convert_from_path(file_path, dpi=150)
|
| 41 |
text = ""
|
| 42 |
for page in pages:
|
| 43 |
+
try:
|
| 44 |
+
img_array = np.array(page)
|
| 45 |
+
result = reader.readtext(img_array, detail=0)
|
| 46 |
+
text += " ".join(result) + "\n"
|
| 47 |
+
except Exception as e:
|
| 48 |
+
print("OCR error on page:", e)
|
| 49 |
return text.strip()
|
| 50 |
|
| 51 |
# -----------------------------
|