13 C
New York
Monday, March 4, 2024

Curious About Building Excellence with Gemini API?

Curious About Building Excellence with Gemini API?

A Guide to Building with Gemini API Integration

A Blueprint for Next-Level Building Projects

Step into the future of search technology as Google unveils its latest breakthrough, the Gemini model, while Bard stages a remarkable comeback, reclaiming its functionality. In this exciting era of innovation, Gemini promises users unparalleled accuracy in responses, allowing one to transcend traditional search boundaries by inputting a blend of images, audio, and text.

Now, building on the excitement generated by Gemini AI’s announcement, Google takes a significant step forward by providing API access for its Gemini models. Currently available for Gemini Pro, encompassing both text-only and text-and-vision models, this release is particularly noteworthy as it introduces visual capabilities that were previously exclusive to text-only Bard. With your API key, you can now explore Gemini’s multimodal capabilities directly on your computer. Let’s delve into the intricacies of accessing and leveraging the Gemini API in this guide.

Step 1: To kick things off, you need to set up Python and Pip on your PC!

You can download Python from https://www.python.org/downloads/ based on your Operating System. Make sure to download Python Version 3.9 or higher. Read this documentation to get pip installed https://pip.pypa.io/en/stable/installation/

Step 2: Ensure Python and Pip are installed successfully

Run the following commands to verify the installation of Python and Pip.

You should now be able to see the version number on successful installation.

Step 3: Install Google’s Generative AI dependency

Now, execute the following command:

pip install google.generativeai

I am working on Google Colab and here are the results!

Step 4: Setting up the Gemini Pro API Key

Navigate to https://makersuite.google.com/app/apikey and log in using your Google Account.

Once logged in, access the API keys section and initiate the process by selecting the “Create API key in new project” option.

Secure the API key by copying it and maintaining its confidentiality. Avoid publicizing or sharing the API key publicly to ensure the security and integrity of your access.

Step 5: Now, let’s harness the potential of Gemini Pro’s Text-Only Model

Open your code editor(I am using Google Colab. Feel free to use any code editor of your choice such as VSCode, Spyder, etc..) and paste the below code. Also paste your api key in the required place.

import google.generativeai as genai

genai.configure(api_key=‘PASTE YOUR API KEY HERE’)

model = genai.GenerativeModel(‘gemini-pro’)

response = model.generate_content(“How can we manage flood disaster?”)

print(response.text)

“How can we manage flood disaster?” is the query provided to the model! Now let’s check with the response. Save the file with .py extension and execute the code (in case you are working on a desktop code editor).

Here are the results!!

Step 6: Working with Gemini Pro’s Text-and-Vision Model

New7Wonders.jpg

I fed the above image into the model.

Next, copy and paste the below code!

import google.generativeai as genai

import PIL.Image

img = PIL.Image.open(‘New7Wonders.jpg’)

genai.configure(api_key=‘PASTE YOUR API KEY HERE’)

model = genai.GenerativeModel(‘gemini-pro-vision’)

response = model.generate_content([“Can you give some information on this picture?”, img])

print(response.text)

Got the below response!

Isn’t that cool?!

From envisioning groundbreaking projects to pioneering the next wave of technological marvels, the stars are the limit. Keep coding, keep dreaming, and let the spirit of innovation guide you to heights yet unknown. Stay limitless!!

Source link

Latest stories