Step 1: Set up your project and source repository

In this step, you set up your Google Cloud project and Python environment inCloud 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 forkingand cloning theGoogleCloudPlatform/generative-airepository. After completing these steps, you verify the setup by running andtesting the app locally in Cloud Shell.

Before you begin

  1. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    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.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. 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.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.

    Enable the APIs

  5. 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.

    Check for the roles

    1. In the Google Cloud console, go to theIAM page.

      Go to IAM
    2. Select the project.
    3. In thePrincipal 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.

    4. For all rows that specify or include you, check theRole column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to theIAM page.

      Go to IAM
    2. Select the project.
    3. ClickGrant access.
    4. In theNew principals field, enter your user identifier. This is typically the email address for a Google Account.

    5. ClickSelect a role, then search for the role.
    6. To grant additional roles, clickAdd another role and add each additional role.
    7. ClickSave.
  6. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.create permission.Learn how to grant roles.
    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.

    Go to project selector

  7. Verify that billing is enabled for your Google Cloud project.

  8. 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.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enable permission.Learn how to grant roles.

    Enable the APIs

  9. 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.

    Check for the roles

    1. In the Google Cloud console, go to theIAM page.

      Go to IAM
    2. Select the project.
    3. In thePrincipal 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.

    4. For all rows that specify or include you, check theRole column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Google Cloud console, go to theIAM page.

      Go to IAM
    2. Select the project.
    3. ClickGrant access.
    4. In theNew principals field, enter your user identifier. This is typically the email address for a Google Account.

    5. ClickSelect a role, then search for the role.
    6. To grant additional roles, clickAdd another role and add each additional role.
    7. ClickSave.

Set up the source repository

  1. In GitHub, fork theGoogleCloudPlatform/generative-ai repository.Learn more about forking repositories in GitHub.

    Fork the repository in GitHub

  1. In the Google Cloud console, activate Cloud Shell.

    Activate Cloud Shell

    At the bottom of the Google Cloud console, aCloud 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.

  2. In the Cloud Shell terminal, run the following commands to clone the forked repository and set thegemini-streamlit-cloudrun directory as the active directory:
    cd
    git clone https://github.com/GIT_USER_NAME/FORK_NAME/
    cdFORK_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

  1. In the Cloud Shell terminal, run the following commands to set up a virtual environment:

    python3-mvenvgemini-streamlitsourcegemini-streamlit/bin/activatepipinstall-rrequirements.txt
  2. Run the following commands to set the environment variables needed for Vertex AI initialization:

    exportGCP_PROJECT=$GOOGLE_CLOUD_PROJECTexportGCP_REGION='us-central1'

Test the app locally

  1. From the Cloud Shell terminal, run the app by running the following command:

    streamlitrunapp.py\--browser.serverAddress=localhost\--server.enableCORS=false\--server.enableXsrfProtection=false\--server.port8080
  2. To preview the app, in the Cloud Shell taskbar, clickWeb Preview Button, and then clickPreview on port 8080.

    For more information about using the Web Preview feature, seePreview web apps.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2026-02-19 UTC.