Passaggio 1: configura il progetto e il repository di origine

In questo passaggio, configurerai il progetto Cloud de Confiance by S3NS e l'ambiente Python in Cloud Shell, abiliterai le API richieste e assegnerai i ruoli Identity and Access Management (IAM) necessari per completare il tutorial. Hai anche configurato un repository GitHub contenente i file sorgente dell'app creando un fork e clonando il repository GoogleCloudPlatform/generative-ai. Dopo aver completato questi passaggi, verifica la configurazione eseguendo e testando l'app localmente in Cloud Shell.

Prima di iniziare

  1. In the Cloud de Confiance console, on the project selector page, select or create a Cloud de Confiance 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  2. Verify that billing is enabled for your Cloud de Confiance project.

  3. Enable the Agent Platform, 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, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  4. Make sure that you have the following role or roles on the project: Agent Platform 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 Cloud de Confiance console, go to the IAM page.

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

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

    Grant the roles

    1. In the Cloud de Confiance console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. Click Grant access.
    4. In the New principals field, enter your user identifier. This is typically the identifier for a user in a workforce identity pool. For details, see Represent workforce pool users in IAM policies, or contact your administrator.

    5. Click Select a role, then search for the role.
    6. To grant additional roles, click Add another role and add each additional role.
    7. Click Save.

Configura il repository di origine

  1. In GitHub, crea un fork del repository GoogleCloudPlatform/generative-ai. Scopri di più sul fork dei repository in GitHub.

    Crea un fork del repository in GitHub

  1. Nella console Cloud de Confiance , attiva Cloud Shell.

    Attiva Cloud Shell

    Nella parte inferiore della console Cloud de Confiance viene avviata una sessione di Cloud Shell e viene visualizzato un prompt della riga di comando. Cloud Shell è un ambiente shell con Google Cloud CLI già installata e con valori già impostati per il progetto corrente. L'inizializzazione della sessione può richiedere alcuni secondi.

  2. Nel terminale Cloud Shell, esegui i comandi seguenti per clonare il repository forked e impostare la directory gemini-streamlit-cloudrun come directory attiva:
    cd
    git clone https://github.com/GIT_USER_NAME/FORK_NAME/
    cd FORK_NAME/gemini/sample-apps/gemini-streamlit-cloudrun

    Sostituisci quanto segue:

    • GIT_USER_NAME: il tuo nome utente GitHub.
    • FORK_NAME: il nome del repository fork che hai appena creato in GitHub.

Configura l'ambiente e le dipendenze

  1. Nel terminale Cloud Shell, esegui questi comandi per configurare un ambiente virtuale:

    python3 -m venv gemini-streamlit
    source gemini-streamlit/bin/activate
    pip install -r requirements.txt
    
  2. Esegui questi comandi per impostare le variabili di ambiente necessarie per l'inizializzazione di Agent Platform:

    export GCP_PROJECT=$GOOGLE_CLOUD_PROJECT
    export GCP_REGION='us-central1' 
    

Testare l'app localmente

  1. Dal terminale Cloud Shell, esegui l'app eseguendo questo comando:

    streamlit run app.py \
      --browser.serverAddress=localhost \
      --server.enableCORS=false \
      --server.enableXsrfProtection=false \
      --server.port 8080
    
  2. Per visualizzare l'anteprima dell'app, fai clic su Pulsante Anteprima web nella barra delle attività di Cloud Shell, quindi fai clic su Anteprima sulla porta 8080.

    Per saperne di più sull'utilizzo della funzionalità Anteprima web, vedi Visualizzare l'anteprima delle app web.