Spaces:
Runtime error
Runtime error
Download backend/app/services/ocr_processor.py from Vivek0912/GenAiEmailClassification: direct link, hf CLI and curl.
- Browser
- Download file 498 Bytes
-
https://huggingface.co/spaces/Vivek0912/GenAiEmailClassification/resolve/main/backend/app/services/ocr_processor.py
- Command line
-
hf download hf://spaces/Vivek0912/GenAiEmailClassification/backend/app/services/ocr_processor.py
-
curl -L -o ocr_processor.py https://huggingface.co/spaces/Vivek0912/GenAiEmailClassification/resolve/main/backend/app/services/ocr_processor.py
498 Bytes
| import pytesseract | |
| import pdfplumber | |
| from PIL import Image | |
| def extract_text_from_pdf(pdf_path: str) -> str: | |
| """Extracts text from a PDF file.""" | |
| text = "" | |
| with pdfplumber.open(pdf_path) as pdf: | |
| for page in pdf.pages: | |
| text += page.extract_text() + "\n" | |
| return text.strip() | |
| def extract_text_from_image(image_path: str) -> str: | |
| """Extracts text from an image file using OCR.""" | |
| image = Image.open(image_path) | |
| return pytesseract.image_to_string(image) | |