Spaces:
Runtime error
Runtime error
Update app.py
Browse files10 unmodified lines111213141516171820 unmodified lines39404142434445464748495051525354555657585960616263646511 unmodified lines77787980818283848586878889909192939410 unmodified lines# Function to read PDF contentdef read_pdf(file_path):pdf_reader = PdfReader(file_path)text = ""for page in pdf_reader.pages:text += page.extract_text()20 unmodified linesChoose 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}")returnexcept Exception as e:st.error(f"Error occurred while reading the PDF: {e}")returntext_splitter = RecursiveCharacterTextSplitter(chunk_size=1000,chunk_overlap=150,11 unmodified lines"document_chunks": documents,"vectorstore": vectorstore,}# Save vectorstore using picklepickle_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 chatbotllm = ChatOpenAI(temperature=0, max_tokens=1000, model_name="gpt-3.5-turbo")qa = ConversationalRetrievalChain.from_llm(llm, vectorstore.as_retriever())10 unmodified lines111213141516171820 unmodified lines39404142434411 unmodified lines56575859606110 unmodified lines# Function to read PDF contentdef read_pdf():pdf_reader = PdfReader('hey.pdf')text = ""for page in pdf_reader.pages:text += page.extract_text()20 unmodified linesChoose the desired PDF, then perform a query.''')text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000,chunk_overlap=150,11 unmodified lines"document_chunks": documents,"vectorstore": vectorstore,}# Load the Langchain chatbotllm = ChatOpenAI(temperature=0, max_tokens=1000, model_name="gpt-3.5-turbo")qa = ConversationalRetrievalChain.from_llm(llm, vectorstore.as_retriever())
app.py+2-35