Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2215,13 +2215,33 @@ def _parse_nfcu_page(pdf_path: str, page_num: int) -> str:
|
|
| 2215 |
Returns complete HTML string for the page, or "" if not NFCU / any error.
|
| 2216 |
"""
|
| 2217 |
try:
|
| 2218 |
-
|
| 2219 |
-
|
| 2220 |
-
|
| 2221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2222 |
return ""
|
| 2223 |
-
|
| 2224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2225 |
|
| 2226 |
if not text:
|
| 2227 |
return ""
|
|
|
|
| 2215 |
Returns complete HTML string for the page, or "" if not NFCU / any error.
|
| 2216 |
"""
|
| 2217 |
try:
|
| 2218 |
+
# Extract full page text using pymupdf (installed on HuggingFace) or
|
| 2219 |
+
# pdfplumber (installed locally) — try both so the function works in
|
| 2220 |
+
# either environment.
|
| 2221 |
+
text = ""
|
| 2222 |
+
try:
|
| 2223 |
+
import pymupdf as _fitz_nf
|
| 2224 |
+
_doc_nf = _fitz_nf.open(pdf_path)
|
| 2225 |
+
if page_num >= len(_doc_nf):
|
| 2226 |
+
_doc_nf.close()
|
| 2227 |
return ""
|
| 2228 |
+
text = _doc_nf[page_num].get_text() or ""
|
| 2229 |
+
_doc_nf.close()
|
| 2230 |
+
except Exception:
|
| 2231 |
+
pass
|
| 2232 |
+
|
| 2233 |
+
if not text:
|
| 2234 |
+
try:
|
| 2235 |
+
import pdfplumber as _plumber_nf
|
| 2236 |
+
with _plumber_nf.open(pdf_path) as _pdf_nf:
|
| 2237 |
+
if page_num >= len(_pdf_nf.pages):
|
| 2238 |
+
return ""
|
| 2239 |
+
text = _pdf_nf.pages[page_num].extract_text() or ""
|
| 2240 |
+
except Exception:
|
| 2241 |
+
pass
|
| 2242 |
+
|
| 2243 |
+
if not text:
|
| 2244 |
+
return ""
|
| 2245 |
|
| 2246 |
if not text:
|
| 2247 |
return ""
|