Unleash the Power of GPT 3 and Google Sheets: Automate Sentiment Analysis and Product Descriptions

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] foreign Circle where we discuss everything AI in today's video we'll be using AI to power up Google Sheets we'll be using this to perform some powerful tasks right inside our spreadsheet spreadsheets are widely used and combining them with the power of AI is definitely a productivity superpower alright let's take a look at what we'll be building out today first we're going to be taking this list of Tweets in our spreadsheet and we're going to be determining what the sentiment for each tweet is we're going to be using GPT the model behind chat gbt to perform this task so here we go to our extensions we go to our macro we have a script that is going to run run through the entire list of tweets and then generate a sentiment and populates the sentiment column so once it's completed you can see our sentiment appears and we can go through it just to make sure it's correct just upgraded my bike with some awesome accessories that looks like a positive tweet and you can go down and read through it's fairly accurate all the tweets with the sentiments as well so for the second example we'll be generating product descriptions for this list of products so we have our product names and we have a description column again we're going to be going over to extensions we're going to be using a macro to get the product description for each of these products again we're using GPT here to do the same thing very similar to what we did in the last one it's going to go ahead and generate all the product descriptions so you can see product description is generated for this different products now this is a good starting point if you're trying to run these type of tasks so you can start to imagine other things you can do you can summarize specific things you can obtain hashtags for your posts so many different things that you can do using this model to perform a task across your rows and this is a good way to do things in bulk using these AI Models All right so let's jump in and see exactly how we're going to be building this out all right to build this out we will require an open AI API key uh you can get this from your website I've added a link in the description so all you need to do is just sign in or sign up if you don't have an account or to your account section click on your account section click on view API keys if you already have a key copy that key or you can generate a whole new key as well so this is the only thing that we'll be needing uh to actually perform our tasks today all right to start off we're gonna be in our spreadsheet so we have a list of tweets here uh in our Google Sheets and the very first thing we want to do first and foremost is to start our app script apps script is a tool that you use to write functions that can perform tasks on your Google applications so before we actually start writing our function we'll be storing our API key from open AI in a script property so right here we can go ahead and add a script property give it a name open AI API key and then we can paste the value that we had received from the open AI website once you're done go ahead and click on the save script properties and then we'll be ready to go so this is the function we're going to be creating today we'll be stepping through everything uh We've also added a GitHub link for this code you can copy that to follow along let's explain the function at a high level before going a little bit deeper so it takes one input in our case a tweet and it uses that tweet as part of a prompt to open AI to get a corresponding sentiment now let's dive a little bit deeper so we start by giving our function a name so we're going to call it get tweet sentiments this function is going to take in one parameter a tweet so we need to get our active sheet to do that we'll be using the spreadsheet app class this gives us access to our spreadsheet we can assign that to a variable which we're calling sheets next up we need to access the data in the spreadsheet to do that we need to use the get data range method and get values method to get access to the data we're going to assign all of that to a data variable now because we have stored our open AI API key as a script property we would need to use the property service class to get our properties to get the specific property we're going to use the get property method along with the key we use to store our open AI key and then we'll use this in our function then we want to go ahead and Define parameters that we're going to be needing to make an API call to open AI starting with the base URL the AI model which we'll be using which means the GPT model we'll be using so we're going to be using text tab in g003 I think you can use other models like Ada or Curry but we're just going to use text DaVinci is the most powerful one just for our demonstration here want to set a Max token which is going to be used to control how much text is outputed and we're going to use a stop which is used to know when to cut out the generation in our case we're using just a full stop because we want the processing to ignore the header we have implemented some logic to make this happen which is why we have a variable called row which we're setting to 1 which indicates where the processing should start from in the second part of our function we would be looping through each of the rows to get the value which we would be using for our prompts we'll use a for each Loop and loop through the rows in our data we also have a condition ensuring that the processing starts after the headers we then increments the row number as we Loop through the list now I want to Define our prompts to start with so here we have a simple prompt that says classify the sentiments in this tweet we are referencing a value from the row that contains the tweet and then we want the results to return either positive negative or neutral it's always a good practice to be explicit in your instructions while designing your prompt next we want to build up our API call so we want to Define options and payload so here we want to include authorization we want to enter the API key which we stored earlier on in our authorization which is basically a Vera token I will be using the URL fetch app which gives us access to a method which we'll be using to make our API call output is initially returned in Json formats we need to parse that using the Json class then we can obtain our sentiment directly from inside the choices the text object from the open AI output finally we get the row and the column rule like to populate so in this case we're setting the row dynamically and incrementing as the loop continues then we set the column to 2 because that is where we're going to be populating the sentiment as well next up we're going to run our code to see if it actually works so we hit the Run button we can see that execution has started when running this for the first time you'll be taking through a dialog where you have to actually Grant access to your Google sheet it's just a Google dialog so be sure to allow that but we can see now that our result has completed execution is completed we can see that our tweets have been processed and we can see both positive and negative sentiments are being processed as required now all right next up is deploy our app so it is usable right from inside our spreadsheet to do that we go to deploy a new deploy we select web app which is what we're going to be using uh in our deployments and then once we're done we want to select permissions as to who's able to utilize this if you don't want any other person to use this you can specify that this is just for you once you're done with that once it's deployed then it's available actually your Macros for use alright next up we're going to be importing this function as a macro so we go to extensions we hit macros we hit import macro and then we want to add our newly added function as a macro so that we can call this macro again so let's test it out so let's remove all the values right now and try to call this macro directly from inside the spreadsheet we'll go to extensions go to macro and now we see our micro there and we can use it and now you can see that it's currently running the script and once it finishes running that script we will see our result as before so that's exactly how we can use a lot of these types of capabilities right inside the spreadsheet so you can continue to imagine all the different ways that you can use this moving forward I'm excited to see what you actually build thank you for watching and talk to you in next time
Info
Channel: Prompt Circle AI
Views: 6,429
Rating: undefined out of 5
Keywords: ai, gpt3, generative ai, artficial intelligence, chatGPT, google sheets, productivity, sentiment analysis
Id: wWrvkhhBRNw
Channel Id: undefined
Length: 10min 31sec (631 seconds)
Published: Sun Jan 15 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.