arrow_back

Build an AI Image Recognition app using Gemini on Vertex AI

Acceder Unirse
Obtén acceso a más de 700 labs y cursos

Build an AI Image Recognition app using Gemini on Vertex AI

Lab 15 minutos universal_currency_alt Sin costo show_chart Introductorio
info Es posible que este lab incorpore herramientas de IA para facilitar tu aprendizaje.
Obtén acceso a más de 700 labs y cursos

Google Cloud self-paced labs logo

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.

  1. Click File > New File to open a new file within the Code Editor.
  2. 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)
  1. Click File > Save, enter genai.py for the Name field and click Save.

  2. To set the environment variables in the new terminal, run the following command:

    export GOOGLE_CLOUD_PROJECT='{{{ project_0.project_id | "project-id" }}}' export GOOGLE_CLOUD_LOCATION='{{{ project_0.default_region | "REGION" }}}' export GOOGLE_GENAI_USE_VERTEXAI=True
  3. 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 400 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.

Antes de comenzar

  1. Los labs crean un proyecto de Google Cloud y recursos por un tiempo determinado
  2. .
  3. Los labs tienen un límite de tiempo y no tienen la función de pausa. Si finalizas el lab, deberás reiniciarlo desde el principio.
  4. En la parte superior izquierda de la pantalla, haz clic en Comenzar lab para empezar

Usa la navegación privada

  1. Copia el nombre de usuario y la contraseña proporcionados para el lab
  2. Haz clic en Abrir la consola en modo privado

Accede a la consola

  1. Accede con tus credenciales del lab. Si usas otras credenciales, se generarán errores o se incurrirá en cargos.
  2. Acepta las condiciones y omite la página de recursos de recuperación
  3. No hagas clic en Finalizar lab, a menos que lo hayas terminado o quieras reiniciarlo, ya que se borrará tu trabajo y se quitará el proyecto

Este contenido no está disponible en este momento

Te enviaremos una notificación por correo electrónico cuando esté disponible

¡Genial!

Nos comunicaremos contigo por correo electrónico si está disponible

Un lab a la vez

Confirma para finalizar todos los labs existentes y comenzar este

Usa la navegación privada para ejecutar el lab

Usa una ventana de navegación privada o de Incógnito para ejecutar el lab. Así evitarás cualquier conflicto entre tu cuenta personal y la cuenta de estudiante, lo que podría generar cargos adicionales en tu cuenta personal.