CV_Reviewer / utils /process_doc.py
Jonah Ramponi
commiting day1
22be37d
raw
history blame
726 Bytes
"""
Script for processing an input CV document
"""
import io
import fitz
from docx import Document
def parse_pdf(pdf_file) -> str:
"""Read PDF from Streamlit's file uploader"""
pdf_document = fitz.open("pdf", pdf_file)
all_text = []
for page_number in range(len(pdf_document)):
page = pdf_document.load_page(page_number)
all_text.append(page.get_text("text"))
pdf_document.close()
return "\n\n".join(all_text)
def parse_docx(docx_file):
"""Read in docx file"""
docx_file = io.BytesIO(docx_file)
document = Document(docx_file)
all_text = []
for paragraph in document.paragraphs:
all_text.append(paragraph.text)
return "\n".join(all_text)