
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
Build a Docker image
/ 50
Deploy the application to Cloud Run
/ 50
This lab demonstrates how to create and deploy an AI-powered chat application using Cloud Run on Google Cloud. The chat application is powered by the Gemini Large Language Model's (LLM) APIs.
You leverage the APIs in a web application and deploy it to Cloud Run, using Cloud Build and Artifact Repository to store the container image of the application build. The application can be used as a starting point for web interfaces using the Gemini APIs.
In this lab, you create a web application that runs on Cloud Run which utilizes APIs provided by the Gemini Large Language Model (LLM) and surfaces them through a simple web interface deployed in the lab.
By creating the application, you gain an understanding of how to build a web application which can utilize Large Language Models, like Gemini, to create engaging, conversation based interactions with end users who can asks questions and receive insightful responses through the chat application.
In this lab, you do the following:
gemini-2.0-flash
model via a chat session.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.
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
Click Activate Cloud Shell at the top of the Google Cloud console.
Click through the following windows:
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
To deploy the Cloud Run application, you download the source from a Cloud Storage bucket.
Next, you build a Docker image for the application and push it to Artifact Registry. Once the container image is built and stored, you reference it to deploy the application to Cloud Run.
chat-app-repo
is available.gcloud auth configure-docker us-central1-docker.pkg.dev
Click Check my progress to verify the objective.
The application has been downloaded and built via Cloud Build. Now you deploy and test it on Cloud Run.
You receive a response generated by the gemini-2.0-flash
API in the output text box below the prompt input.
Click Check my progress to verify the objective.
To understand more about how the application utilizes the Gemini Chat Bison API, you briefly explore the code used by the app.
In Cloud Shell, click Open Editor which opens Cloud Shell Editor for you to browse the code with.
In the Explore pane, expand the folder chat-flask-cloudrun
and select app.py
to begin exploring the code.
Notice the following Python methods:
create_session
: this method creates a new session with Vertex AI using the chat_model = GenerativeModel("gemini-2.0-flash")
model. It is used by the route /gemini
which you will observe further to establish a new chat session.response
: this method retrieves a response.index
and gemini_chat
: the index
and gemini_chat
methods define routes for the application's API. The index
method loads the index.html
page when a user loads the application and the gemini_chat
method submits the user's prompt collected from the index.html
page to the API and returns the results in JSON format.The index.html
file includes inline JavaScript to read the results from the form submission when a user clicks Send and updates the UI with the response of the Gemini API call.
You have now completed the lab! In this lab, you learned how to build and deploy a simple web application using Cloud Build and Artifact Registry. The application is deployed to Cloud Run and utilizes Gemini to respond to end user queries to create a chat based application that allows end users to ask questions and receive responses in a web UI.
...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 May 14, 2025
Lab Last Tested May 14, 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