In diesem Schritt richten Sie Ihr Cloud de Confiance by S3NS -Projekt und Ihre Python-Umgebung in Cloud Shell ein, aktivieren die erforderlichen APIs und weisen die IAM-Rollen (Identity and Access Management) zu, die Sie für die Durchführung der Anleitung benötigen.
Außerdem richten Sie ein GitHub-Repository mit den Quellcode-Dateien der App ein, indem Sie das Repository GoogleCloudPlatform/generative-ai forken und klonen. Nachdem Sie diese Schritte ausgeführt haben, können Sie die Einrichtung prüfen, indem Sie die App lokal in Cloud Shell ausführen und testen.
Hinweis
-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Cloud de Confiance project.
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.enablepermission. 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.-
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
-
In the Cloud de Confiance 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 Cloud de Confiance 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 identifier for a user in a workforce identity pool. For details, see Represent workforce pool users in IAM policies, or contact your administrator.
- Click Select a role, then search for the role.
- To grant additional roles, click Add another role and add each additional role.
- Click Save.
-
Quell-Repository einrichten
Führen Sie in GitHub einen Fork des Repositorys GoogleCloudPlatform/generative-ai aus. Weitere Informationen zum Forken von Repositories auf GitHub
-
Aktivieren Sie Cloud Shell in der Cloud de Confiance Console.
Unten in der Cloud de Confiance Console wird eine Cloud Shell-Sitzung gestartet und eine Eingabeaufforderung angezeigt. Cloud Shell ist eine Shell-Umgebung, in der das Google Cloud CLI bereits installiert ist und Werte für Ihr aktuelles Projekt bereits festgelegt sind. Das Initialisieren der Sitzung kann einige Sekunden dauern.
- Führen Sie im Cloud Shell-Terminal die folgenden Befehle aus, um den Fork des Repositorys zu klonen und das Verzeichnis
gemini-streamlit-cloudrunals aktives Verzeichnis festzulegen:cd
git clone https://github.com/GIT_USER_NAME/FORK_NAME/
cd FORK_NAME/gemini/sample-apps/gemini-streamlit-cloudrunErsetzen Sie dabei Folgendes:
- GIT_USER_NAME: Ihr GitHub-Nutzername
- FORK_NAME: Der Name des Fork-Repositorys, das Sie gerade in GitHub erstellt haben.
Umgebung und Abhängigkeiten einrichten
Führen Sie im Cloud Shell-Terminal die folgenden Befehle aus, um eine virtuelle Umgebung einzurichten:
python3 -m venv gemini-streamlit source gemini-streamlit/bin/activate pip install -r requirements.txtFühren Sie die folgenden Befehle aus, um die Umgebungsvariablen festzulegen, die für die Initialisierung der Agent Platform erforderlich sind:
export GCP_PROJECT=$GOOGLE_CLOUD_PROJECT export GCP_REGION='us-central1'
App lokal testen
Führen Sie die App im Cloud Shell-Terminal mit dem folgenden Befehl aus:
streamlit run app.py \ --browser.serverAddress=localhost \ --server.enableCORS=false \ --server.enableXsrfProtection=false \ --server.port 8080Wenn Sie eine Vorschau der App ansehen möchten, klicken Sie in der Cloud Shell-Taskleiste auf
und dann auf Vorschau auf Port 8080.
Weitere Informationen zur Verwendung der Webvorschau finden Sie unter Web-Apps in der Vorschau ansehen.