1단계: 프로젝트 및 소스 저장소 설정

다음 단계에서는 Cloud Shell에서 Google Cloud 프로젝트와 Python 환경을 설정하고 필요한 API를 사용 설정하며 튜토리얼을 완료하는 데 필요한 Identity and Access Management(IAM) 역할을 할당합니다. 또한 GoogleCloudPlatform/generative-ai 저장소를 포크하고 클론하여 앱 소스 파일이 포함된 GitHub 저장소를 설정합니다. 다음 단계를 완료한 후 Cloud Shell에서 로컬로 앱을 실행하고 테스트하여 설정을 확인합니다.

시작하기 전에

  1. 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.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. 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.

    Enable the APIs

  5. 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

    1. In the Google Cloud console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. 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.

    4. 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

    1. In the Google Cloud console, go to the IAM page.

      IAM으로 이동
    2. 프로젝트를 선택합니다.
    3. 액세스 권한 부여를 클릭합니다.
    4. 새 주 구성원 필드에 사용자 식별자를 입력합니다. 일반적으로 Google 계정의 이메일 주소입니다.

    5. 역할 선택 목록에서 역할을 선택합니다.
    6. 역할을 추가로 부여하려면 다른 역할 추가를 클릭하고 각 역할을 추가합니다.
    7. 저장을 클릭합니다.
    8. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

      Go to project selector

    9. Make sure that billing is enabled for your Google Cloud project.

    10. 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.

      Enable the APIs

    11. 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

      1. In the Google Cloud console, go to the IAM page.

        Go to IAM
      2. Select the project.
      3. 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.

      4. 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

      1. In the Google Cloud console, go to the IAM page.

        IAM으로 이동
      2. 프로젝트를 선택합니다.
      3. 액세스 권한 부여를 클릭합니다.
      4. 새 주 구성원 필드에 사용자 식별자를 입력합니다. 일반적으로 Google 계정의 이메일 주소입니다.

      5. 역할 선택 목록에서 역할을 선택합니다.
      6. 역할을 추가로 부여하려면 다른 역할 추가를 클릭하고 각 역할을 추가합니다.
      7. 저장을 클릭합니다.

      소스 저장소 설정

      1. GitHub에서 GoogleCloudPlatform/generative-ai 저장소를 포크합니다. GitHub에서 저장소 포크 자세히 알아보기

        GitHub에서 저장소 포크

      1. In the Google Cloud console, activate Cloud Shell.

        Activate Cloud Shell

        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.

      2. 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: 방금 GitHub에서 만든 포크 저장소의 이름입니다.

      환경 및 종속 항목 설정

      1. Cloud Shell 터미널에서 다음 명령어를 실행하여 가상 환경을 설정합니다.

        python3 -m venv gemini-streamlit
        source gemini-streamlit/bin/activate
        pip install -r requirements.txt
        
      2. 다음 명령어를 실행하여 Vertex AI 초기화에 필요한 환경 변수를 설정합니다.

        export GCP_PROJECT=$GOOGLE_CLOUD_PROJECT
        export GCP_REGION='us-central1' 
        

      로컬로 앱 테스트

      1. Cloud Shell 터미널에서 다음 명령어를 실행하여 앱을 실행합니다.

        streamlit run app.py \
          --browser.serverAddress=localhost \
          --server.enableCORS=false \
          --server.enableXsrfProtection=false \
          --server.port 8080
        
      2. 앱을 미리 보려면 Cloud Shell 작업 표시줄에서 웹 미리보기 버튼를 클릭한 후 포트 8080에서 미리보기를 클릭합니다.

        웹 미리보기 기능 사용 방법에 대한 자세한 내용은 웹 앱 미리보기를 참조하세요.