Get access to over 700 hands-on labs, skill badges, and courses
bb-ide-genai-001
Overview
Labs are timed and cannot be paused. The timer starts when you click Start Lab.
The included cloud terminal is preconfigured with the gcloud SDK.
Use the terminal to execute commands and then click Check my progress to verify your work.
Objective
Generative AI on Vertex AI (also known as genAI or gen AI) gives you access to Google's large generative AI models so you can test, tune, and deploy them for use in your AI-powered applications. In this lab, you will:
Connect to Vertex AI (Google Cloud AI platform): Learn how to establish a connection to Google's AI services using the Vertex AI SDK.
Load a pre-trained generative AI model -Gemini: Discover how to use a powerful, pre-trained AI model without building one from scratch.
Send image + text questions to the AI model: Understand how to provide input for the AI to process.
Extract text-based answers from the AI: Learn to handle and interpret the text responses generated by the AI model.
Understand the basics of building AI applications: Gain insights into the core concepts of integrating AI into software projects.
Working with Vertex AI Python SDK
After starting the lab, you will get a split pane view consisting of the Code Editor on the left side and the lab instructions on the right side. Follow these steps to interact with the Generative AI APIs using Vertex AI Python SDK.
Click File > New File to open a new file within the Code Editor.
Copy and paste the provided code snippet into your file.
from google import genai
from google.genai.types import HttpOptions, Part
client = genai.Client(http_options=HttpOptions(api_version="v1"))
response = client.models.generate_content(
model="gemini-2.0-flash-001",
contents=[
"What is shown in this image?",
Part.from_uri(
file_uri="gs://cloud-samples-data/generative-ai/image/scones.jpg",
mime_type="image/jpeg",
),
],
)
print(response.text)
Click File > Save, enter genai.py for the Name field and click Save.
To set the environment variables in the new terminal, run the following command:
Execute the Python file by invoking the below command inside the terminal within the Code Editor pane to view the output.
/usr/bin/python3 /genai.py
Note: If you encounter a 500 error, try re-running the code.
Code Explanation
The code snippet is loading a pre-trained AI model called Gemini (gemini-2.0-flash-001) on Vertex AI.
The code calls the generate_content method of the loaded Gemini model.
The input to the method is an image URI and a prompt containing a question about the image.
The code uses Gemini's ability to understand images and text together. It uses the text provided in the prompt to describe the contents of the image.
Try it yourself! Experiment with different image URIs and prompt questions to explore Gemini's capabilities.
Click Check my progress to verify the objective.
Generate content for the image
Congratulations!
You have completed the lab! Congratulations!!
Copyright 2025 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
Labs create a Google Cloud project and resources for a fixed time
Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
On the top left of your screen, click Start lab to begin
Use private browsing
Copy the provided Username and Password for the lab
Click Open console in private mode
Sign in to the Console
Sign in using your lab credentials. Using other credentials might cause errors or incur charges.
Accept the terms, and skip the recovery resource page
Don't click End lab unless you've finished the lab or want to restart it, as it will clear your work and remove the project
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one
Use private browsing to run the lab
Use an Incognito or private browser window to run this lab. This
prevents any conflicts between your personal account and the Student
account, which may cause extra charges incurred to your personal account.
In this lab, you will learn how to use Google's Vertex AI SDK to interact with the powerful Gemini generative AI model, enabling you to ask questions about images and receive insightful text-based responses.