Transcript for:
Building a Generative AI Application using Vertex AI and PaLM API

hello all welcome back so in this video we are going to see how we can build a j application using vertex AI pal API okay so again this will be one an amazing video on very hot and trending topic that is a generative Ai and here I will be leveraging a Google cloud services that is vertex Ai and pal API okay so we'll see what we are going to see in this complete video so let me walk you through that first so in this video first we'll see what is a generative AI just to clear your Basics I'll just walk you through what is a generative Ai and how it is different from our traditional Ai and ml Services then how gen AI works so we'll see how gen Works what are the different current hot tools which are based on the Gen then we'll see a generative a studio in a Google Cloud so then we'll move to the Google Cloud and on the console I will show you the generative a studio in Google cloud and Au the different options in Google Cloud generative AI Studio okay so then we'll see a python SDK Forex AI pal API so this Palm API we can use to build our gen application using a Google Cloud okay so then we'll create a simple python chart application using the Gen and once we created a simple python application we try to create a web application using a python flask and pal API and we'll deploy that application on a web okay so then we'll try to test that application we'll chart that application so this application will be like your Bard or chart GPD where you will ask something in chat and your application will give you response as a like a gen application so you can ask okay give me a sample program for python give me terraform code so simple question you can ask to test the application your application will answer you back just like Google b or chat GPT or any other gen tool and then we'll create a Docker container for our gen app and we'll try to deploy the docker container on a cloud run so this will be longer video as I'm covering all basic to advance all these steps in single video so just stay tuned till the end if you want to learn about gen as well as how we can deploy the Gen application on a Google Cloud now we'll see what is a generative AI or a gen AI so on my screen you can see a typical definition of generative AI in plain English that it is a branch of AI that focuses on creating new content such as text images audio and video so let me explain you in a simple term so when I was a kid my mother gave me one ABCD book okay and I was trying to learn ABCD that a for apple b for ball or c for cat and D for dog now I learned that okay for Apple before all and after a few days my mother asked me to write your name in English and I wrote my name as a v so how I could do that because I learn ABCD and then based on my knowledge what I learn in that ABCD I wrote my name as a Vishal because I know I can write that name so the same way genni works so we can provide some input data to machine learning model okay so this is your input Text data that we can call llm or large language model so where we can provide a huge amount of text input data or it can be your media data or it can be your image data okay so we can provide a huge amount of data to your model and then ask your model to provide input based on your prompt so for me just to my human intelligence okay I learn ABCD and based on that that was my input data and based on that input data I can generate my name that is my output that is my human intelligence so same way it applies for GNA so for gni we can provide input data in form of like example A B CD and we can write our J to okay now you can write my name so this is a simple example so you just take an example of your chart GPD or B so whatever you ask to chart GPT it can give you an answer or it can give B can give you an answer so these are nothing but a gen tools so simply let me go to the one of the tools I will show you now just take example of this gen tool so B is again one gen tool based on the Google's llm model so here I can just ask anything okay create me essay on my best friend and it will create me essay on my best friend so this is like J tools they are creating this essay creating a content in the form of text now this is creating only in form of text because this tool support only a text format there are other tools which create images which create video based on your prompt so prompts is whatever input you are giving so this is one kind of gen tool again the same chat GPD here you can ask okay give me simple python hello world program okay so it gave me the program so it is generating text based on the data it is trained on so chat GPD already trained with open Ai and it has provided a lot of data and it trained on these so GPT is nothing but generative pre-train Transformer okay so it is again the Gen tool so these are the Gen tools which train already on the huge amount of data and it can create or it can generate output based on the prompt we provide so that is called as a J Tool so here let's go back to original slide now why this J is trend nowadays because I'll try to explain you the difference between the jni and our traditional AI so just here example of the classical our traditional Ai and you can see one model building so if you are not aware of the basics of machine learning do not worry I'm just uh trying to cover uh overview of the machine learning models here so any machine learning model you have to provide some data you have to train your model and based on that the train data your model will provide you an output so input then your training data then train your model and output that is the basic flow of any machine learning model so let it be a chart GPD let it be a b or any llm large language model so you have to first provide some input data in order to get output from your machine learning model So In traditional machine learning model you have to provide your training code you have to provide some data and based on your data your model will provide output so this output can be any form of like prediction so it can predict your weather forecast so any machine learning like say suppose example any weather machine learning model so you have provided huge amount of values of your temperature your other weather data and based on that historical weather data it will trying to predict your uh weather forecast okay the tomorrow there will be rain tomorrow there will be like uh less R so this kind of prediction it will create or a classify so suppose you have provided 100 images to your uh machine learning model so I have created one project in Vex where I provided a different images to my machine learning model and then I train model on whatx and based on that training data it classified my images in a different category based on the label I have given so here you can see the example that okay I will train my model this is a cat I will provide 100 cat photo then I will train my machine learning model okay this is a dag this is a dog and I will provide 100 a dog photo and then I will ask my model to classify which is a cat which is a dog then then my machine learning model will classify that images okay this is cat images this is dog images So based on a training data my machine learning model either I will predict or classify or clusterize okay so this is a traditional AI based on the training data it will provide you an output so that is how the training traditional machine learning model will work now let's go and check how geni works so in the Gen as well you will provide a training code you will provide labell data and also you will provide unlabelled data so what is mean by label data and unlabelled data so in label data so say I am providing cat image and I will mention okay this is a cat I will provide dog image I will mention this is a dog this is my label data because my model will identify this is cat image this is dog image so this is called as supervised learning and in unlabeled data this is kind of like semi supervised and unsupervised learning where I will just provide some data to train my model so I will provide huge amount of text Data I will provide say example I will provide huge documentation of python okay how Python Programming will work and then I'll ask my uh chatbot provide me a python code for XY Z then my based on that training data based on that python documentation provide it will give me the python code so that is called like unlabelled data or unstructured data I would say and based on that data or model will train and it will create a new content so it can create content on the text like our chat GPD body is creating it can provide a code like we saw an example or it can create image So currently we didn't see the example of image but in near uh future I will create some videos where using API I will create some uh like J application to create images as well so I'll create some projects on that as well so currently here you can see this is how the Gen application will work and now you can see the example so here it will just ask me to read a book you can just ask your model to read a a book and that book will contain the information okay this is cat this is dog or all kind of f animal and then it will ask a question okay now what is a cat so it will provide information based on the book it read so it is same I give the example of learning ABCD and then creating your own name or writing your own essay because you learn only ABCD but based on that your own intelligence you created like huge English text or essay so you are creating or you are generating content based on the data you got train on so that is how a generative AI works now I hope you got some basic understanding of generative Ai and the traditional AI now we'll see what is a generative AI studio so I will be covering generative AI Studio because I going to use generative a studio to create my gen app so this is part of Google Cloud where we can test our geni application and prototype and customize the Gen model as well okay so I'll go to Google Cloud console and we'll show you how we can work on a gen AI Studio there so I'm on my Google Cloud console now and gen AI studio is a part of the Vex a section so I'll go to the Vex AI here so Vex a is a Google Cloud AI platform okay so in this side left side you can see the Gen studio so I'll go to an overview so now suppose if you want to build any gen application you can use this gen Studio to test your application build your application and customize your gen application so now I'll be using this to create my own gen application so I'll be creating uh one chatbot so which will respond to your any query like just like a chat GP or a Google Cloud B okay so uh let me go to the language section and I will show you how I can build my own uh chatbot or how I can build my own a gen application so here I'll be using a Google llm uh pal API so pal is nothing but a pathway language model which will be based on the Google large language model and it will be part of the vexo so here I'll just show you how our model will work once we deploy it as a web application as a gen application so simply I'll just ask anything okay so I'll ask here who was winner for 201 15 IC World Cup so as I am a cricket fan and just asking few random question related to Cricket and we'll see if my J studio will respond and it gave me Australia which is a correct answer here so Australia was the World Cup winner for IC Cricket World Cup so here how this is working so it is using a tech SP model in a Google J studio so I will be using this model to deploy my code instead I will just check which is the latest and available model so here you can see this is a preview model so I'll be using this Bion model 01 which is you can see you don't see any preview option so it means it is generally available but how I can use this in my code or how I can use this gen Studio to build my own gen application so this is very amazing stuff here so you can simply click on The View code and you will see the python code here so first I will using this python code and I will test my application as a simple python application and then I will use a python flask and deploy this as my uh chat application on a web okay so I'll just use this so I already have a code in my vs code so I'll go there now okay so this is my vs code so this is similar to whatever I have here in my generative as studio so I copied from here I just customize using my variables and the prompts uh input prompts I want to accept it from the terminal so else whatever the libraries I using it will be the same so you can use the same code else do not worry I'll be providing the complete source code on a GitHub repository okay now this is a simple application I have created in Python using a Vex a language model okay so you can see I am importing the Vex a now again we'll just get help from AI again so I have already enabled D AI on my system if you don't know what is D you can go back and check my previous playlist on the D and I don't know how this code is working so instead I will ask AI again to explain me this code so I'll simply select a part of the code one by one so I'll just select this I'll just ask my D to explain this okay and my D will explain this complete code so we'll understand what it is doing so the create session function create new chat session with Vex language model which is a chat Bion 001 as I shown you here that I will be using a b model 001 model which is available model currently is not in preview and it is publicly available now so I'll be using this 001 model and I'm using this here Chad Vision 001 which is a pre-trend model this function returns a chat object that can be used to send message to the model and receive a response so from this python API I will be sending this text so earlier I was giving text prompt here and getting output from the UI now I'll be doing it through the python so I will send some input text to this model text Vision model 001 and this model will return some response and it will show me as a output on my python terminal okay so I'll go back here and so this we understood okay this is creating one chat session like we created here so this is is creating one chart session now we'll just just again check this what this part of the code is doing and we'll just again Ask D to explain this so D will explain what this code is doing so this run chart function is the main function of the program it creates a new chart session with Vex AI model and then start Loop that prompts user for the input and send input model to the for a response so again this is just uh keeping our Loop which is a main window it will accept input and provide output in a loop so this is a main model so I'm just trying to explain that we can get help from D also to get more understanding of the code also it can help us to generate the code as well so that you can refer my previous video how how I uh worked with a d and how you can enable the D to get help to understand the code or a generate a new code okay so uh that is our code now now let's see how I can execute as the application so I'll just open a terminal new terminal okay and I'll try to run this test.py file so I'll just first create simple python file I'll run it on a terminal just like a chat window and then I'll try to create a python flashy application okay so I'll just execute python test.py so one thing to remember if you are not able to execute it as a test.py file or a direct Python program you might get some error because of dependency so before you how to install the SDK Forex so how you can install you can do the PIP install and this Google Cloud AI platform okay so these are the dependencies for this uh the project I am doing here so you can install these dependencies first so simply I doing python test.py here let me execute and it will ask me as a promp first to provide an input so initially it will be slow because it is creating call to my whatx platform and then it was providing response back to my server so okay here I'll just start my chat now the chat session is started I'll tap hello and it will provide me response like hello how I can help you so I'll just ask I am stress today and we'll see what response I'm sorry to hear that what's causing you a stress I'll just mention okay overthinking I'm just randomly doing stupid prompt here can be very difficult thing to do I'll just again ask how I can deal with it okay so it gave me the prompt so it is just working like your chat GPT or your Google B so it is just like your chatbot which provide you the intelligent output based on your input prompt now you understand this is working completely fine very amazingly here so I will try to create it as a flask application okay I'll just terminate it here okay and now if I want to create it as a flask application only I need to make few changes which I already made in app.py so instead of printing output on the terminal and providing input on the terminal so both the things I will do on my web console so I already created here app.py so I'm not going to explain you this code you can simply copy this code so the same code I'm just trying to uh like embed it in the flask application so it will return return output on the flask app so now I will run flask application Python app.py and it will create and start new a python flask application okay so I'll just follow this link and go to my web page okay now you can see this is my chatbot it's like your Google B and chat GPT the generative a app where you can just ask anything so we again start some random stuff Hello so here I'm not maintaining any chat history just the simple demo I have created now it will take some time because it is through the python flask application but it will give you response so I will ask again what is pal API because we are using the pal API to create this gen application and it will explain what is pal AI API so pal API is a large language model from Google AI that can be understand and generate human language it's trend on the massive data set of text and code again I will ask some programming related question how to create simple flask application okay so every time I'm giving input prompt my flask application is working with uh vertex AI giving as a input and getting response back from the Vex AI p and providing as output now you could see it provided me the output so you don't see the in much well written format but yeah it is giving the proper output and if I copy it and paste it in a notepad plus okay so you can see it given a run the appropriate example here so it has given the complete python code so it is perfectly working like your other chat application like B and chat GPT so you can ask anything so I will ask again what is capital of India I'm just asking some random question to make sure it is working fine okay the capital of India is New Delhi now we will go again one step ahead of this now we'll deploy this as an web application on a cloud Run Okay so before that we have to create it as a Docker container so so I have already created a Docker file here you can see the docker file so which is a simple Docker file I am using in all my python flask applications so you can refer the same file and index.html just for my web UI so whatever the UI have created here this is for my Wei and app.py is our python flask main file I would say uh now I already push code to the GitHub repository here okay so you can refer this code and now I'm going to Cloud run to deploy this as my web application so if you face any issue we'll resolve that and move ahead so yeah definitely if you are learning you will face lot of errors and issu and you have to sort it you have to find a way to get the correct code deployed and the correct application working okay so now I am on my cloud run so I previously deployed one weather application on a cloud run so you can if you want to learn on the doop side as well you can refer my previous video on how I deployed and automated the cicd pipeline for my weather application so now I will create a new service for my J application which is my chatbot application and I don't want to use existing so I want to continuously deploy new version from The Source repository as I have code in my GitHub repository so I will use ji chatbot name here okay and yeah so the region I will use us Central one only so set up Cloud build so here again as you are doing a continuous deployment you have to set up the cloud build for that you have to integrate your GitHub repository already here if you have bit bucket or you have codeing code Source repository you can use that as well but I already have the GitHub repository and code available I will use the existing GitHub repository if you are using very first time GitHub repository with the cloud build or a cloud run it will ask you for authentication that you can enter a GitHub uh username password or you can authenticate using other method as well and now it will show me all my repository available and I will select the J chatbot app repository so I have to accept it and then I will create a build configuration so whatever the code I'm pushing it will okay so here I will choose a master Branch because I have code in the master Branch the build type is Docker file which is available already in uh repository root directory okay so my Docker file should be available in the root directory inside my repository and let's save it and once I select create it will create okay I will do allow un authenticated invocation so everyone can access my application and then I'll create it okay so now my service is getting deployed okay so the build job is in progress now let's see the logs open link in a new log so it will take you to the Google Cloud build page and we can observe all the steps and logs here so it is still running and you can see it's completed now so let me go back okay and it is completed so let me just check on the latest revision hope it's working if not we'll troubleshoot it yeah it's amazing now it's working okay so let me just type hello here and we'll see if I'm getting response or getting any authentication issue while communicating from cloud run to Vex a oh I'm getting proper response and it is quick so it means uh it is quick from cloud run instead of I'm doing it from my local system and I will ask again help me to write python code to add two numbers I'm just asking a basis basic questions and it is giving me the output here how I can write uh let me ask again what is generative AI studio so let let see what it provide so you can see generative a studio is a platform that allow us to create and share their own a generated content okay so let me ask a generative AI so it is giving response like a chat gpta and B so we created our own chatbot let me ask something else I'm fan of Ms doni so I'll ask who is Ms doni okay so Mahendra Singh dhoni born 7th July 1981 commonly known as mson is Indian cricketer who is current captain of the Indian national Cricket in a limited over format so it is bit old information it is giving but yeah as an chart model or a gen model it is giving me the correct information just as it was trained previously maybe a year or two years back that is why it is giving uh some old information but by the way it is working fine and I deployed my own gen application using a Google Cloud generative a studio Vex a and pal API so you can use this video and you can create your own gen application so this is a simple example and simple use case I have mentioned you can create very different application you can create there are variety of application you can create and you can leverage this spam API or there are other API as well which you can leverage to create your own gen application so hope you enjoyed this video and we'll see you in the next video so thank you for watching this video