다음 단계에서는 Cloud Shell에서 Google Cloud 프로젝트와 Python 환경을 설정하고 필요한 API를 사용 설정하며 튜토리얼을 완료하는 데 필요한 Identity and Access Management(IAM) 역할을 할당합니다.
또한 GoogleCloudPlatform/generative-ai 저장소를 포크하고 클론하여 앱 소스 파일이 포함된 GitHub 저장소를 설정합니다. 다음 단계를 완료한 후 Cloud Shell에서 로컬로 앱을 실행하고 테스트하여 설정을 확인합니다.
시작하기 전에
Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a 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.
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.
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.
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.
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.
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.
At the bottom of the Google Cloud console, a
Cloud Shell
session starts and displays a command-line prompt. Cloud Shell is a shell environment
with the Google Cloud CLI
already installed and with values already set for
your current project. It can take a few seconds for the session to initialize.
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
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[],[],null,["# Step 1: Set up your project and source repository\n\nIn this step, you set up your Google Cloud project and Python environment in\nCloud Shell, enable the required APIs, and assign the Identity and Access Management\n(IAM) roles that you need to complete the tutorial.\nYou also set up a GitHub repository containing the app source files by forking\nand cloning the [`GoogleCloudPlatform/generative-ai`](https://github.com/GoogleCloudPlatform/generative-ai)\nrepository. After completing these steps, you verify the setup by running and\ntesting the app locally in Cloud Shell.\n\nBefore you begin\n----------------\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n 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.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=compute.googleapis.com, artifactregistry.googleapis.com, iap.googleapis.com, run.googleapis.com, cloudbuild.googleapis.com, iam.googleapis.com, cloudaicompanion.googleapis.com)\n-\n\n Make sure that you have the following role or roles on the project:\n\n 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.\n\n #### Check for the roles\n\n 1.\n In the Google Cloud console, go to the **IAM** page.\n\n [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)\n 2. Select the project.\n 3.\n In the **Principal** column, find all rows that identify you or a group that\n you're included in. To learn which groups you're included in, contact your\n administrator.\n\n 4. For all rows that specify or include you, check the **Role** column to see whether the list of roles includes the required roles.\n\n #### Grant the roles\n\n 1.\n In the Google Cloud console, go to the **IAM** page.\n\n [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)\n 2. Select the project.\n 3. Click person_add **Grant access**.\n 4.\n In the **New principals** field, enter your user identifier.\n\n This is typically the email address for a Google Account.\n\n 5. In the **Select a role** list, select a role.\n 6. To grant additional roles, click add **Add\n another role** and add each additional role.\n 7. Click **Save**.\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n 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.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=compute.googleapis.com, artifactregistry.googleapis.com, iap.googleapis.com, run.googleapis.com, cloudbuild.googleapis.com, iam.googleapis.com, cloudaicompanion.googleapis.com)\n-\n\n Make sure that you have the following role or roles on the project:\n\n 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.\n\n #### Check for the roles\n\n 1.\n In the Google Cloud console, go to the **IAM** page.\n\n [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)\n 2. Select the project.\n 3.\n In the **Principal** column, find all rows that identify you or a group that\n you're included in. To learn which groups you're included in, contact your\n administrator.\n\n 4. For all rows that specify or include you, check the **Role** column to see whether the list of roles includes the required roles.\n\n #### Grant the roles\n\n 1.\n In the Google Cloud console, go to the **IAM** page.\n\n [Go to IAM](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=project)\n 2. Select the project.\n 3. Click person_add **Grant access**.\n 4.\n In the **New principals** field, enter your user identifier.\n\n This is typically the email address for a Google Account.\n\n 5. In the **Select a role** list, select a role.\n 6. To grant additional roles, click add **Add\n another role** and add each additional role.\n 7. Click **Save**.\n\n\u003cbr /\u003e\n\nSet up the source repository\n----------------------------\n\n1. In GitHub, fork the [GoogleCloudPlatform/generative-ai](https://github.com/GoogleCloudPlatform/generative-ai) repository. [Learn more about forking repositories in GitHub](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/fork-a-repo).\n\n [Fork the repository in GitHub](https://github.com/GoogleCloudPlatform/generative-ai/fork)\n\n\u003c!-- --\u003e\n\n2. In the Google Cloud console, activate Cloud Shell.\n\n [Activate Cloud Shell](https://console.cloud.google.com/?cloudshell=true)\n\n\n At the bottom of the Google Cloud console, a\n [Cloud Shell](/shell/docs/how-cloud-shell-works)\n session starts and displays a command-line prompt. Cloud Shell is a shell environment\n with the Google Cloud CLI\n already installed and with values already set for\n your current project. It can take a few seconds for the session to initialize.\n3. In the Cloud Shell terminal, run the following commands to clone the forked repository and set the `gemini-streamlit-cloudrun` directory as the active directory: \n\n ```\n cd\n git clone https://github.com/GIT_USER_NAME/FORK_NAME/\n cd FORK_NAME/gemini/sample-apps/gemini-streamlit-cloudrun\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eGIT_USER_NAME\u003c/var\u003e: Your GitHub username.\n - \u003cvar translate=\"no\"\u003eFORK_NAME\u003c/var\u003e: The name of the fork repository that you just created in GitHub.\n\nSet up the environment and dependencies\n---------------------------------------\n\n1. In the Cloud Shell terminal, run the following commands to set up a virtual environment:\n\n python3 -m venv gemini-streamlit\n source gemini-streamlit/bin/activate\n pip install -r requirements.txt\n\n2. Run the following commands to set the environment variables needed for Vertex AI initialization:\n\n export GCP_PROJECT=$GOOGLE_CLOUD_PROJECT\n export GCP_REGION='us-central1' \n\nTest the app locally\n--------------------\n\n1. From the Cloud Shell terminal, run the app by running the following command:\n\n streamlit run app.py \\\n --browser.serverAddress=localhost \\\n --server.enableCORS=false \\\n --server.enableXsrfProtection=false \\\n --server.port 8080\n\n2. To preview the app, in the Cloud Shell taskbar, click , and then click **Preview on port 8080**.\n\n For more information about using the Web Preview feature, see [Preview web apps](/shell/docs/using-web-preview)."]]