In questo passaggio, configuri il tuo Google Cloud progetto e l'ambiente Python in
Cloud Shell, abiliti le API richieste e assegni i ruoli Identity and Access Management
(IAM) necessari per completare il tutorial.
Configuri anche un repository GitHub contenente i file di origine dell'app creando un fork
e clonando il GoogleCloudPlatform/generative-ai
repository. Dopo aver completato questi passaggi, verifichi la configurazione eseguendo e testando l'app in locale in Cloud Shell.
Prima di iniziare
- Accedi al tuo Google Cloud account. Se non conosci Google Cloud, crea un account per valutare le prestazioni dei nostri prodotti in scenari reali. I nuovi clienti ricevono anche 300 $di crediti senza costi per l'esecuzione, il test e il deployment dei workload.
-
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.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your 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.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
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
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
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.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
- Click Grant access.
-
In the New principals field, enter your user identifier. This is typically the email address for a Google Account.
- Click Select a role, then search for the role.
- To grant additional roles, click Add another role and add each additional role.
- Click Save.
-
-
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.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your 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.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.-
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
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
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.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
- Click Grant access.
-
In the New principals field, enter your user identifier. This is typically the email address for a Google Account.
- Click Select a role, then search for the role.
- To grant additional roles, click Add another role and add each additional role.
- Click Save.
-
Configura il repository di origine
In GitHub, crea un fork del repository GoogleCloudPlatform/generative-ai. Scopri di più sulla creazione di fork di repository in GitHub.
-
Nella Google Cloud console, attiva Cloud Shell.
Nella parte inferiore della Google Cloud console, viene avviata una sessiona di Cloud Shell e viene visualizzato un prompt della riga di comando. Cloud Shell è un ambiente shell con Google Cloud CLI già inclusa e installata e con valori già impostati per il progetto corrente. L'inizializzazione della sessione può richiedere alcuni secondi.
- Nel terminale Cloud Shell, esegui i comandi seguenti per clonare il
repository con fork e impostare la
gemini-streamlit-cloudrundirectory come directory attiva:cd
git clone https://github.com/GIT_USER_NAME/FORK_NAME/
cd FORK_NAME/gemini/sample-apps/gemini-streamlit-cloudrunSostituisci quanto segue:
- GIT_USER_NAME: il tuo nome utente GitHub.
- FORK_NAME: il nome del repository con fork che hai appena creato in GitHub.
Configura l'ambiente e le dipendenze
Nel terminale Cloud Shell, esegui i comandi seguenti per configurare un ambiente virtuale:
python3 -m venv gemini-streamlit source gemini-streamlit/bin/activate pip install -r requirements.txtEsegui i comandi seguenti per impostare le variabili di ambiente necessarie per l'inizializzazione di Vertex AI:
export GCP_PROJECT=$GOOGLE_CLOUD_PROJECT export GCP_REGION='us-central1'
Testa l'app in locale
Dal terminale Cloud Shell, esegui l'app eseguendo il comando seguente:
streamlit run app.py \ --browser.serverAddress=localhost \ --server.enableCORS=false \ --server.enableXsrfProtection=false \ --server.port 8080Per visualizzare l'anteprima dell'app, nella barra delle attività di Cloud Shell, fai clic su
, 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.