Spaces:
Sleeping
Sleeping
Update app.py
Browse files4 unmodified lines56789101116 unmodified lines282930313233343536373839404142434445464748179 unmodified lines2282292302312322332344 unmodified linesfrom PIL import Image# source: eagle0504/document-search-q-seriesdef read_and_textify_advanced(files, chunk_size):"""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 linestext = pageObj.extract_text().strip() # Extract text from the pageif text:# Split text into chunks of approximately 'chunk_size' wordswords = 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 listelse:# If no text extracted, still add a placeholdertext_list.append("")pageObj.clear() # Clear the page object (optional, for memory management)print(text_list)return text_listdef get_questions(context, instructions) -> str:179 unmodified linesst.rerun()with st.spinner("Loading, please be patient with us ... ๐"):textify_output = read_and_textify_advanced(uploaded_files, 1)df = pd.DataFrame(textify_output)df.columns = ['context']4 unmodified lines56789101116 unmodified lines28293031323334353637383940179 unmodified lines2202212222232242252264 unmodified linesfrom PIL import Image# source: eagle0504/document-search-q-seriesdef 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 linestext = pageObj.extract_text().strip() # Extract text from the pageif text:# Split text into chunks of approximately 'chunk_size' wordswords = 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)return text_listdef get_questions(context, instructions) -> str:179 unmodified linesst.rerun()with st.spinner("Loading, please be patient with us ... ๐"):textify_output = read_and_textify_advanced(uploaded_files)df = pd.DataFrame(textify_output)df.columns = ['context']
app.py+7-15