ChatGPT / BARD API - Build a FREE Chatbot in Python w/ Google Colab

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
are you Amazed by the power of charge GPT and what guys with little bit of Python Programming you can actually make your own chatbot for custom use cases like this this or this do you want to know how well that's exactly what we are going to discuss in today's video and the best part is going to be absolutely free and you guys can follow me along so whether you are a student looking for a resume pointer or a professional wanting to have fun this video is for you so there are essentially three things we are going to do in the next 10 minutes or so first up we'll build a simple yet powerful version of our chatbot in Python powered by the Google barred API this first step is absolutely beginner friendly then from there we are going to step up and build a more sophisticated chatbot for a custom use case which is text summarization again using barred API why are we using Google bar API and node chat jpt you may ask well the answer is API is absolutely free to access especially for learning purposes so all you guys can follow me along and replicate it on your end but hey I'll still be discussing chargpt API in the third part of this video and briefly cover how you can build a chatbot powered by chat repeat for the same use case which is text summarization on this note let's begin to get started you need two things number one an IDE for python coding I'll be using Google collab in this demonstration which I find very beginner friendly and easy to use second is the API keys for Google part and charitivity I'll be showing you the steps to sort of retrieve these Keys later in the video when we get there at this point let's jump onto the screen recording for our Hands-On so guys this is our project folder on Google Drive uh for text summarization I've kept these couple of PDF files over here uh the first one is uh the famous book called The Art of War and uh the second one is a research paper from Google titled attention is all we need I'm sure you would have heard of this the third file here is uh the code file so let's fire it up to get going on building our chat goods and of course I'll share a link to this drive folder in the description part of this video so that you guys can access both of these books and the code file so let's get started alright now I am on Google collab over here to the left you see the sections of this code file uh as I said a while back we'll be first building a simpler version of our chatbot followed by a custom chatbot for the specific use case powered by bard towards the end we discuss a charge DVD API too on this note let's begin our code review all right let's begin by setting up our environment first over here we are first installing The Bard API python package uh bad API returns response of Google bard through API for your further reading I'll put a link to the documentation in the comment section so you may read that through next up we are importing these essential libraries alright as third step here we need to configure four bar access for this we need to obtain this ID from your browser cookies and here are the steps to do it first go to your Bard window do a right click click on inspect then within this window on the right click on application cookies and within cookies you will find bar.google.com which is the URL and within this table you will find your ID which is over here over here and then all you have to do is to copy this remember this is your personal ID so handle it with care all right once you have obtained this ID replace it over here in this code cell and run it now that we have everything in place let's start with the simplest version of our chatbot we'll use The Bard API to get answers to our questions for instance in this example we are asking the question why is the sky blue to our chatbot and it will provide us with the answer let's take a look I didn't see we got the answer to our question from googlebot as we all know that Bard is connected with internet unlike chat GPT which is trained on data till 2021 so you may even query on the recent events like what is the current status of azure series 2023 let's see what we get as we see we are getting the correct response Australia is leading the 2023 ashes Series right now two is to zero alright so this is a simple chatbot powered by Google bard allowing you to perform prompting from within your jupyter notebook cool right guys now when we have successfully configured and tested our bad part chatbot sky is the limit really on the kind of customizations we may build on top of this using python so next up let's jump on to building a custom chatbot in this section guys we are going to build a tech summarizer that takes a PDF document as input which could be a research paper or a book and summarize it into a handful of words so let's let's do this for building our text summarizer the first thing we need to do is to install this python Library called Pi PDF Pi PDF is a free and open source python library that helps us retrieve text from PDF document which is something essential for summarizing PDF documents okay once it's told then we import it now as I showed you a while back I have gathered these couple of PDF documents for this demonstration link to this drive folder is in the description part Below guys I sort of told you a while back all right coming back to collab to access our PDF documents from within the Google Drive we need to First Mount Google drive to collab so that's what we do over here we follow these steps as next step I am declaring the directory to our drive folder and the file names here this attention is all you need is the paper that will try summarizing first guys as we all know bud has a limit on the input prompt length which is around 4000 characters so we can't send the entire PDF text into a single query for summarization rather what we can do is to find out a way of sending this data into Parts a simple way of doing this is to divide the whole text of the PDF on the basis of pages which we are following in our case however a better strategy is to split the text on the basis of paragraphs but then it will increase the number of API calls that we'll have to make and thereby increasing the overall compute time so we are going to go with the simpler approach over here so here in this next code cell we are calling the PDF reader module from PI PDF to read the text from our PDF document one page at a time and store it in this empty list called text let's run it this next step is sort of optional for you here we have this function called join elements that merges text from multiple Pages stored in our list as single element see the idea here is this Bard has prompt length limits but it's still a sizable 4000 characters at this point so again for the sake of reducing the number of API calls what we can do is to actually merge multiple pages of text into one and over here in this code I'm actually merging three pages of text into one and storing it into this new list which I'm calling new text and guys if you have tried an alternate strategy for handling the text do share it in the comment section it would be great hearing from you next up we Define this get completion function to fetch response from Bard for our specific prompts and now is the time when we start prompting for our specific use case which is text summarization this is a matter of experiment really guys to figure out the best prompt for you for now you can use this prompt which has worked well for me I highly encourage you to try out your own version of prompt and do share those in the comment section below along with brief on the result you got from it this cell might take a few minutes to run so I'll sort of fast forward the video [Music] so guys this is the summary of our attention is all you need paper finally in this last code cell we get to save our summary that we have obtained in a text file and once we do that it gets stored in the Google Drive directory folder that we have over here and with this guys our text summarizer is now ready to summarize a different book all you have to do is to put it in your drive folder like I have this out of workbook over here and declare the file name uh to that book over here in this code cell trust me guys that's really not the end of route for you there are these bunch of practice use cases I am putting up for you as a challenge do try to solve them and share your code file as a link in the comment section of this video along with a brief on the use case you prepared the chatbot for all right in this last section of our code we are doing everything we discussed so far in this video but with chat GPT API now I'm keeping this code here for your ready reference if you plan on building a chat GPT powered chatbot for sure you will get better results with this charg API as compared to Bard but for now the chat GPT API is not freely available so Bard is the next best thing really but if you can somehow manage to get access to chargpt API or you have a paid plan with openai go ahead and use this code for your use cases if you get stuck do fingers in the comment section and we'll get back to you guys pat yourself on the back for reaching till here in this tutorial you learned how to build a chatbot powered by Bard and chat CPT starting from scratch remember building our chat board opens up endless possibilities for creating Innovative applications whether it's answering questions or summarizing text chatbots are here to assist us in a variety of ways and if you found this video helpful make sure you give it a thumbs up and subscribe to our channel for more exciting tutorials on data science and generate API also do not forget to check out the code that we have put for you in the description part of this video thanks for watching and I'll see you in the next video Happy coding to you bye
Info
Channel: Analytics Vidhya
Views: 45,829
Rating: undefined out of 5
Keywords: chatbot python, chatbot python project, python chatbot project, chatgpt api, chatgpt api python, bard api, bard api python, bard api integration, chatgpt api integration, bard api key, chatgpt api key, chatbot gpt, chatbot project, chatbot tutorial python, chatbot python chatgpt, chatbot chatgpt python, chatbot bard, chatgpt explained, google bard vs chatgpt, build a chatbot, build a chatbot in python, chatgpt bot python, chatgpt bot, bard bot google
Id: qhmaDOo7D_E
Channel Id: undefined
Length: 10min 47sec (647 seconds)
Published: Fri Jul 14 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.