Spaces:
Runtime error
Runtime error
Update app.py
Browse files10 unmodified lines1112131415141516171820 unmodified lines39404142434445464748495051525354555657585960616242434411 unmodified lines56575880818283848586878889909159606110 unmodified lines
# Function to read PDF contentdef read_pdf(file_path): pdf_reader = PdfReader(file_path)def read_pdf(): pdf_reader = PdfReader('hey.pdf') text = "" for page in pdf_reader.pages: text += page.extract_text()20 unmodified lines Choose the desired PDF, then perform a query. ''')
custom_names = list(pdf_mapping.keys())
selected_custom_name = st.sidebar.selectbox('Choose your PDF', ['', *custom_names])
selected_actual_name = pdf_mapping.get(selected_custom_name)
if selected_actual_name: pdf_folder = "pdfs" file_path = os.path.join(pdf_folder, selected_actual_name)
try: text = read_pdf(file_path) st.info("The content of the PDF is hidden. Type your query in the chat window.") except FileNotFoundError: st.error(f"File not found: {file_path}") return except Exception as e: st.error(f"Error occurred while reading the PDF: {e}") return
text_splitter = RecursiveCharacterTextSplitter( chunk_size=1000, chunk_overlap=150,11 unmodified lines "document_chunks": documents, "vectorstore": vectorstore, }
# Save vectorstore using pickle pickle_folder = "Pickle" if not os.path.exists(pickle_folder): os.mkdir(pickle_folder)
pickle_file_path = os.path.join(pickle_folder, f"{selected_custom_name}.pkl")
if not os.path.exists(pickle_file_path): with open(pickle_file_path, "wb") as f: pickle.dump(vectorstore, f)
# Load the Langchain chatbot llm = ChatOpenAI(temperature=0, max_tokens=1000, model_name="gpt-3.5-turbo") qa = ConversationalRetrievalChain.from_llm(llm, vectorstore.as_retriever())app.py+2-35