Package: doc-loader
doc_loaderWhat is itdoc_loader is a utility package for loading multiple types of documents in the form of images, it can be used to load images intoPillowornumpyformats and can load from in memory buffers as well as from file pathsMain FeaturesGeneral purpose document loader which accepts .png, .jpg, .jpeg, .pdf, .tiff, .tif formats and outputs list of either PIL.Image objects or list of numpy arraysHandles Password Protected PDF'sApplies Exif Orientation to .jpg and .png images if presentInput:fastapi.UploadFile,werkeug.FileStorageobject orstr(file path)Output: List of images as PIL objects or numpy arrayWhere to get itThe source code is currently hosted on GitHub at:https://github.com/CapgeminiInventIDE/doc_loaderBinary installers for the latest released version are available at thePython package indexpipinstalldoc_loaderDependenciesPillownumpypdf2image+ popplerutilsOPTIONALPyMuPDF+ MuPDFLicenseMozilla Public License 2.0Usagepip install doc_loaderIn your code where you need to you will be using doc_loader you can refer to below script as reference:fromdoc_loaderimportDocumentLoader,OutputTypefromwerkzeug.datastructuresimportFileStoragefromfastapiimportUploadFilepath="/opt/working/src/tests/data/tmp.png"# Open file using pathpage_count,document=DocumentLoader.load(path,max_num_pages=2,output_type=OutputType.NUMPY)print(page_count,document)# Open file using UploadFilewithopen(path,"rb")asfp:upload_file=UploadFile(path,fp)page_count,document=DocumentLoader.load(upload_file,max_num_pages=2,output_type=OutputType.NUMPY)print(page_count,document)# Open file using FileStoragewithopen(path,"rb")asfp:file_storage=FileStorage(fp,filename=path)page_count,document=DocumentLoader.load(file_storage,max_num_pages=2,output_type=OutputType.NUMPY)print(page_count,document)Optional featuresextract_text_pdf- allows you to get text from a searchable pdf if possible, otherwise will raise an error that can be handled, to use thispip install doc_loader[pdf_text_extract]fromdoc_loaderimportextract_text_pdffromwerkzeug.datastructuresimportFileStoragefromfastapiimportUploadFilepath="/opt/working/src/tests/data/is-doc-has-cgtext.pdf"# Open file using pathpage_count,document=extract_text_pdf(path,max_num_pages=2)print(page_count,document)# Open file using UploadFilewithopen(path,"rb")asfp:upload_file=UploadFile(path,fp)page_count,document=extract_text_pdf(upload_file,max_num_pages=2)print(page_count,document)# Open file using FileStoragewithopen(path,"rb")asfp:file_storage=FileStorage(fp,filename=path)page_count,document=extract_text_pdf(file_storage,max_num_pages=2)print(page_count,document)Contributing to doc_loaderTo contribute to doc_loader, follow these steps:Fork the repositoryCreate a branch in your own fork:git checkout -b <branch_name>.Make your changes and commit them:git commit -m '<commit_message>'Push to the original branch:git push origin <project_name>/<location>Create the pull request back to our fork.About UsCapgemini Invent combines strategy, technology, data science and creative design to solve the most complex business and technology challenges.Disruption is not new, but the pace of change is. The fourth industrial revolution is forcing businesses to rethink everything they know.Leading organizations behave as living entities, constantly adapting to change. With invention at their core, they continuously redesign their business to generate new sources of value. Winning is about fostering inventive thinking to create what comes next.Invent. Build. Transform.This is why we have created Capgemini Invent, Capgemini’s new digital innovation, consulting and transformation global business line. Our multi-disciplinary team helps business leaders find new sources of value. We accelerate the process of turning ideas into prototypes and scalable real-world solutions; leveraging the full business and technology expertise of the Capgemini Group to implement at speed and scale.The result is a coordinated approach to transformation, enabling businesses to create the products, services, customer experiences, and business models of the future.We're Hiring!Do you want to be part of the team that builds doc_loader andother great productsat Capgemini Invent? If so, you're in luck! Capgemini Invent is currently hiring Data Scientists who love using data to drive their decisions. Take a look atour open positionsand see if you're a fit.