Run Google's Gemini Pro and Pro Vision via API in Google Colab (Code Included)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Google has opened apis sess to their gmany pro model and you can use it for testing for absolutely free gini model comes in three different sizes Gman Ultra G Pro and G Nano G Pro is the second best model from Google and you can use CH pro model into your applications using API before before we discuss how we can use G Pro model in our projects let's look at the pricing so over here you can see the pricing so uh now you can see it's free for everyone until you make 60 quaries per minute but if you are making more than 60 quaries per minute then you can go with the pay as you go package but it's not available currantly and it will be coming soon at uh Google AI Studio for currently you can uh use it for free until you are making 60 queries per minute and price for the input is free price for the output is free but there is a one catch uh the Google will use your input the text the input text as well as the output which is generated by the model to improve their product and you can get your API key in Google AI studio so if you just simply click over here now this where Google maker suit will be open and you can get your API key from here so uh you can just click on this option like you are consenting that uh you will so now I'm just you can create your account if you haven't created your account uh you can just sign up with your Google account and uh and you can just get click on get API key and if you just create API key in new project from here so this might take few seconds and you can see this is your API key you can simply copy this so let me uh show you how you we can run G Pro model in the Google cab so let's test the G Pro model in Google collab so here is the Google collab notebook that I have prepared for this tutorial you can simply click over here Secrets stab and you can add the new secret key so you can simply add the API key in the value tab over here that you have uh copied when you are just creating a new API key okay over here so I will just past that API key over here in the value tab now I will just add the API key so now you can see I have added my API key and over here I will just write the name so whatever name you write over here in the name tab please remember that name because this will be your invo requirement variable name so I will just write the name Jam Pro key okay and you can simply provided notbook assess and you can simply hide this API key from here by clicking on this step and if you want to just delete this you can delete this as well and I will simply provide it notebook assess like I will be able to use this inside this Google go notebook so now I will just install all the required libraries so first of all I will install the Google generative a package I have already run this script previously as well so this for that it can simply run the cells fastly now I will just import all the required libraries that we will be using in this tutorial so I'm just importing generative AI from google. generative AI then uh use to if you want to securely store your API key and uh use in this Google Go app notebook we will require import data you we will require user data library and simply if uh if you want to just uh display the generated text from the uh uh model in the form of markdown so we can import the markdown library and display Library so that uh basically import markdown and display Library are are used to display the text that is generated from our G Pro model in a proper format so now here you can set up our API key uh okay so I have already told you how you can get your AP ke but here I have added the link as well so this will redirect you to the API Key C app and you can simply get your API key from here so I have already told you how you can get your API key and as you know that in the secret tab I have just written uh the name of the here I just added my uh API key and here I've just written the name GD Pro key so this will be the name uh or this is the environment name of the variable so I will just add the same name name over here giny Pro key and user data. get okay so this will be our Google API key and just I'm just setting the environment over here so you can simply run this cell okay so now it has run so now we are ready to call the JY API so first let's see what different models are available under the JY API So currently as I told you at the start that J waro model is available while gmany Ultra model it will be available in early 2024 so if you just run this C so this will show you the different models that are available under the J API So currently JY pro model is available at JY Pro Vision model is available we will be using both of this model in this Google bab notbook so in first we will see how we can generate text in the output from the text input so the user will pass some text in the input and in the output we have some text generated by the model okay so for text only prompt you can use the generative pro model so if we have our input in in if our input is only in the form of text then we can use G Pro Model but if our input is in the form of text as well as as in the form of image as well or you can say that if we are using image and text both in our input then we can use gemd Pro Vision model but if we are using only text in our input then we can use simp J pro model but if we have in image and text code in the input then we can use J Pro Vision model so I only have text in the input so I will use gy pro model and here I'm just using the generate contact method and I'm just passing the input what is the meaning of light as an input to my uh gen G Pro Model so this might take few seconds more to generate the response okay so now you can see that it take around def fallowing the time that it has taken to generate that response so it's around 10 second so let's see what the response our model has generated the meaning of life is a multiac and deeply personal question that has been founded by philosophers and individual throughout history while while there is no single univers universally agreed upon answer several prominent themes and perspective imer you now you can see the answer is generated by the model but it's not in the proper format like we need to bring it in the proper format we need to add markdowns as well I have just created a function two. markdown so that we can add markdown so if I just run this cell now so now you can see that our answer is in the form of proper markdown so this is the answer and we have just formatted this answer into this uh using this function and now it's in the proper markdown for so the meaning of life is deeply personal question that has been ped by philosophers and visual throughout history while there is no single agre on answered several prominent teams and perspective emerge while considering this question while purpose and fulfillment happiness and willbe so these are the on the mark uh headings which are present in the form of markdowns so in some cases uh the API will fail to return the result so you can just use this prom that feedback method to see why the API has failed to return any result or if you will see if it has blocked your result due to safety concerns so or if it have blocked your prompt due to safing concern so you can simply write respond. prom feedback currently you can see we are able to generate the response but if any case API fail to resarch the result you can simply write prop that feedback to see why the AP APA failed to uh uh fail to answer or fail to return the result so there are several reasons like if you have uh pass an input which is in the form of ha speech or harassment or dangerous content then it will not return a response okay so G can return multiple responses for a single prompts like you can see over here we have passed a single prompt what is the meaning of life and we have only one round response which is over here but G model can also return multiple responses for a single PR and you can review those responses by writing response. candidate s will show you all the responses that are generated by the jam model so now you can see here we have all the responses that are generated by the jam model in respond to our prompt so now usually we see that when we pass the input prompt and we have the answer but if by default the model returns a response after completed the entire generation process you can also stream the response at is being generated so we can make the we can stream the response as well like it will be generated step by step like we can stream the response process like we shouldn't wait for the response to be completely generated and we can streamline all this process and you can use this by setting stream is equal to True okay so you can also stream the response as it is being generated and the model will return the chunks of the response as soon as they are generated okay so let's wait for this cell so now you can see here we have the response and we are just passing the same input prom the meaning of live is personal and subjective question that has encountered by philosopher religious readers and thinkers throughout history and here we have the response so now we have seen that how we can pass that in text as input and we can uh our model will uh generate output in the form of text as well now we will in our input prompt we will pass text as well as the image as our input so in our input prompt we passing the image as well as the text as the input okay so first of all we will only pass the image as our input and our our model will generate a response in the form of text okay so here we have the input image so you can if you just click on this link uh you can see that this is our input image which we are using so we are just assigning the this image uh this the name image jpg and you can see if you just run this cell you will see the image will appear over here it will be downloaded in the Google collab notbook and you can simply display that image in your Google cab notebook as well using the display Library which we have imported at the start now you can see this is the image so if I just pass this image to the uh G provision model so if we have uh input in the form of image or if we have input in the form of image and text then we will using G provision model so I will just pass this image as an input to the G provision model so let's see what response we get from here so this might take few more seconds before we get the response so like you can see that chicken meal preparation balls with brown rice and roasted broccoli and B pepper so it has given a response from here so now we will provide both text and image in the prompt so in our input we will providing the image as well as a text in the as the input so I will just write the text write a short engaging block post based on this picture like this picture it should include a description of the meal in the photo and talk about by JY me print and here we have the image this is the text as input and here this image is being passed as the input over here as well and we have stretch stream is equal to true so let's run this cell now so now it will generate the response over here and let's see what response do we get over here so here we have the response me preparing can be a great way to save time and money and it can help you to eat healthier here you can see we have the complete response so with gini model we can represent text into the form of vectors as well so with embedding model we can convert text into vectors so vectors are basically floating Point numbers so embedding is a technique used to represent information as a list of floating Point numbers with gmany you can uh represent text word sentences blocks of text into vectors so now you can see that uh we can use embed d-h content method to generate embedding so the matter handling handles embeddings for the following TOS so you can see the TOs details over here and the description is provided over here as well so I will just use ed- content method and here in the content I will just pause a text uh so I just want to convert this text into vectors using giny so here you can see we are using this embedding model provided by JY and we want to just convert this text into vectors or floating Point number and we have a toss type as retrieval document and you can see the details over here so if I just run this text this will convert the text into vectors so now if we just passed uh so now you can see here we have pass only a single line of text but if we have want to pass the text or batches of uh text in the form of batches of strings okay so we can just pass it over here like you can see we have different multiple sentences over here what is the meaning of life how much would would uh would chck chck how does the brain work so we want to pass all this text to our embedding model and we want to generate uh we want to convert this text into floating Point numbers or we just uh using embeding we want to convert this text into vectors okay so I will just run this text cell now so now you can see that uh using embedding model provided by Jony we are able to convert this text into vectors or floating Point number and you can see the response over here so in this tutorial I have provided a quick overview of of how you can use J pro model and I hope you have learned something in this tutorial thank you for watching
Info
Channel: Muhammad Moin
Views: 1,856
Rating: undefined out of 5
Keywords: Gemini, build with gemini, google gemini, google gemini pro, gemini pro, gemini pro vision, gemini pro api, gemini pro vision api, Gemini in Google Colab, run gemini, google gemini in colab, llms, generative ai, generative model, google
Id: mTkWXzM__aY
Channel Id: undefined
Length: 15min 39sec (939 seconds)
Published: Sat Dec 16 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.