This Streamlit web application, LangChain Explorer, leverages LangChain's powerful capabilities for question answering and information retrieval. It enables users to input queries and receive relevant answers from a collection of PDF documents. The application employs various language models and embedding techniques to provide accurate and context-aware responses.
- Python 3.x
- Streamlit
- langchain library
- Hugging Face Transformers
- PyTorch (if using GPU)
Ensure you have the required dependencies installed using:
pip install streamlit langchain torch
Additionally, you may need to install the Hugging Face Transformers library:
pip install transformers
- Download the PDF documents and place them in a directory (replace 'data/' with the actual directory path).
- Run the Streamlit app using the following command:
streamlit run langchain_explorer.py
- Enter your query in the input box and click the "Submit" button to receive relevant answers.
-
Document Loading and Splitting:
- PDF documents are loaded from a specified directory using LangChain's
PyPDFLoader
and split into text chunks.
- PDF documents are loaded from a specified directory using LangChain's
-
Embedding and Vector Store:
- LangChain utilizes Hugging Face embeddings to convert text chunks into embeddings.
- A FAISS Vector Store is created from the embeddings.
-
Question Answering Chain:
- LangChain's
RetrievalQA
is configured to retrieve relevant information from the vector store. - A language model (LLM) is used to generate answers based on the retrieved information.
- LangChain's
-
Streamlit App:
- A Streamlit web application allows users to input queries and receive real-time answers.
-
Configure the data path, model paths, and other parameters according to your setup.
-
Run the Streamlit app script:
streamlit run langchain_explorer.py
- Open the provided local URL in your web browser.
- Adjust the data path, model paths, and other configurations based on your document collection and language model choices.
This code is licensed under the MIT License.
Feel free to customize and use this code for your question answering and information retrieval tasks. If you find it helpful, consider providing attribution to the original source.