Gemini Pro API in Python: Learn to Access using Google API Key

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
this is amazing what if you can use Gemini API using API Keys generated from Google AI Studio what if you can use generative AI package to interact with your Gemini API what is the difference between Google AI Studio vertex AI API keys and service account that's exactly what we're going to see today let's get [Music] started hi everyone I'm really excited to show you about gerini AP using API key and also we are going to see the difference between vertex Ai and Google AI Studio I'm going to take you through step by step but before that I regularly create videos in regards to Artificial Intelligence on my YouTube channel so do subscribe and click the Bell icon to stay tuned coming to Gemini API there are two ways of accessing this API One is using Google Cloud console another one is using Google AI Studio Google Cloud console looks like this and here you can create your service account from the I am and admin panel either you grant access to the existing email address or you can create a service account on the left hand side by clicking this icon service account is nothing but email address for our software to use so that is all about Google Cloud console and we use vertex AI python package to interact with API but in regards to Google AI Studio we use Google generative AI python package to interact with the API and we generate API key from Google AI Studio to use Gemini API so Google AI Studio looks like this and you can create your API Key by clicking this button keep a copy of the API key that is required to run the current application which we are going to create now let's dive into the code the first step is cond create iph and gerini python equal 3.11 and click enter then cond activate gerini and click enter next export your Google API key which you have just generated from Google AI Studio here and then click enter next pip install Google generative AI package this is the one used to interact with gini API now let's create a file called app.py and open it inside the file import google. generative AI as gen aai then UT OS the first step is the configuration where you pass your API key to gen ai. configure then you define the temperature top P top K and then Max output tokens the second step is initializing the model here gen. generative model we are defining the model name and passing the generation config and the third step is to generate content that means ask questions to the large language model to do that response equals model. generate content and I'm asking a question create a meal plan for today and finally you're printing out the response so this is similar to vertex AI API which I've shown before which I will link that in the description below in this we are importing generative AI package defining the configuration initializing the model using gen. generative model and then ask you to generate content by asking a question now we're going to run this code in your terminal Python app.py and click enter now we got breakfast lunch dinner snacks and other tips now we're going to see how we can stream this response to do that I'm adding Chunk in response and then printing the output now going to delete this line now going back to our terminal Python app.py and click enter now it's going to stream it streamed very quickly that you couldn't see the streamed response now we are going to use gini Vision API so we're going to change the model name to gini Pro Vision then we are going to import the path from path lib next we are going to change the output is print response. txt the configurations remain the same in the generate content step we are going to import image image path equals path image. jpeg next we are reading bytes from that image next we're going to create prompt Parts which contains the question to ask about the image and the image so the question we going to ask is describe what the people are doing in this image so this is the image and we going to describe what the people are doing and finally response equals model. generate content and passing the prompts it's multimodal so it can accept text and image and finally printing the response now we're going to run this code in your terminal Python app.py and click enter here is the answer two men are playing Cricket the man in the foreground is the batsman and the Man in the background is the Wicket keeper the batsman is about to hit the ball with this bat the Wicket keeper is standing behind the stumps and ready to catch the ball if the batsman misses it that's it as simple simple as that now you are able to integrate Gemini into your own python application I'm going to create more videos similar to this so stay tuned I hope you like this video do like share and subscribe and thanks for watching
Info
Channel: Mervin Praison
Views: 4,098
Rating: undefined out of 5
Keywords: google gemini, google gemini ai, gemini, ai, google bard, google ai, gemini ai, introducing google gemini, what is google gemini, google gemini demo, google gemini hands on, google gemini how to use, google gemini ai demo, how to use google gemini ai, how to use google gemini, api, gemini api, how to use gemini api, how to access gemini api, gemini ai pro, gemini ai api tutorial, tutorial, gemini pro api, gemini pro vision, gemini vision api, gemini api key, api key, ultra
Id: UKQUWeYYrxE
Channel Id: undefined
Length: 5min 12sec (312 seconds)
Published: Wed Dec 20 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.