Spaces:
Build error
Build error
Download fileconverter.py from CarolineDelva/TextScout2: direct link, hf CLI and curl.
- Browser
- Download file 447 Bytes
-
https://huggingface.co/spaces/CarolineDelva/TextScout2/resolve/main/fileconverter.py
- Command line
-
hf download hf://spaces/CarolineDelva/TextScout2/fileconverter.py
-
curl -L -o fileconverter.py https://huggingface.co/spaces/CarolineDelva/TextScout2/resolve/main/fileconverter.py
447 Bytes
| import docx2txt | |
| import PyPDF2 | |
| def convert_docx_file_to_txt_file(docx_path): | |
| text = docx2txt.process(docx_path) | |
| return text | |
| def convert_pdf_file_to_txt_file(pdf_path): | |
| with open(pdf_path, 'rb') as pdf_file: | |
| pdf_reader = PyPDF2.PdfReader(pdf_file) | |
| text = "" | |
| for page_num in range(len(pdf_reader.pages)): | |
| page = pdf_reader.pages[page_num] | |
| text += page.extract_text() | |
| return text | |