Learn more
How To

Integrating Vertex AI with Google BigQuery for Continuous Image Analysis in Retool

Integrate Google BigQuery and Vertex AI with Retool to build powerful applications for continuous image analysis. This post guides you through setting up a Retool application to perform image classification using Vertex AI and BigQuery. Learn how to configure your environment, prepare data, set up Retool, and automate the image classification process for scalable and efficient workflows.

Britton Stamper
July 22, 2024
Integrating Vertex AI with Google BigQuery for Continuous Image Analysis in Retool
Table of Contents

Integrating Google BigQuery and Vertex AI with Retool enables you to build powerful applications for continuous image analysis. Retool is a platform that allows you to quickly build internal tools with a drag-and-drop interface, making it ideal for integrating various services and performing complex workflows. This blog post will guide you through setting up a Retool application for continuous image classification using Vertex AI and BigQuery.

Step 1: Set Up Your Environment

Install Required Libraries

Ensure that your Google Cloud SDK and required libraries are set up:

pip install google-cloud-bigquery google-cloud-aiplatform google-auth

Set Up Google Cloud Credentials

Make sure your Google Cloud credentials are configured:

export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/credentials.json"

Step 2: Configure BigQuery and Vertex AI

Preparing Your Data in BigQuery

First, ensure your image data is stored and accessible in BigQuery. Typically, image data might be stored in Cloud Storage, with metadata and paths stored in BigQuery.

-- Example query to create a table with image paths
CREATE TABLE my_dataset.image_data AS
SELECT
 image_id,
 image_path
FROM
 external_image_source;

Configuring Vertex AI

Set up Vertex AI for image classification. Use Vertex AI to create a model or deploy a pre-trained model.

from google.cloud import aiplatform

# Initialize Vertex AI
aiplatform.init()

# Upload and deploy a model
model = aiplatform.Model.upload(
   display_name='my_image_classification_model',
   artifact_uri='gs://path_to_model_artifact',
   serving_container_image_uri='gcr.io/cloud-aiplatform/prediction/tf2-cpu.2-3:latest'
)

Step 3: Setting Up Retool

Connect BigQuery to Retool

  1. Add a BigQuery Resource:
    • Go to Retool, navigate to Resources, and add a new BigQuery Resource.
    • Authenticate using your Google Cloud credentials.
  2. Create a Query to Fetch Image Paths:
  3. SELECT image_path FROM my_dataset.image_data WHERE processed = FALSE;

Integrate Vertex AI with Retool

  1. Add a REST API Resource:
    • Go to Resources and add a new REST API Resource.
    • Set the base URL to your Vertex AI endpoint.
  2. Create a Query to Classify Images:
  3. const imagePath = {{ table.selectedRow.data.image_path }};
    const response = await fetch(`${baseUrl}/v1/models/my_image_classification_model:predict`, {
       method: 'POST',
       headers: {
           'Authorization': `Bearer ${apiKey}`,
           'Content-Type': 'application/json'
       },
       body: JSON.stringify({ instances: [imagePath] })
    });
    return await response.json();

Update BigQuery with Classification Results

Create a query to update BigQuery with the classification results:

UPDATE my_dataset.image_data
SET prediction = {{ prediction }}, processed = TRUE
WHERE image_path = {{ imagePath }};

Step 4: Building the Retool Application

Create the Interface

  1. Image Upload:
    • Add a file upload component to upload images to Cloud Storage.
    • Use a button to trigger the storage of the image path in BigQuery.
  2. Display Images:
    • Use a table to display images that need to be processed.
    • Add a button to classify the selected image using the Vertex AI query.
  3. Show Results:
    • Display the prediction results on the UI.
    • Add a button to update BigQuery with the classification results.

Conclusion

By integrating Google BigQuery and Vertex AI with Retool, you can create a powerful application for continuous image analysis. This setup enables you to leverage the advanced AI capabilities of Vertex AI and the robust data handling of BigQuery, all within an easy-to-use Retool interface. Whether for medical image analysis, retail, or manufacturing, this integration provides a scalable and efficient solution for ongoing image classification tasks. For more detailed information, refer to the Google Cloud documentation and Retool documentation.

We're here to help!

Get the Semantic Layer Guide!

Everything that a data leader needs to understand and deploy metrics at scale

Download The Full Guide

Core Semantic Layer Concepts

Benefits and ROI

Implementation Steps

Get started with the next generation of data applications

Create an account to connect your business and elevate how your operate.

ABOUT THE AUTHOR
Britton Stamper

Britton is the CTO of Push.ai and oversees Product, Design, and Engineering. He's been a passionate builder, analyst and designer who loves all things data products and growth. You can find him reading books at a coffee shop or finding winning strategies in board games and board rooms.

Enjoyed this read?

Stay up to date with the latest product updates and insights sent straight to your inbox!

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.