Spaces:
Sleeping
Sleeping
Download pdf_parser.py from ArielKes/RoutePlannerApp: direct link, hf CLI and curl.
- Browser
- Download file 693 Bytes
-
https://huggingface.co/spaces/ArielKes/RoutePlannerApp/resolve/main/pdf_parser.py
- Command line
-
hf download hf://spaces/ArielKes/RoutePlannerApp/pdf_parser.py
-
curl -L -o pdf_parser.py https://huggingface.co/spaces/ArielKes/RoutePlannerApp/resolve/main/pdf_parser.py
693 Bytes
| import pdfplumber | |
| from bidi.algorithm import get_display | |
| def extract_text_from_pdf(data_path): | |
| """Extract text from a PDF using pdfplumber.""" | |
| pdfplumber_text = [] | |
| with pdfplumber.open(data_path) as pdf: | |
| for page in pdf.pages: | |
| pdfplumber_text.append(page.extract_text()) | |
| return "\n".join(pdfplumber_text) | |
| def fix_hebrew_lines(text): | |
| """Reverse lines that contain Hebrew characters (for RTL display).""" | |
| return get_display(text) | |
| def process_pdf_hebrew_rtl(data_path): | |
| """Full pipeline: extract from PDF and fix RTL issues.""" | |
| raw_text = extract_text_from_pdf(data_path) | |
| fixed_text = fix_hebrew_lines(raw_text) | |
| return fixed_text | |