Spaces:
Runtime error
Runtime error
Download core/doc_processor.py from utkarsh134/FastAPI-Experience-Extractor: direct link, hf CLI and curl.
- Browser
- Download file 670 Bytes
-
https://huggingface.co/spaces/utkarsh134/FastAPI-Experience-Extractor/resolve/1fe46a05dbb5bdbb6066ed6c75c668e562f4e59a/core/doc_processor.py
- Command line
-
hf download hf://spaces/utkarsh134/FastAPI-Experience-Extractor@1fe46a05dbb5bdbb6066ed6c75c668e562f4e59a/core/doc_processor.py
-
curl -L -o doc_processor.py https://huggingface.co/spaces/utkarsh134/FastAPI-Experience-Extractor/resolve/1fe46a05dbb5bdbb6066ed6c75c668e562f4e59a/core/doc_processor.py
670 Bytes
| import pymupdf | |
| from io import BytesIO | |
| import docx2txt | |
| def extract_text_from_bytes(pdf_bytes): | |
| try: | |
| memory_stream = BytesIO(pdf_bytes) | |
| doc = pymupdf.open(stream=memory_stream, filetype="pdf") | |
| text = "" | |
| for page in doc: | |
| text += page.get_text() | |
| doc.close() | |
| return text | |
| except Exception as e: | |
| return f"Error reading PDF: {str(e)}" | |
| def extract_text_from_docx(docx_bytes): | |
| try: | |
| docx_stream = BytesIO(docx_bytes) | |
| text = docx2txt.process(docx_stream) | |
| return text | |
| except Exception as e: | |
| return f"Error reading DOCX: {str(e)}" | |