gemma-gemini-eu-travels / setup /vertex_ai_setup.py
Ashmi Banerjee
updated gemini service creds
a2de729
raw
history blame
830 Bytes
from typing import Optional
from dotenv import load_dotenv
from google.oauth2 import service_account
import vertexai
import os
import json
import base64
load_dotenv()
# TODO: fix it in spaces
VERTEXAI_PROJECT = os.environ["VERTEXAI_PROJECT"]
def decode_service_key():
encoded_key = os.environ["GOOGLE_APPLICATION_CREDENTIALS"]
original_service_key = json.loads(base64.b64decode(encoded_key).decode('utf-8'))
return original_service_key
def initialize_vertexai_params(location: Optional[str] = "us-central1"):
GOOGLE_APPLICATION_CREDENTIALS = decode_service_key()
service_account.Credentials.from_service_account_file(
filename=GOOGLE_APPLICATION_CREDENTIALS,
scopes=["https://www.googleapis.com/auth/cloud-platform"],
)
vertexai.init(project=VERTEXAI_PROJECT, location=location)