Wednesday, September 13, 2023

Step by Step Demo of Vertex AI in GCP

 This tutorial gets your started with GCP Vertex AI Generative AI service in step by step demo.




Commands Used:


gcloud services enable aiplatform.googleapis.com


gcloud iam service-accounts create <Your Service Account Name>


gcloud projects add-iam-policy-binding <Your Project ID> \

    --member=serviceAccount:<Your Service Account Name>@<Your Project ID>.iam.gserviceaccount.com \

    --role=roles/aiplatform.admin

from google.auth.transport.requests import Request

from google.oauth2.service_account import Credentials


key_path='<Your Project ID>.json'


credentials = Credentials.from_service_account_file(

    key_path,

    scopes=['https://www.googleapis.com/auth/cloud-platform'])


if credentials.expired:

    credentials.refresh(Request())

PROJECT_ID = '<Your Project ID>'

REGION = 'us-central1'


!pip install -U google-cloud-aiplatform "shapely<2"

import vertexai


# initialize vertex

vertexai.init(project = PROJECT_ID, location = REGION, credentials = credentials)


from vertexai.language_models import TextGenerationModel


generation_model = TextGenerationModel.from_pretrained("text-bison@001")


prompt = "I want to self manage a bathroom renovation project in my home. \

Please suggest me step by step plan to carry out this project."


print(generation_model.predict(prompt=prompt).text)

No comments: