בשלב הזה, תגדירו את הפרויקט ב- Google Cloud ואת סביבת Python ב-Cloud Shell, תפעילו את ממשקי ה-API הנדרשים ותקצו את התפקידים בניהול הזהויות והרשאות הגישה (IAM) שנדרשים להשלמת המדריך.
בנוסף, אתם מגדירים מאגר ב-GitHub שמכיל את קובצי המקור של האפליקציה על ידי יצירת עותק (forking) ושכפול (cloning) של המאגר GoogleCloudPlatform/generative-ai. אחרי שמבצעים את השלבים האלה, מאמתים את ההגדרה על ידי הפעלה ובדיקה של האפליקציה באופן מקומי ב-Cloud Shell.
לפני שמתחילים
- נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
-
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 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.
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: 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 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 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.
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: 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 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.
-
הגדרת מאגר המקור
ב-GitHub, יוצרים Fork של מאגר GoogleCloudPlatform/generative-ai. מידע נוסף על יצירת Fork של מאגרים ב-GitHub
-
במסוף Google Cloud , מפעילים את Cloud Shell.
בחלק התחתון של Google Cloud המסוף יתחיל סשן של Cloud Shell ותופיע הודעה של שורת הפקודה. Cloud Shell היא סביבת מעטפת שבה ה-CLI של Google Cloud מותקן ומוגדרים ערכים לפרויקט הקיים. הסשן יופעל תוך כמה שניות.
- בטרמינל של Cloud Shell, מריצים את הפקודות הבאות כדי לשכפל את המאגר המפוצל ולהגדיר את הספרייה
gemini-streamlit-cloudrunכספרייה הפעילה:cd
git clone https://github.com/GIT_USER_NAME/FORK_NAME/
cd FORK_NAME/gemini/sample-apps/gemini-streamlit-cloudrunמחליפים את מה שכתוב בשדות הבאים:
- GIT_USER_NAME: שם המשתמש שלכם ב-GitHub.
- FORK_NAME: השם של מאגר ה-fork שיצרתם ב-GitHub.
הגדרת הסביבה ויחסי התלות
בטרמינל של Cloud Shell, מריצים את הפקודות הבאות כדי להגדיר סביבה וירטואלית:
python3 -m venv gemini-streamlit source gemini-streamlit/bin/activate pip install -r requirements.txtמריצים את הפקודות הבאות כדי להגדיר את משתני הסביבה שנדרשים לאתחול של Agent Platform:
export GCP_PROJECT=$GOOGLE_CLOUD_PROJECT export GCP_REGION='us-central1'
בדיקת האפליקציה באופן מקומי
בטרמינל של Cloud Shell, מריצים את האפליקציה באמצעות הפקודה הבאה:
streamlit run app.py \ --browser.serverAddress=localhost \ --server.enableCORS=false \ --server.enableXsrfProtection=false \ --server.port 8080כדי לראות תצוגה מקדימה של האפליקציה, בסרגל המשימות של Cloud Shell, לוחצים על
ואז על תצוגה מקדימה ביציאה 8080.
מידע נוסף על השימוש בתכונה 'תצוגה מקדימה באינטרנט' זמין במאמר תצוגה מקדימה של אפליקציות אינטרנט.