
Before you begin
- 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
Create BigQuery Python notebook and connect to runtime
/ 10
Create the cloud resource connection and grant IAM role
/ 10
Review images, dataset, and grant IAM role to service account
/ 10
Create the dataset and customer reviews table in BigQuery
/ 30
Create the Gemini Pro model in BigQuery
/ 10
Prompt Gemini to analyze customer reviews for keywords and sentiment
/ 20
Respond to customer reviews
/ 10
In this lab you learn how to extract keywords and assess customer sentiment in customer reviews using BigQuery Machine Learning with remote models (Gemini Pro).
BigQuery is a fully managed, AI-ready data analytics platform that helps you maximize value from your data and is designed to be multi-engine, multi-format, and multi-cloud. One of its key features is BigQuery Machine Learning, which lets you create and run machine learning (ML) models by using SQL queries or with Colab Enterprise notebooks.
Gemini is a family of generative AI models developed by Google DeepMind that is designed for multimodal use cases. The Gemini API gives you access to the Gemini Pro, Gemini Pro Vision, and Gemini Flash models.
At the end of this lab you will build a Python-based customer service application in a Colab Enterprise notebook within BigQuery, using the Gemini Flash model to respond to audio-based customer reviews.
In this lab, you learn how to:
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.
This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the left is the Lab Details pane with the following:
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
In this task you create a BigQuery Python notebook and connect the notebook to the runtime.
In the Google Cloud console, on the Navigation menu, click BigQuery.
Click DONE on the Welcome pop-up.
Click Notebook.
Select
Click SELECT.
You will also notice that the Python notebook is added in the notebooks section of the explorer under your project.
Delete all of the cells that are in the notebook by clicking the trash icon that appears when you hover over each cell.
Once complete, the notebook should be blank and you are ready to move on to the next step.
Click Connect.
Click on the Qwiklabs student ID.
Please wait. It may take up to 3 minutes to connect to the runtime.
At some point, you will see the connection status update to Connected at the bottom of your browser window.
Click Check my progress to verify the objective.
In this task you create a Cloud resource connection in BigQuery, so you can work with Gemini Pro and Gemini Flash models. You will also grant the cloud resource connection's service account IAM permissions, through a role, to enable it access the Vertex AI services.
You will use the Python SDK and the Google Cloud CLI to create the resource connection. But first you need to import Python libraries and set the project_id and region variables.
Create a new code cell with the code below:
This code will import the Python libraries.
Run this cell. The libraries are now loaded and ready to be used.
Create a new code cell with the code below:
Run this cell. The variables for project_id and region are set.
Create a new code cell with the code below:
This code will use the Google Cloud CLI command bq mk --connection
to create the resource connection.
Run this cell. The resource connection is now created.
Click the view actions button next to your project id in the Explorer.
Choose Refresh contents.
Expand external connections. Notice us.gemini_conn
is now listed as an external connection.
Click us.gemini_conn.
In the Connection info pane, copy the service account ID to a text file for use in the next task.
In the console, on the Navigation menu, click IAM & Admin.
Click Grant Access.
In the New principals field, enter the service account ID that you copied earlier.
In the Select a role field, enter Vertex AI, and then select Vertex AI User role.
Click Save.
The result is the service account now includes the Vertex AI User role.
Click Check my progress to verify the objective.
In this task, you review the dataset and the audio files, then you grant IAM permissions to the cloud resource connection's service account.
Before you dive into this task to grant permissions to the resource connection service account, review the dataset and the image files.
In the Google Cloud console, select the Navigation menu (), and then select Cloud Storage > Buckets.
Click on the
The bucket contains the gsp1249 folder, open the folder. You will see four items in it:
audio
folder contains all audio files you will analyze. Feel free to access the audio folder and review the audio files.customer_reviews.csv
file is the dataset that contains the text based customer reviews.images
folder contains an image file you will use later in this lab. Feel free to access this folder and view the image file contained within it.notebook.ipynb
, this is a copy of the notebook you are creating in this lab. Feel free to review it as needed.Granting IAM permissions to the resource connection's service account before you start working in BigQuery will ensure you do not encounter access denied errors when running queries.
Return to the root of the bucket.
Click PERMISSIONS.
Click GRANT ACCESS.
In the New principals field, enter the service account ID you copied earlier.
In the Select a role field, enter Storage Object, and then select Storage Object Admin role.
Click Save.
The result is the service account now includes the Storage Object Admin role.
Click Check my progress to verify the objective.
In this task, you create a dataset for the project, the table for customer reviews.
For the dataset you will use the following properties:
Field | Value |
---|---|
Dataset ID | gemini_demo |
Location type | select Multi-region |
Multi-region | select US |
Return to the Python notebook in BigQuery.
Create a new code cell with the code below:
Notice the code starts with %%bigquery
, this tells Python that the code immediately following this statement will be SQL code.
Run this cell.
The result is the SQL code will create the gemini_demo
dataset in your project residing in the US region listed underneath your project in the BigQuery Explorer.
To create the customer reviews table you will use a SQL query.
Create a new code cell with the code below:
Run this cell.
The result is the customer_reviews
table is created with sample customer review data, including the customer_review_id
, customer_id
, location_id
, review_datetime
, review_text
, social_media_source
, and social_media_handle
for each review in the dataset.
In the Explorer, click on the customer_reviews table and review the schema and details.
Query the table to review records by creating a new code cell with the code below.
Run this cell.
The result is the records are displayed from the table with all columns included.
Click Check my progress to verify the objective.
Now that the tables are created, you can begin to work with them. In this task, you create the Gemini Pro model in BigQuery.
Return to the Python notebook.
Create a new code cell with the code below:
Run this cell.
The result is the gemini_pro
model is created and you see it added to the gemini_demo
dataset, in the models section.
In the Explorer, click on the gemini_pro model and review the details and schema.
Click Check my progress to verify the objective.
In this task, you will use Gemini Pro model to analyze each customer review for sentiment, either positive or negative.
Create a new code cell with the code below:
Run this cell.
This query takes customer reviews from the customer_reviews
table, constructs the prompt, and then uses these with the gemini_pro
model to classify the sentiment of each review. The results are then stored in a new table customer_reviews_analysis
so that you may use it later for further analysis.
Please wait. The model takes approximately 30 seconds to process the customer review records.
When the model is finished, the result is the customer_reviews_analysis
table is created.
In the Explorer, click on the customer_reviews_analysis table and review the schema and details.
Create a new code cell with the code below:
Run this cell.
The result is rows with the ml_generate_text_llm_result
column (containing the sentiment analysis), the customer review text, customer id and location id.
Take a look at some of the records. You may notice some of the results for positive and negative may not be formatted correctly, with extraneous characters like periods, or extra space. You can sanitize the records by using the view below.
Create a new code cell with the code below:
Run this cell.
The code creates the view, cleaned_data_view
and includes the sentiment results, the review text, the customer id and the location id. It then takes the sentiment result (positive or negative) and ensures that all letters are made lower case, and extraneous character like extra spaces or periods are removed. The resulting view will make it easier to do further analysis in later steps within this lab.
Create a new code cell with the code below:
Run this cell.
Notice that the sentiment
column now has clean values for positive and negative reviews. You will be able to use this view in later steps to build a report.
You can use Python and the Matplotlib library to create a bar chart report of the counts of positive and negative reviews.
Create new code cell to use the BigQuery client to query the cleaned_data_view for positive and negative reviews, and group the reviews by sentiment, storing the results in a dataframe.
Run this cell.
The result of running the cell is a table output with total counts of positive and negative reviews.
Create a new cell to define variables for the report.
Run this cell. There is no output.
Create a new cell to build the report.
Run this cell.
The result is a bar chart with the counts of positive and negative reviews.
Alternatively you can build a simple, color-coded report of the counts of negative and positive sentiment using the code below:
Negative | Positive |
---|---|
{count[0]} | {count[1]} |
Click Check my progress to verify the objective.
Data beans wants to experiment with customer reviews using images and audio recordings. In this section of this notebook you will use CloudStorage, BigQuery, Gemini Flash, and Python to perform sentiment analysis on customer reviews provided to data beans as images and audio files. And from the resulting analysis you will generate customer service responses to be sent back to the customer thanking them for their review and actions the coffee house can take based upon the review.
You will do this both at scale and then later with one image and audio file, so that you may learn how to create a Proof of Concept application for customer service representatives. This enables a "human-in-the-loop" strategy for the customer feedback process, where customer service representatives can take action with both the customer and individual coffee houses.
Create a new cell to conduct sentiment analysis on audio files and respond to the customer.
A few key points about this cell:
Run this cell.
The result is all 5 of the audio files are analysed and the output of the analysis is provided as a JSON response. The JSON response could be parsed accordingly and routed to the appropriate applications to respond to the customer or the location with actions for improvement.
In this section of the lab, you will learn how to create a customer service application based upon a negative review analysis. You will:
Create a new cell, and enter the following code, so that you can Generate the transcript for the negative review audio file, create the JSON object, and associated variables.
A few key points about this cell:
Run the cell.
The output is minimal, just the uri of the audio file processed and processing messages.
Create an HTML based table from the selected values and load the audio file containing the negative review into the player.
customer_id: 7061 - @coffee_lover789 |
---|
{transcript} | {sentiment} feedback | ||||
|
|||||
Customer summary:{summary} | |||||
Recommended actions:{actions} | |||||
Suggested Response:{response} |
A few key points about this cell:
Look for the <td style="padding:10px;">
tag with the {summary}
output included. Add new line of code before this tag.
Paste <td rowspan="3" style="padding: 10px;"><img src="<authenticated url here>" alt="Customer Image" style="max-width: 300px;"></td>
into this new line of code.
Find the Authenticated URL for the image_7061.png file. Go to Cloud Storage, select the only bucket you have there, the images folder, and then click on the image.
On the resulting page, copy the Authenticated URL for the image.
Return to the Python notebook in BigQuery. Replace the <authenticated url here>
with the actual Authenticated URL in the code you just pasted.
Run the cell.
Again the output is minimal. Just some processing messages, indicating each step completes.
Create a new cell to download the audio file and load it into the player, using the code below:
A few key points about this cell:
Run the cell.
Create a new cell and enter the code below:
Run the cell.
This cell is where the magic happens. The display method is used to display the HTML and the Audio file loaded into the player. Review the output of the cell. It should look identical to the image below:
Click Check my progress to verify the objective.
You successfully created cloud resource connection in BigQuery. You also created a dataset, tables, and models to prompt Gemini to analyze sentiment and keywords on customer reviews. Finally, you used Gemini to analyze audio-based customer reviews to generate summaries and keywords to respond to customer reviews within a customer service application.
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated April 10, 2025
Lab Last Tested April 10, 2025
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.
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