Download core/pdf_processing.py from Salahin/Chat-PDF: direct link, hf CLI and curl.
- Browser
- Download file 761 Bytes
-
https://huggingface.co/spaces/Salahin/Chat-PDF/resolve/main/core/pdf_processing.py
- Command line
-
hf download hf://spaces/Salahin/Chat-PDF/core/pdf_processing.py
-
curl -L -o pdf_processing.py https://huggingface.co/spaces/Salahin/Chat-PDF/resolve/main/core/pdf_processing.py
761 Bytes
| from PyPDF2 import PdfReader | |
| import streamlit as st | |
| from langchain_text_splitters import RecursiveCharacterTextSplitter | |
| def get_pdf_text(pdf_docs): | |
| try: | |
| text = "" | |
| for pdf in pdf_docs: | |
| pdf_reader = PdfReader(pdf) | |
| for page in pdf_reader.pages: | |
| text += page.extract_text() | |
| return text | |
| except Exception as e: | |
| st.error(f"Error extracting text from PDF: {e}") | |
| return None | |
| def get_text_chunks(text): | |
| try: | |
| text_splitter = RecursiveCharacterTextSplitter(chunk_size=10000, chunk_overlap=1000) | |
| chunks = text_splitter.split_text(text) | |
| return chunks | |
| except Exception as e: | |
| st.error(f"Error splitting text into chunks: {e}") | |
| return None | |