Spaces:
Sleeping
Sleeping
Update app.py
Browse files4 unmodified lines567889101116 unmodified lines2829303132333435363738394041423132333435363745383940179 unmodified lines2202212222312232242252264 unmodified linesfrom PIL import Image
# source: eagle0504/document-search-q-seriesdef read_and_textify_advanced(files, chunk_size):def read_and_textify_advanced(files): """ Reads PDF files and extracts text from each page, breaking the text into specified segments. This function iterates over a list of uploaded PDF files, extracts text from each page,16 unmodified lines text = pageObj.extract_text().strip() # Extract text from the page if text: # Split text into chunks of approximately 'chunk_size' words words = text.split(".") for j in range(0, len(words), chunk_size): # Get the chunk of text from j-chunk_size to j+chunk_size # start = max(0, j - chunk_size) # end = min(len(words), j + chunk_size + 1) chunk = ".".join(words[j:j+chunk_size]) + '.' chunk = chunk.strip() text_list.append(chunk) # Create a source identifier for each chunk and add it to the list else: # If no text extracted, still add a placeholder text_list.append("") words = text.split(".").strip() for j in range(0, len(words)): if words[j]: chunk = (words[j]).strip() text_list.append(chunk) pageObj.clear() # Clear the page object (optional, for memory management)
print(text_list) return text_list
def get_questions(context, instructions) -> str:179 unmodified lines st.rerun() with st.spinner("Loading, please be patient with us ... 🙏"): textify_output = read_and_textify_advanced(uploaded_files, 1) textify_output = read_and_textify_advanced(uploaded_files) df = pd.DataFrame(textify_output) df.columns = ['context']app.py+7-15