In diesem Schritt richten Sie Ihr Google Cloud -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 abgeschlossen haben, können Sie die Einrichtung überprüfen, indem Sie die App lokal in Cloud Shell ausführen und testen.
Hinweis
- Melden Sie sich in Ihrem Google Cloud -Konto an. Wenn Sie mit Google Cloudnoch nicht vertraut sind, erstellen Sie ein Konto, um die Leistungsfähigkeit unserer Produkte in der Praxis sehen und bewerten zu können. Neukunden erhalten außerdem ein Guthaben von 300 $, um Arbeitslasten auszuführen, zu testen und bereitzustellen.
-
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.
-
Quell-Repository einrichten
Verzweigen Sie das Repository GoogleCloudPlatform/generative-ai auf GitHub. Weitere Informationen zum Forken von Repositories in GitHub
-
Aktivieren Sie Cloud Shell in der Google Cloud Console.
Unten in der Google Cloud 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 für die Vertex AI-Initialisierung erforderlichen Umgebungsvariablen festzulegen:
export GCP_PROJECT=$GOOGLE_CLOUD_PROJECT export GCP_REGION='us-central1'
App lokal testen
Führen Sie im Cloud Shell-Terminal den folgenden Befehl aus, um die App auszuführen:
streamlit run app.py \ --browser.serverAddress=localhost \ --server.enableCORS=false \ --server.enableXsrfProtection=false \ --server.port 8080Klicken Sie in der Cloud Shell-Taskleiste auf
und dann auf Vorschau auf Port 8080, um eine Vorschau der App aufzurufen.
Weitere Informationen zur Verwendung der Webvorschau finden Sie unter Web-Apps in der Vorschau ansehen.