bethanie05 commited on
Commit
0bb20c9
·
verified ·
1 Parent(s): a2c9f23

Modify google credentials code.

Browse files
Files changed (1) hide show
  1. chat_application/main.py +14 -5
chat_application/main.py CHANGED
@@ -5,7 +5,10 @@ from datetime import datetime, timedelta
5
  import random
6
  import time
7
  import math
 
 
8
  import google.auth
 
9
  from google.auth.transport.requests import AuthorizedSession
10
  from vertexai.tuning import sft
11
  from vertexai.generative_models import GenerativeModel
@@ -29,15 +32,21 @@ app.config["SECRET_KEY"] = "supersecretkey"
29
  socketio = SocketIO(app)
30
 
31
  # Setup for Vertex API calls
32
- credentials, _ = google.auth.default(
33
- scopes=["https://www.googleapis.com/auth/cloud-platform"]
 
 
 
 
34
  )
35
  google_session = AuthorizedSession(credentials)
 
36
  vertex_client = genai.Client(
37
  vertexai=True,
38
- project="frozone-475719",
39
- location="us-central1"
40
- )
 
41
  """
42
  #original lines before separating system instructions and prompts
43
  # Initialize the bots
 
5
  import random
6
  import time
7
  import math
8
+ import os
9
+ import json
10
  import google.auth
11
+ from google.oauth2 import service_account
12
  from google.auth.transport.requests import AuthorizedSession
13
  from vertexai.tuning import sft
14
  from vertexai.generative_models import GenerativeModel
 
32
  socketio = SocketIO(app)
33
 
34
  # Setup for Vertex API calls
35
+ serviceAccount_json = os.environ["GOOGLE_SERVICE_ACCOUNT_JSON"]
36
+ serviceAccount_info = json.loads(serviceAccount_json)
37
+
38
+ credentials = service_account.Credentials.from_service_account_info(
39
+ serviceAccount_info,
40
+ scopes=["https://www.googleapis.com/auth/cloud-platform"],
41
  )
42
  google_session = AuthorizedSession(credentials)
43
+
44
  vertex_client = genai.Client(
45
  vertexai=True,
46
+ project=os.environ["GOOGLE_CLOUD_PROJECT"],
47
+ location=os.environ.get("VERTEX_LOCATION", "us-central1"),
48
+ credentials=credentials,
49
+ )
50
  """
51
  #original lines before separating system instructions and prompts
52
  # Initialize the bots