Tutorial: Chat with PDFs on your Google Drive
6 easy steps to chat with your document in Google Drive. It costs less than a ChatGPT subscription and is more secure.
Unlock the ability to interact with PDFs in your Google Drive as if you're having a conversation with them. This simple guide is crafted for anyone who wants immediate results without delving into the technicalities. Get ready to chat with your documents!
Find a sample google colab document all the way at the bottom of this article.
What You'll Need
Before we begin, ensure you have the following:
A PDF uploaded to your Google Drive.
A Google Colab account ready for use.
And, you need to subscribe to this newsletter… Not mandatory, but please? 😅
Setting Up Your Workspace
Step 1: Open Your Google Colab Notebook
Visit Google Colab, login with your google account and create a new colab notebook. That should look something like this. 👇
Step 2: Connect to Google Drive
Within your new notebook, look for the file icon on the left sidebar. Click on it and wait for a few seconds for the Colab environment to load.
Then click the Google Drive symbol to mount your drive. This should ask you a couple of permissions to enable you to connect with your google drive.
Once this is done, you should see two things:
A drive folder which is nothing but your google drive that’s connected to the colab notebook.
A piece of code that can be used to connect to your colab notebook. The code should look something like below.
Now run the code by pressing the play button on the left side of the code. This might again ask you for a few permissions, but once it finishes running, your google drive will be connected with the colab notebook.
Step 3: Installing Embedchain package
Before we install, lets add a new cell by hovering on the centre of the last cell and clicking on “+ Code” button.
Once we do that, let’s add the following code to the new cell and run it again by clicking the play button.
!pip install embedchain
This will generate a lot of output messages, wait for it to finish, scroll all the way to the bottom and look for the "Successfully installed" message to confirm everything went smoothly.
Step 4: Getting Ready to Chat
Import Packages and Load Your OpenAI API Key
Here’s where you bring in the tools you need. Add the following code to a new cell:
from embedchain import App
os.environ["OPENAI_API_KEY"] = "sk-yourapikey"
bot = App()
Don't forget to replace
"sk-yourapikey" with the actual key you get from your OpenAI account.
Step 5: Adding Your PDF to the Conversation
Add Your PDF to the Bot
With this step, you tell the bot about the PDF you want to chat with. Add the following code to a new cell and run it:
I have my PDF (grammy_awards.pdf) in a folder called “PDFs” in my google drive. Make sure to update the above code to match the path of your pdf in your google drive.
Step 6: Let’s start the chat!
Start Chatting with Your PDF!
It's showtime! Ask your PDF anything by adding the below code to a new cell and running it:
bot.query('Who hosted the grammy awards of the year 2014?')
Replace the above question with your own and you can start chatting with the PDF in your google drive!
Here’s a sample output:
You've just stepped into the future of document interaction. With these few steps, you can effortlessly extract information from your PDFs. Remember to monitor your OpenAI API usage to manage any associated costs.
Enjoy your new-found efficiency in data retrieval and happy chatting with your documents!
AI Newsletter Today is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.