This project demonstrates how to summarize PDF documents using artificial intelligence. Both examples use Google Gemini AI, but one uses LangChain and the other one accesses Gemini AI API directly.
This example implements Google Gemini AI API directly (using the PDF loader from LangChain for simplicity).
This example (the default one) implements LangChain abstraction.
python -m venv/venv
- Creates a new virtual environment, we will use this to store temporary API keys in a secure way.source venv/bin/activate
- Activate the virtual environment.
See this guide if you are using other operating systems.
Run the following commands in order to install the required dependencies and configure your GOOGLE_API_KEY
:
pip install -r requirements.txt
- Install the required packages.export GOOGLE_API_KEY="your_google_api_key"
- You can obtain your API key by going to Google AI Studio and following the instructions.
Run one of the following commands in order to run either one of the examples:
python geminiai-api-example.py
- Optional, this uses Gemini AI API.python langchain-example.py
- Optional, this uses LangChain.
Either is you are running the langchain-example.py
(LangChain) or the geminiai-api-example.py
(Gemini AI API), you simply need to modify lines 5
or 10
of each of the files if you would like to see different results in your output.
The output for the current PDF (which contains five pages) is as follows:
Climate change poses risks to businesses, including physical risks like floods and droughts, price risks due to resource scarcity, product risks from shifting preferences, ratings risks from investors, regulation risks from government action, and reputation risks from public perception. Companies can adapt by forecasting scenarios, investing in resilience, and embracing sustainability.