This project allows you to have a conversation with the content of multiple uploaded PDF files, leveraging Google's Gemini large language model (LLM) through LangChain. The interactive web interface is built with Streamlit.
└── 📁 utils
├── 📄 pdf_handler.py
└── 📄 embedding_handler.py
📄 app.py
📄 requirements.txt
📄 .env
app.py
: The main Streamlit application file. It contains the logic for loading PDFs, processing text, creating embeddings, interacting with Gemini, and displaying the chat interface.utils/pdf_handler.py
: Contains functions to extract text from PDF files.utils/embedding_handler.py
: Contains functions to split the text into smaller chunks and create embeddings using language models.requirements.txt
: Lists the required Python dependencies for the project..env
: File to store environment variables, such as your Google Cloud API key.
-
Enable Google Cloud API and obtain credentials:
- Go to the Google Cloud Console.
- Create a project or select an existing one.
- Enable the Generative Language API.
- Create a service account and download the JSON key.
-
Set up environment variables:
- Create a
.env
file in the root of your project and add the following:GOOGLE_API_KEY="SUBSTITUTE_YOUR_API_KEY_HERE"
- Create a
-
Clone the repository:
git clone https://github.com/your-username/chat-with-pdfs.git cd chat-with-pdfs
-
Create and activate a virtual environment:
python3 -m venv .venv source .venv/bin/activate
-
Install the dependencies:
pip install -r requirements.txt
-
Run the application:
streamlit run app.py
-
Access the application: Open your web browser and go to
http://localhost:8501/
.
- Upload PDFs: Use the file upload widget in the sidebar to upload one or more PDF files.
- Process: Click the "Process" button to extract text from the PDFs, split it into chunks, and create embeddings.
- Converse: Type your question in the text box and press Enter. The chatbot will respond based on the information extracted from the PDFs.
- Make sure you have enabled billing for your project on Google Cloud, as using the Gemini API may incur charges.
- The accuracy and quality of the chatbot's responses depend on the quality of the uploaded PDFs, the Gemini model being used, and how the questions are phrased.
- This is a basic project and can be extended with additional features such as support for different file formats, model customization options, enhanced user interface, and more.
- Refer to the LangChain and Google Gemini documentation for more detailed information on customization and advanced usage.