(pdf_path)
| 212 | |
| 213 | # Process PDF files |
| 214 | def process_pdf(pdf_path): |
| 215 | reader = PdfReader(pdf_path) |
| 216 | all_text = "" |
| 217 | for page in reader.pages: |
| 218 | extracted_text = page.extract_text() |
| 219 | if extracted_text: |
| 220 | processed_text = ' '.join(extracted_text.split('\n')) |
| 221 | all_text += processed_text + "\n\n" |
| 222 | txt_filepath = save_extracted_text_to_txt(all_text, os.path.basename(pdf_path)) |
| 223 | os.remove(pdf_path) # Delete the original PDF file |
| 224 | return txt_filepath |
| 225 | |
| 226 | # Main logic for handling OpenAI API key and document processing |
| 227 | if "openai_api_key" not in st.session_state: |
no test coverage detected