Starting April 29, 2025, Gemini 1.5 Pro and Gemini 1.5 Flash models are not available in projects that have no prior usage of these models, including new projects. For details, see Model versions and lifecycle.
Stay organized with collections
Save and categorize content based on your preferences.
In this step, you set up your Google Cloud project and Python environment in
Cloud Shell, enable the required APIs, and assign the Identity and Access Management
(IAM) roles that you need to complete the tutorial.
You also set up a GitHub repository containing the app source files by forking
and cloning the GoogleCloudPlatform/generative-ai
repository. After completing these steps, you verify the setup by running and
testing the app locally in Cloud Shell.
Before you begin
Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Enable the Vertex AI, Compute Engine, Artifact Registry, Identity-Aware Proxy (IAP), Cloud Run Admin, Cloud Build, Identity and Access Management (IAM) API, and Gemini for Google Cloud APIs.
Make sure that you have the following role or roles on the project:
Vertex AI User, Cloud Build Editor, Cloud Run Admin, Artifact Registry Admin, Compute Load Balancer Admin, Service Account User, IAP Policy Admin, OAuth Config Editor, and Service Usage Admin.
In the Principal column, find all rows that identify you or a group that
you're included in. To learn which groups you're included in, contact your
administrator.
For all rows that specify or include you, check the Role column to see whether
the list of roles includes the required roles.
Enable the Vertex AI, Compute Engine, Artifact Registry, Identity-Aware Proxy (IAP), Cloud Run Admin, Cloud Build, Identity and Access Management (IAM) API, and Gemini for Google Cloud APIs.
Make sure that you have the following role or roles on the project:
Vertex AI User, Cloud Build Editor, Cloud Run Admin, Artifact Registry Admin, Compute Load Balancer Admin, Service Account User, IAP Policy Admin, OAuth Config Editor, and Service Usage Admin.
In the Principal column, find all rows that identify you or a group that
you're included in. To learn which groups you're included in, contact your
administrator.
For all rows that specify or include you, check the Role column to see whether
the list of roles includes the required roles.
At the bottom of the Google Cloud console, a
Cloud Shell
session starts and displays a command-line prompt. Cloud Shell is a shell environment
with the Google Cloud CLI
already installed and with values already set for
your current project. It can take a few seconds for the session to initialize.
In the Cloud Shell terminal, run the following commands to clone the
forked repository and set the gemini-streamlit-cloudrun
directory as the active directory:
cd git clone https://github.com/GIT_USER_NAME/FORK_NAME/ cd FORK_NAME/gemini/sample-apps/gemini-streamlit-cloudrun
Replace the following:
GIT_USER_NAME: Your GitHub username.
FORK_NAME: The name of the fork repository that you just created in GitHub.
Set up the environment and dependencies
In the Cloud Shell terminal, run the following commands to set up a virtual environment:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-27 UTC."],[],[],null,["# Step 1: Set up your project and source repository\n\nIn this step, you set up your Google Cloud project and Python environment in\nCloud Shell, enable the required APIs, and assign the Identity and Access Management\n(IAM) roles that you need to complete the tutorial.\nYou also set up a GitHub repository containing the app source files by forking\nand cloning the [`GoogleCloudPlatform/generative-ai`](https://github.com/GoogleCloudPlatform/generative-ai)\nrepository. After completing these steps, you verify the setup by running and\ntesting the app locally in Cloud Shell.\n\nBefore you begin\n----------------\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Vertex AI, Compute Engine, Artifact Registry, Identity-Aware Proxy (IAP), Cloud Run Admin, Cloud Build, Identity and Access Management (IAM) API, and Gemini for Google Cloud APIs.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=compute.googleapis.com, artifactregistry.googleapis.com, iap.googleapis.com, run.googleapis.com, cloudbuild.googleapis.com, iam.googleapis.com, cloudaicompanion.googleapis.com)\n-\n\n Make sure that you have the following role or roles on the project:\n\n Vertex AI User, Cloud Build Editor, Cloud Run Admin, Artifact Registry Admin, Compute Load Balancer Admin, Service Account User, IAP Policy Admin, OAuth Config Editor, and Service Usage Admin.\n\n #### Check for the roles\n\n 1.\n In the Google Cloud console, go to the **IAM** page.\n\n [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)\n 2. Select the project.\n 3.\n In the **Principal** column, find all rows that identify you or a group that\n you're included in. To learn which groups you're included in, contact your\n administrator.\n\n 4. For all rows that specify or include you, check the **Role** column to see whether the list of roles includes the required roles.\n\n #### Grant the roles\n\n 1.\n In the Google Cloud console, go to the **IAM** page.\n\n [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)\n 2. Select the project.\n 3. Click person_add **Grant access**.\n 4.\n In the **New principals** field, enter your user identifier.\n\n This is typically the email address for a Google Account.\n\n 5. In the **Select a role** list, select a role.\n 6. To grant additional roles, click add **Add\n another role** and add each additional role.\n 7. Click **Save**.\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Vertex AI, Compute Engine, Artifact Registry, Identity-Aware Proxy (IAP), Cloud Run Admin, Cloud Build, Identity and Access Management (IAM) API, and Gemini for Google Cloud APIs.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=compute.googleapis.com, artifactregistry.googleapis.com, iap.googleapis.com, run.googleapis.com, cloudbuild.googleapis.com, iam.googleapis.com, cloudaicompanion.googleapis.com)\n-\n\n Make sure that you have the following role or roles on the project:\n\n Vertex AI User, Cloud Build Editor, Cloud Run Admin, Artifact Registry Admin, Compute Load Balancer Admin, Service Account User, IAP Policy Admin, OAuth Config Editor, and Service Usage Admin.\n\n #### Check for the roles\n\n 1.\n In the Google Cloud console, go to the **IAM** page.\n\n [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)\n 2. Select the project.\n 3.\n In the **Principal** column, find all rows that identify you or a group that\n you're included in. To learn which groups you're included in, contact your\n administrator.\n\n 4. For all rows that specify or include you, check the **Role** column to see whether the list of roles includes the required roles.\n\n #### Grant the roles\n\n 1.\n In the Google Cloud console, go to the **IAM** page.\n\n [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)\n 2. Select the project.\n 3. Click person_add **Grant access**.\n 4.\n In the **New principals** field, enter your user identifier.\n\n This is typically the email address for a Google Account.\n\n 5. In the **Select a role** list, select a role.\n 6. To grant additional roles, click add **Add\n another role** and add each additional role.\n 7. Click **Save**.\n\n\u003cbr /\u003e\n\nSet up the source repository\n----------------------------\n\n1. In GitHub, fork the [GoogleCloudPlatform/generative-ai](https://github.com/GoogleCloudPlatform/generative-ai) repository. [Learn more about forking repositories in GitHub](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo).\n\n [Fork the repository in GitHub](https://github.com/GoogleCloudPlatform/generative-ai/fork)\n\n\u003c!-- --\u003e\n\n2. In the Google Cloud console, activate Cloud Shell.\n\n [Activate Cloud Shell](https://console.cloud.google.com/?cloudshell=true)\n\n\n At the bottom of the Google Cloud console, a\n [Cloud Shell](/shell/docs/how-cloud-shell-works)\n session starts and displays a command-line prompt. Cloud Shell is a shell environment\n with the Google Cloud CLI\n already installed and with values already set for\n your current project. It can take a few seconds for the session to initialize.\n3. In the Cloud Shell terminal, run the following commands to clone the forked repository and set the `gemini-streamlit-cloudrun` directory as the active directory: \n\n ```\n cd\n git clone https://github.com/GIT_USER_NAME/FORK_NAME/\n cd FORK_NAME/gemini/sample-apps/gemini-streamlit-cloudrun\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eGIT_USER_NAME\u003c/var\u003e: Your GitHub username.\n - \u003cvar translate=\"no\"\u003eFORK_NAME\u003c/var\u003e: The name of the fork repository that you just created in GitHub.\n\nSet up the environment and dependencies\n---------------------------------------\n\n1. In the Cloud Shell terminal, run the following commands to set up a virtual environment:\n\n python3 -m venv gemini-streamlit\n source gemini-streamlit/bin/activate\n pip install -r requirements.txt\n\n2. Run the following commands to set the environment variables needed for Vertex AI initialization:\n\n export GCP_PROJECT=$GOOGLE_CLOUD_PROJECT\n export GCP_REGION='us-central1' \n\nTest the app locally\n--------------------\n\n1. From the Cloud Shell terminal, run the app by running the following command:\n\n streamlit run app.py \\\n --browser.serverAddress=localhost \\\n --server.enableCORS=false \\\n --server.enableXsrfProtection=false \\\n --server.port 8080\n\n2. To preview the app, in the Cloud Shell taskbar, click , and then click **Preview on port 8080**.\n\n For more information about using the Web Preview feature, see [Preview web apps](/shell/docs/using-web-preview)."]]